Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !769

[PHP] Upgrade php-cs-fixer to 2.12, enables PHP >= 7.2 support

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/mattmelling/php7.2 into master 6 years ago
  • Overview 0
  • Commits 3
  • Pipelines 0
  • Changes 30

Created by: mattmelling

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

The PHP client uses friendsofphp/php-cs-fixer v1.12 for PSR2 analysis. 1,12 doesn't supports PHP up to < 7.2.

PHP >= 7.2 support was added in php-cs-fixer v2 which made some changes to the API and default fixers/rules.

This PR upgrades php-cs-fixer to v2.12. The fixers/rules have been aligned for PSR2 as desired in the original PR on swagger-codegen (#3863). I've changed defaults for some of the rules to prevent lots of whitespace warnings from php-cs-fixer, these typically seem to be down to blank template values and are not raised when using the configuration in master.

Notes

php-cs-fixer added the idea of "risky" fixers in v2. Since the strict_param and strict_comparison fixers are considered risky, we must alter the command line to vendor/bin/php-cs-fixer fix --dry-run --diff -vvv --allow-risky yes even when using --dry-run.

/cc @jebentier, @dkarlovi, @mandrean, @jfastnacht, @ackintosh, @ybelenko

Compare
  • master (base)

and
  • latest version
    3cba142e
    3 commits, 2 years ago

30 files
+ 2253
- 55

    Preferences

    File browser
    Compare changes
modules/openapi-g‎enerator/…/…/…/php‎
.ph‎p_cs‎ +19 -14
ObjectSerial‎izer.mustache‎ +2 -2
composer‎.mustache‎ +1 -1
model_gener‎ic.mustache‎ +1 -1
sam‎ples‎
cli‎ent‎
petstore-secu‎rity-test/php‎
.openapi-‎generator‎
VER‎SION‎ +1 -1
do‎cs‎
A‎pi‎
FakeA‎pi.md‎ +57 -0
Mo‎del‎
ModelRe‎turn.md‎ +10 -0
l‎ib‎
A‎pi‎
FakeA‎pi.php‎ +321 -0
Mo‎del‎
ModelInte‎rface.php‎ +96 -0
ModelRe‎turn.php‎ +298 -0
ApiExcep‎tion.php‎ +121 -0
Configur‎ation.php‎ +429 -0
HeaderSel‎ector.php‎ +110 -0
ObjectSeri‎alizer.php‎ +317 -0
te‎st‎
A‎pi‎
FakeApi‎Test.php‎ +83 -0
Mo‎del‎
ModelRetu‎rnTest.php‎ +85 -0
.ph‎p_cs‎ +23 -0
.trav‎is.yml‎ +10 -0
READ‎ME.md‎ +112 -0
compos‎er.json‎ +38 -0
git_p‎ush.sh‎ +52 -0
phpunit.‎xml.dist‎ +21 -0
petstore/php/Op‎enAPIClient-php‎
l‎ib‎
Mo‎del‎
Anima‎l.php‎ +1 -1
ObjectSeri‎alizer.php‎ +2 -2
.ph‎p_cs‎ +19 -14
compos‎er.json‎ +1 -1
openapi3/client/…/p‎hp/OpenAPIClient-php‎
l‎ib‎
Mo‎del‎
Anima‎l.php‎ +1 -1
ObjectSeri‎alizer.php‎ +2 -2
.ph‎p_cs‎ +19 -14
compos‎er.json‎ +1 -1
modules/openapi-generator/src/main/resources/php/.php_cs
+ 19
- 14
  • View file @ 3cba142e

  • Edit in single-file editor

  • Open in Web IDE

<?php
return Symfony\CS\Config::create()
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
return PhpCsFixer\Config::create()
->setUsingCache(true)
->fixers(
[
'ordered_use',
'phpdoc_order',
'short_array_syntax',
'strict',
'strict_param'
]
)
->finder(
Symfony\CS\Finder\DefaultFinder::create()
->in(__DIR__)
->setRules([
'@PSR2' => true,
'ordered_imports' => true,
'phpdoc_order' => true,
'array_syntax' => [ 'syntax' => 'short' ],
'strict_comparison' => true,
'strict_param' => true,
'no_trailing_whitespace' => false,
'no_trailing_whitespace_in_comment' => false,
'braces' => false,
'single_blank_line_at_eof' => false,
'blank_line_after_namespace' => false,
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude('test')
->exclude('tests')
->in(__DIR__)
);
modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache
+ 2
- 2
  • View file @ 3cba142e

  • Edit in single-file editor

  • Open in Web IDE


@@ -58,7 +58,7 @@ class ObjectSerializer
if ($value !== null
&& !in_array($openAPIType, [{{&primitives}}], true)
&& method_exists($openAPIType, 'getAllowableEnumValues')
&& !in_array($value, $openAPIType::getAllowableEnumValues())) {
&& !in_array($value, $openAPIType::getAllowableEnumValues(), true)) {
$imploded = implode("', '", $openAPIType::getAllowableEnumValues());
throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'");
}
@@ -274,7 +274,7 @@ class ObjectSerializer
return new \SplFileObject($filename, 'r');
} elseif (method_exists($class, 'getAllowableEnumValues')) {
if (!in_array($data, $class::getAllowableEnumValues())) {
if (!in_array($data, $class::getAllowableEnumValues(), true)) {
$imploded = implode("', '", $class::getAllowableEnumValues());
throw new \InvalidArgumentException("Invalid value for enum '$class', must be one of: '$imploded'");
}
modules/openapi-generator/src/main/resources/php/composer.mustache
+ 1
- 1
  • View file @ 3cba142e

  • Edit in single-file editor

  • Open in Web IDE


@@ -30,7 +30,7 @@
"require-dev": {
"phpunit/phpunit": "^4.8",
"squizlabs/php_codesniffer": "~2.6",
"friendsofphp/php-cs-fixer": "~1.12"
"friendsofphp/php-cs-fixer": "~2.12"
},
"autoload": {
"psr-4": { "{{escapedInvokerPackage}}\\" : "{{srcBasePath}}/" }
modules/openapi-generator/src/main/resources/php/model_generic.mustache
+ 1
- 1
  • View file @ 3cba142e

  • Edit in single-file editor

  • Open in Web IDE


@@ -166,7 +166,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa
{{#discriminator}}
// Initialize discriminator property with the model name.
$discriminator = array_search('{{discriminatorName}}', self::$attributeMap);
$discriminator = array_search('{{discriminatorName}}', self::$attributeMap, true);
$this->container[$discriminator] = static::$openAPIModelName;
{{/discriminator}}
}
samples/client/petstore/php/OpenAPIClient-php/lib/Model/Animal.php
+ 1
- 1
  • View file @ 3cba142e

  • Edit in single-file editor

  • Open in Web IDE


@@ -186,7 +186,7 @@ class Animal implements ModelInterface, ArrayAccess
$this->container['color'] = isset($data['color']) ? $data['color'] : 'red';
// Initialize discriminator property with the model name.
$discriminator = array_search('className', self::$attributeMap);
$discriminator = array_search('className', self::$attributeMap, true);
$this->container[$discriminator] = static::$openAPIModelName;
}
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
3.2.1
3.2.1 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 participants
Reference: OpenAPITools/openapi-generator!807
Source branch: github/fork/mattmelling/php7.2

Menu

Explore Projects Groups Snippets