-
Notifications
You must be signed in to change notification settings - Fork 274
N°8796 - Add PHP code style validation in iTop and extensions #757
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
Merged
+2,841
−0
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
53417ff
poc php-cs-fixer
odain-cbd 01cf699
PSR2 for now
odain-cbd c273fbb
PSR12 + array short
odain-cbd 5769b5a
move php-cs-fixer stuff in tests/php-code-style
odain-cbd d3910ee
add README
odain-cbd 614fa1d
fix php-cs-fixer move into php-code-style
odain-cbd ffd3544
illustrate code reformatting on webservices folder
odain-cbd 0ca8114
phpstan: change composer php requirements
odain-cbd fc6c535
indent with tabs + inception style applied everywhere even php-cs-fix…
odain-cbd 34ffb9e
use tabs for code style indentation
odain-cbd 2d5acc4
format concat with spaces
odain-cbd 013ab40
finalize included/excluded folders to formatting tool
odain-cbd 44d0910
add trailing_comma_in_multiline option
odain-cbd b72fdb4
adapt composer.json requirements
odain-cbd 5af9123
Revert changes on webservices folder
odain-cbd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?php | ||
|
|
||
| $APPROOT = dirname(__DIR__, 2); | ||
|
|
||
| echo $APPROOT; | ||
| $finder = PhpCsFixer\Finder::create() | ||
| ->in($APPROOT) | ||
| ->exclude(['oql', 'data', 'extensions']) | ||
| ->notPath(['/env-*/', '/cache-*/', 'lib', 'vendor', 'node_modules']) | ||
| ; | ||
|
|
||
| $config = new PhpCsFixer\Config(); | ||
| return $config->setRiskyAllowed(true) | ||
| ->setRules([ | ||
| '@PSR12' => true, | ||
| 'indentation_type' => true, | ||
| 'no_extra_blank_lines' => true, | ||
| 'array_syntax' => ['syntax' => 'short'], | ||
| 'concat_space' => true, | ||
| 'trailing_comma_in_multiline' => true, | ||
| ]) | ||
| ->setIndent("\t") | ||
| ->setLineEnding("\n") | ||
| ->setFinder($finder) | ||
| ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| Code formatting tool used by iTop is PHP-CS-Fixer: | ||
| https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/master | ||
|
|
||
|
|
||
| to check code style issues (no path provided means whole iTop code base): | ||
|
|
||
| ``` | ||
| cd tests/php-code-style/; composer install; cd - | ||
| tests/php-code-style/vendor/bin/php-cs-fixer check --config tests/php-code-style/.php-cs-fixer.dist.php [PATH] | ||
| ``` | ||
|
|
||
| to respect iTop code standards and re-format (no path provided means whole iTop code base): | ||
|
|
||
| ``` | ||
| tests/php-code-style/vendor/bin/php-cs-fixer fix --config tests/php-code-style/.php-cs-fixer.dist.php [PATH] | ||
|
|
||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "require-dev": { | ||
| "php": "^7.0 || ^8.0", | ||
| "friendsofphp/php-cs-fixer": "^3.89", | ||
| "phpstan/phpstan": "^2.1" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just move the
.php-cs-fixer.dist.phpto the root directory and add this in the main README?When also moving composer, the command would then just become
vendor/bin/php-cs-fixer fix [PATH], which is much easier/friendly to use.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you. CLI would be shorter and that's what I started with.
but we prefer to keep such stuff apart. ie phpstan/phpunit/php-cs-fixer are gathered in tests folder to package iTop community easily without them. zip is heavy enough. packaging tools are simpler to maintain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not impact .zip size when putting in
require-devsection of composer?If that's the case, then why not using
tests/composer.jsoninstead?