Skip to content

[php] Add PSR-12 rule set#12302

Merged
wing328 merged 7 commits intoOpenAPITools:masterfrom
ybelenko:4726_phpclient
May 9, 2022
Merged

[php] Add PSR-12 rule set#12302
wing328 merged 7 commits intoOpenAPITools:masterfrom
ybelenko:4726_phpclient

Conversation

@ybelenko
Copy link
Copy Markdown
Contributor

@ybelenko ybelenko commented May 6, 2022

I've added PSR-12 rule set to Php-CS-Fixer config since it's officially supported now.
The config file has been renamed to .php-cs-fixer.dist.php to be able to overwrite it with local config file without dist part.

I don't know why we have so many rules since we agreed to follow PSR-12 only at the first place.
New config:

/**
 * @generated
 * @link https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/HEAD/doc/config.rst
 */
$finder = PhpCsFixer\Finder::create()
    ->in(__DIR__)
    ->exclude('vendor')
    ->exclude('test')
    ->exclude('tests')
;

$config = new PhpCsFixer\Config();
return $config->setRules([
        '@PSR12' => 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,
        'no_leading_import_slash' => false,
    ])
    ->setFinder($finder)
;

If somebody knows why we have disabled:

        'braces' => false,
        'single_blank_line_at_eof' => false,
        'blank_line_after_namespace' => false,

Also added rule no_leading_import_slash => false because there are model classes with leadings slashes in imports. No clue why, but still.

Fixer run output:

vendor/bin/php-cs-fixer fix --allow-risky=yes -vv
PHP CS Fixer 3.8.0 BerSzcz against war! by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.0.16
Loaded config default from "/Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/.php-cs-fixer.dist.php".
............................................................                                                                                    60 / 60 (100%)
Legend: ?-unknown, I-invalid file syntax (file ignored), S-skipped (cached or empty file), .-no changes, F-fixed, E-error

Fixed all files in 2.246 seconds, 28.000 MB memory used

I would remove the old .php_cs file from samples right in current PR, but the CI workflow will be failed instantly...

Related #4726

cc @jebentier @dkarlovi @mandrean @jfastnacht @renepardon

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

ybelenko added 7 commits May 6, 2022 14:59
This version requires PHP 7.4 or 8.0 which perfectly meets our supported
PHP right now.
This way it can be overwritten with local file(same name without "dist"
part). Also it's recommended filename from the package doc.
@wing328
Copy link
Copy Markdown
Member

wing328 commented May 9, 2022

@wing328 wing328 merged commit e639dad into OpenAPITools:master May 9, 2022
@ybelenko ybelenko deleted the 4726_phpclient branch May 9, 2022 18:07
@wing328 wing328 added this to the 6.0.0 milestone May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants