Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Slim] Add PHP CodeSniffer to check coding style #897

Merged
merged 5 commits into from
Aug 26, 2018

Conversation

ybelenko
Copy link
Contributor

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, 3.3.x, 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

As defined in guide of contributing, PHP templates should meet PSR-2 coding style.

I've added PHP CodeSniffer package to check source code on violations against user defined standard. User can change coding standard with phpcsStandard config option. 'PSR12' is default(checks against PSR-1 and PSR-2)

I think it's perfect time to add linters and code formatters while generator is small like Slim now. It will be easier to update templates and check them automatically every next PR. By this reason I suggest to merge this PR before #735.

cc @jebentier @dkarlovi @mandrean @jfastnacht @ackintosh

We follow PSR-2 coding style guide in PHP generators. It might be convenient
for users to specify own coding standard without modifying templates. That's
why I've added this option.

At first, I thought to add option validation and accept only standards from
predefined list. But this option also can be a full path to the standard's
root directory, I've changed my mind. User should use this option with caution.

Ref to all PHP CodeSniffer CLI options:
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage
Copy link
Member

@wing328 wing328 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enhancement looks good to me 👍 . We should probably do the same in other PHP (client, server) generators.

@ybelenko ybelenko merged commit 15cec0a into OpenAPITools:master Aug 26, 2018
@ybelenko ybelenko deleted the slim_psr2 branch August 26, 2018 10:26
@ybelenko ybelenko added this to the 3.2.3 milestone Aug 26, 2018
@wing328
Copy link
Member

wing328 commented Aug 30, 2018

@ybelenko thanks for the PR, which has been included in the v3.2.3 release: https://twitter.com/oas_generator/status/1035200785066254336

A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
* [Slim] Add PHP CodeSniffer package

* [Slim] Add phpcsStandard generator option

We follow PSR-2 coding style guide in PHP generators. It might be convenient
for users to specify own coding standard without modifying templates. That's
why I've added this option.

At first, I thought to add option validation and accept only standards from
predefined list. But this option also can be a full path to the standard's
root directory, I've changed my mind. User should use this option with caution.

Ref to all PHP CodeSniffer CLI options:
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage

* [Slim] Extend readme with PHP CodeSniffer docs

* [Slim] Format templates to meet PSR-2

* [Slim] Refresh samples
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.

None yet

2 participants