-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b82052d
php-cs-fixer - add suggested tool, spike cli/file mode
zdenekdrahos 6afb595
php-cs-fixer - load configuration from .phpqa.yml
zdenekdrahos d6e12a0
php-cs-fixer - custom xsl template
zdenekdrahos 721a61b
php-cs-fixer - fix displaying report in full phpqa report
zdenekdrahos e7b3e23
php-cs-fixer - refactoring deifnition of output modes
zdenekdrahos d8d764a
php-cs-fixer - add suggested tool
zdenekdrahos b9dbaac
php-cs-fixer - fix coding standard
zdenekdrahos 51a8362
php-cs-fixer - fix rules definition in yaml file
zdenekdrahos 4f10154
php-cs-fixer - add documentation for output modes and advanced config…
zdenekdrahos 236b1ae
php-cs-fixer - rename report title
zdenekdrahos 506041a
php-cs-fixer - allow risky rules in .phpqa.yml
zdenekdrahos b9b32b7
php-cs-fixer - fix installing suggested tools after clone
zdenekdrahos 966dda6
php-cs-fixer - allow custom .php_cs configuration instead of mapping …
zdenekdrahos eca908b
php-cs-fixer - ignore configuration file
zdenekdrahos 840901c
php-cs-fixer - multiple dirs are supported if config file is specified
zdenekdrahos 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
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 |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
/vendor/ | ||
/build/ | ||
phpstan-phpqa.neon | ||
.php_cs | ||
.php_cs.cache |
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
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
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,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> |
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
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 |
---|---|---|
@@ -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 |
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
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 |
---|---|---|
|
@@ -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,53 @@ 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 |
||
{ | ||
$configFile = $this->config->value('php-cs-fixer.config'); | ||
if ($configFile) { | ||
$analyzedDir = $this->options->getAnalyzedDirs(' '); | ||
} else { | ||
$analyzedDirs = $this->options->getAnalyzedDirs(); | ||
$analyzedDir = reset($analyzedDirs); | ||
if (count($analyzedDirs) > 1) { | ||
$this->say("<error>php-cs-fixer analyzes only first directory {$analyzedDir}</error>"); | ||
$this->say( | ||
"- <info>multiple dirs are supported if you specify " . | ||
"<comment>php-cs-fixer.config</comment> in <comment>.phpqa.yml</comment></info>" | ||
); | ||
} | ||
} | ||
$args = [ | ||
'fix', | ||
$analyzedDir, | ||
'verbose' => '', | ||
'format' => $this->options->isSavedToFiles ? 'junit' : 'txt', | ||
]; | ||
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( | ||
|
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,10 @@ | ||
<?php | ||
|
||
namespace Edge\QA; | ||
|
||
class OutputMode | ||
{ | ||
const HANDLED_BY_TOOL = 0; | ||
const RAW_CONSOLE_OUTPUT = 1; | ||
const XML_CONSOLE_OUTPUT = 2; | ||
} |
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
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
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.
you may require
risky
support, as some of the rules require that to be enabled