-
Notifications
You must be signed in to change notification settings - Fork 58
Support php-cs-fixer #66
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
Changes from 13 commits
b82052d
6afb595
d6e12a0
721a61b
e7b3e23
d8d764a
b9dbaac
51a8362
4f10154
236b1ae
506041a
b9b32b7
966dda6
eca908b
840901c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ | |
| /vendor/ | ||
| /build/ | ||
| phpstan-phpqa.neon | ||
| .php_cs.cache | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,7 @@ Experimental tool is executed only if the tool is specified in `--tools`. | |
|
|
||
| Tool | PHP | Supported since | Description | Status | | ||
| ---- | --- | --------------- | ----------- | ------ | | ||
| [php-cs-fixer](http://cs.sensiolabs.org/) | [`>= 5.3`](https://github.com/EdgedesignCZ/phpqa/pull/66#discussion_r115206573) | `1.12` | Automatically detect and fix PHP coding standards issues | stable | | ||
| [parallel-lint](https://github.com/JakubOnderka/PHP-Parallel-Lint) | `>= 5.4` | `1.9` | Check syntax of PHP files | stable | | ||
| [phpstan](https://github.com/phpstan/phpstan) | `>= 7.0` | `1.9` | Discover bugs in your code without running it | _experimental_ ([`v0.7`](https://github.com/EdgedesignCZ/phpqa/pull/43)) | | ||
|
|
||
|
|
@@ -157,6 +158,7 @@ phpcs | [checkstyle.xml](https://edgedesigncz.github.io/phpqa/report/checkstyle. | |
| pdepend | [pdepend-jdepend.xml](https://edgedesigncz.github.io/phpqa/report/pdepend-jdepend.xml), [pdepend-summary.xml](https://edgedesigncz.github.io/phpqa/report/pdepend-summary.xml), [pdepend-dependencies.xml](https://edgedesigncz.github.io/phpqa/report/pdepend-dependencies.xml), [pdepend-jdepend.svg](https://edgedesigncz.github.io/phpqa/report/pdepend-jdepend.svg), [pdepend-pyramid.svg](https://edgedesigncz.github.io/phpqa/report/pdepend-pyramid.svg) | ✗ | | ||
| phpmd | [phpmd.xml](https://edgedesigncz.github.io/phpqa/report/phpmd.xml) | [✓](https://github.com/phpmd/phpmd/blob/master/src/main/php/PHPMD/Renderer/TextRenderer.php#L47) | | ||
| phpmetrics | [phpmetrics.html (v1)](https://edgedesigncz.github.io/phpqa/report/phpmetrics.html), [phpmetrics/index.html (v2)](https://edgedesigncz.github.io/phpqa/report/phpmetrics/), [phpmetrics.xml](https://edgedesigncz.github.io/phpqa/report/phpmetrics.xml) | [✓](https://github.com/phpmetrics/PhpMetrics#usage) | | ||
| php-cs-fixer | [php-cs-fixer.html](https://edgedesigncz.github.io/phpqa/report/php-cs-fixer.html) | [✓](http://cs.sensiolabs.org/#usage "txt output format") | | ||
| parallel-lint | [parallel-lint.html](https://edgedesigncz.github.io/phpqa/report/parallel-lint.html) | [✓](https://github.com/JakubOnderka/PHP-Parallel-Lint#example-output) | | ||
| phpstan | [phpstan.html](https://edgedesigncz.github.io/phpqa/report/phpstan.html), [phpstan-phpqa.neon](https://edgedesigncz.github.io/phpqa/report/phpstan-phpqa.neon) | [✓](https://edgedesigncz.github.io/phpqa/report/phpstan.html), [phpstan-phpqa.neon](https://edgedesigncz.github.io/phpqa/report/phpstan-phpqa.neon "Generated configuration is saved in current working directory") | | ||
|
|
||
|
|
@@ -199,6 +201,10 @@ Tool | Settings | Default Value | Your value | |
| [phpcs.standard](https://pear.php.net/manual/en/package.php.php-codesniffer.usage.php#package.php.php-codesniffer.usage.coding-standard) | Coding standard | PSR2 | Name of existing standard (`PEAR`, `PHPCS`, `PSR1`, `PSR2`, `Squiz`, `Zend`), or path to your coding standard | ||
| [phpcs.ignoreWarnings](https://github.com/EdgedesignCZ/phpqa/issues/53) | If number of allowed errors is compared with warnings+errors, or just errors from `checkstyle.xml` | `false` | Boolean value | ||
| [phpcs.reports](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Reporting) | Report types | [`full`](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Reporting#printing-full-and-summary-reports) report in [cli mode](#output-modes), [`checkstyle`](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Reporting#printing-a-checkstyle-report) in [file mode](#output-modes) | Predefined [report types](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Reporting) or [custom reports](https://github.com/wikidi/codesniffer#examples) | ||
| [php-cs-fixer.rules](http://cs.sensiolabs.org/#usage) | Coding standard rules | `@PSR2` | String value | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you may require |
||
| [php-cs-fixer.allowRiskyRules](http://cs.sensiolabs.org/#usage) | Whether risky rules may run | `false` | Boolean value | ||
| [php-cs-fixer.config](http://cs.sensiolabs.org/#usage) | Load configuration from [file](https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/.php_cs.dist) | `null` | Path to `.phpcs` file | ||
| [php-cs-fixer.isDryRun](http://cs.sensiolabs.org/#usage) | If code is just analyzed or fixers are applied | `true` | Boolean value | ||
| [phpmd](http://phpmd.org/documentation/creating-a-ruleset.html) | Ruleset | [Edgedesign's standard](/app/phpmd.xml) | Path to ruleset | ||
| [phpcpd](https://github.com/sebastianbergmann/phpcpd/blob/de9056615da6c1230f3294384055fa7d722c38fa/src/CLI/Command.php#L136) | Minimum number of lines/tokens for copy-paste detection | 5 lines, 70 tokens | | ||
| [phpstan](https://github.com/phpstan/phpstan#configuration) | Level, config file | Level 0, `%currentWorkingDirectory%/phpstan.neon` | Take a look at [phpqa config in tests/.travis](/tests/.travis/) | | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> | ||
|
|
||
| <xsl:output method="html" encoding="UTF-8"/> | ||
|
|
||
| <xsl:template match="/"> | ||
| <html> | ||
| <head> | ||
| <title>PHP CS Fixer report</title> | ||
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" /> | ||
| <style> | ||
| .file { | ||
| background: #f9f9f9 | ||
| } | ||
| .fixed-navbar { | ||
| list-style-type: none; | ||
| position: fixed; | ||
| top: 0; | ||
| right: 1em; | ||
| } | ||
| </style> | ||
| <script> | ||
| var onDocumentReady = [ | ||
| function () { | ||
| $('[data-fixers]').each(function () { | ||
| var original = $(this).text(); | ||
| var fixers = original.replace("applied fixers:\n---------------", ''); | ||
| var html = fixers.split('* ').splice(1).join('<br />'); | ||
| $(this).html(html); | ||
| }); | ||
| } | ||
| ]; | ||
| </script> | ||
| </head> | ||
| <body> | ||
|
|
||
| <div class="container-fluid"> | ||
|
|
||
| <h1>PHP CS Fixer report</h1> | ||
|
|
||
| <nav> | ||
| <ul class="nav nav-pills" role="tablist"> | ||
| <li role="presentation" class="active"> | ||
| <a href="#overview" aria-controls="overview" role="tab" data-toggle="tab">Overview</a> | ||
| </li> | ||
| <li role="presentation"> | ||
| <a href="#errors" aria-controls="errors" role="tab" data-toggle="tab">Errors</a> | ||
| </li> | ||
| </ul> | ||
| </nav> | ||
|
|
||
| <div class="tab-content"> | ||
|
|
||
| <div role="tabpanel" class="tab-pane active" id="overview"> | ||
| <table class="table table-striped"> | ||
| <thead> | ||
| <tr> | ||
| <th>Files</th> | ||
| <th>Errors</th> | ||
| <th>Duration</th> | ||
| </tr> | ||
| </thead> | ||
| <tr> | ||
| <td><xsl:value-of select="/testsuites/testsuite/@tests" /></td> | ||
| <th><span class="label label-danger"><xsl:value-of select="/testsuites/testsuite/@failures" /></span></th> | ||
| <th><span class="label label-info"><xsl:value-of select="/testsuites/testsuite/@time" /></span></th> | ||
| </tr> | ||
| </table> | ||
| </div> | ||
|
|
||
| <div role="tabpanel" class="tab-pane" id="errors"> | ||
| <div class="fixed-navbar"> | ||
| <div class="input-group" style="width: 20em"> | ||
| <span class="input-group-addon"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></span> | ||
| <input data-search="errors" type="text" class="form-control" placeholder="trailing..." /> | ||
| </div> | ||
| </div> | ||
| <script> | ||
| onDocumentReady.push(function () { | ||
| var rows = $('[data-filterable] tbody tr'); | ||
|
|
||
| $("[data-search]").keyup(function () { | ||
| var term = $(this).val().toLowerCase(); | ||
|
|
||
| rows.hide(); | ||
| matchElements(rows).show(); | ||
|
|
||
| function matchElements(elements) { | ||
| return elements.filter(function () { | ||
| var rowContent = $(this).text().toLowerCase(); | ||
| return rowContent.indexOf(term) !== -1 | ||
| }); | ||
| } | ||
| }); | ||
| }); | ||
| </script> | ||
| <table class="table table-striped table-hover" data-filterable="errors"> | ||
| <thead> | ||
| <tr> | ||
| <th>File</th> | ||
| <th>Errors (fixers)</th> | ||
| </tr> | ||
| </thead> | ||
| <xsl:for-each select="/testsuites/testsuite/testcase"> | ||
| <xsl:for-each select="./failure"> | ||
| <tr> | ||
| <td><strong><xsl:value-of select="../@name" /></strong></td> | ||
| <td data-fixers=""><xsl:value-of select="current()" /></td> | ||
| </tr> | ||
| </xsl:for-each> | ||
| </xsl:for-each> | ||
| </table> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
|
|
||
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> | ||
| <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> | ||
| <script> | ||
| $(document).ready(onDocumentReady); | ||
| </script> | ||
| </body> | ||
| </html> | ||
| </xsl:template> | ||
| </xsl:stylesheet> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| #!/bin/sh | ||
|
|
||
| ./phpqa --verbose --report --config tests/.travis --tools phpcs:0,phpmd:0,phpcpd:0,parallel-lint:0,phpstan,phpmetrics,phploc,pdepend | ||
| ./phpqa --verbose --report --config tests/.travis --tools phpcs:0,php-cs-fixer:0,phpmd:0,phpcpd:0,parallel-lint:0,phpstan,phpmetrics,phploc,pdepend |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,14 @@ trait CodeAnalysisTasks | |
| 'composer' => 'squizlabs/php_codesniffer', | ||
| 'binary' => 'phpcs', | ||
| ), | ||
| 'php-cs-fixer' => array( | ||
| 'optionSeparator' => ' ', | ||
| 'internalClass' => 'PhpCsFixer\Config', | ||
| 'outputMode' => OutputMode::XML_CONSOLE_OUTPUT, | ||
| 'composer' => 'friendsofphp/php-cs-fixer', | ||
| 'xml' => ['php-cs-fixer.xml'], | ||
| 'errorsXPath' => '//testsuites/testsuite/testcase/failure', | ||
| ), | ||
| 'phpmd' => array( | ||
| 'optionSeparator' => ' ', | ||
| 'xml' => ['phpmd.xml'], | ||
|
|
@@ -61,13 +69,13 @@ trait CodeAnalysisTasks | |
| 'parallel-lint' => array( | ||
| 'optionSeparator' => ' ', | ||
| 'internalClass' => 'JakubOnderka\PhpParallelLint\ParallelLint', | ||
| 'hasOnlyConsoleOutput' => true, | ||
| 'outputMode' => OutputMode::RAW_CONSOLE_OUTPUT, | ||
| 'composer' => 'jakub-onderka/php-parallel-lint', | ||
| ), | ||
| 'phpstan' => array( | ||
| 'optionSeparator' => ' ', | ||
| 'internalClass' => 'PHPStan\Analyser\Analyser', | ||
| 'hasOnlyConsoleOutput' => true, | ||
| 'outputMode' => OutputMode::RAW_CONSOLE_OUTPUT, | ||
| 'composer' => 'phpstan/phpstan', | ||
| ), | ||
| ); | ||
|
|
@@ -384,13 +392,45 @@ function ($relativeDir) { | |
| ); | ||
| } | ||
|
|
||
| private function phpcsfixer() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you like, you could execute the code (FixCommand) instead of running it as separated CLI process |
||
| { | ||
| $analyzedDirs = $this->options->getAnalyzedDirs(); | ||
| $analyzedDir = reset($analyzedDirs); | ||
| if (count($analyzedDirs) > 1) { | ||
| $this->say("<error>php-cs-fixer analyzes only first directory {$analyzedDir}</error>"); | ||
|
||
| } | ||
| $args = [ | ||
| 'fix', | ||
| $analyzedDir, | ||
| 'verbose' => '', | ||
| 'format' => $this->options->isSavedToFiles ? 'junit' : 'txt', | ||
| ]; | ||
| $configFile = $this->config->value('php-cs-fixer.config'); | ||
| if ($configFile) { | ||
| $args['config'] = $configFile; | ||
| } else { | ||
| $args += [ | ||
| 'rules' => $this->config->value('php-cs-fixer.rules'), | ||
| 'allow-risky' => $this->config->value('php-cs-fixer.allowRiskyRules') ? 'yes' : 'no', | ||
| ]; | ||
| } | ||
| if ($this->config->value('php-cs-fixer.isDryRun')) { | ||
| $args['dry-run'] = ''; | ||
| } | ||
| return $args; | ||
| } | ||
|
|
||
| private function buildHtmlReport() | ||
| { | ||
| foreach ($this->usedTools as $tool) { | ||
| if (!$tool->htmlReport) { | ||
| $tool->htmlReport = $this->options->rawFile("{$tool->binary}.html"); | ||
| } | ||
| if ($tool->hasOnlyConsoleOutput) { | ||
| if ($tool->hasOutput(OutputMode::XML_CONSOLE_OUTPUT)) { | ||
| file_put_contents($this->options->rawFile("{$tool}.xml"), $tool->process->getOutput()); | ||
| } | ||
|
|
||
| if ($tool->hasOutput(OutputMode::RAW_CONSOLE_OUTPUT)) { | ||
| twigToHtml( | ||
| 'cli.html.twig', | ||
| array( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?php | ||
|
|
||
| namespace Edge\QA; | ||
|
|
||
| class OutputMode | ||
| { | ||
| const HANDLED_BY_TOOL = 0; | ||
| const RAW_CONSOLE_OUTPUT = 1; | ||
| const XML_CONSOLE_OUTPUT = 2; | ||
| } |
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 would add
.php_cs(not.php_cs.dist) as well