Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
php-cs-fixer - refactoring deifnition of output modes
  • Loading branch information
zdenekdrahos committed May 8, 2017
commit e7b3e237adc8ad9cb630380706eaa6df3629b4a2
11 changes: 5 additions & 6 deletions src/CodeAnalysisTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ trait CodeAnalysisTasks
'php-cs-fixer' => array(
'optionSeparator' => ' ',
'internalClass' => 'PhpCsFixer\Config',
'hasOnlyConsoleOutput' => false,
'hasXmlOutputInConsole' => true,
'outputMode' => OutputMode::XML_CONSOLE_OUTPUT,
'composer' => 'friendsofphp/php-cs-fixer',
'xml' => ['php-cs-fixer.xml'],
'errorsXPath' => '//testsuites/testsuite/testcase/failure',
Expand All @@ -70,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',
),
);
Expand Down Expand Up @@ -419,11 +418,11 @@ private function buildHtmlReport()
if (!$tool->htmlReport) {
$tool->htmlReport = $this->options->rawFile("{$tool->binary}.html");
}
if ($tool->hasXmlOutputInConsole) {
if ($tool->hasOutput(OutputMode::XML_CONSOLE_OUTPUT)) {
file_put_contents($this->options->rawFile("{$tool}.xml"), $tool->process->getOutput());
}

if ($tool->hasOnlyConsoleOutput) {
if ($tool->hasOutput(OutputMode::RAW_CONSOLE_OUTPUT)) {
twigToHtml(
'cli.html.twig',
array(
Expand Down
10 changes: 10 additions & 0 deletions src/OutputMode.php
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;
}
15 changes: 9 additions & 6 deletions src/RunningTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class RunningTool
public $binary;
private $internalClass;
private $optionSeparator;
private $outputMode;

private $xmlFiles;
private $errorsXPath;
Expand All @@ -16,8 +17,6 @@ class RunningTool

public $htmlReport;
public $userReports = [];
public $hasOnlyConsoleOutput;
public $hasXmlOutputInConsole;
/** @var \Symfony\Component\Process\Process */
public $process;

Expand All @@ -29,7 +28,7 @@ public function __construct($tool, array $toolConfig)
'xml' => [],
'errorsXPath' => '',
'allowedErrorsCount' => null,
'hasOnlyConsoleOutput' => false,
'outputMode' => OutputMode::HANDLED_BY_TOOL,
'internalClass' => null,
];
$this->tool = $tool;
Expand All @@ -40,15 +39,19 @@ public function __construct($tool, array $toolConfig)
$this->errorsXPath = is_array($config['errorsXPath'])
? $config['errorsXPath'] : [$this->errorsXPath => $config['errorsXPath']];
$this->allowedErrorsCount = $config['allowedErrorsCount'];
$this->hasOnlyConsoleOutput = $config['hasOnlyConsoleOutput'];
$this->hasXmlOutputInConsole = $config['hasXmlOutputInConsole'];
$this->outputMode = $config['outputMode'];
}

public function isInstalled()
{
return !$this->internalClass || class_exists($this->internalClass);
}

public function hasOutput($outputMode)
{
return $this->outputMode == $outputMode;
}

public function buildOption($arg, $value)
{
if ($value || $value === 0) {
Expand All @@ -67,7 +70,7 @@ public function analyzeResult($hasNoOutput = false)
{
$xpath = $this->errorsXPath[$this->errorsType];

if ($hasNoOutput || $this->hasOnlyConsoleOutput) {
if ($hasNoOutput || $this->hasOutput(OutputMode::RAW_CONSOLE_OUTPUT)) {
return $this->evaluteErrorsCount($this->process->getExitCode() ? 1 : 0);
} elseif (!$xpath) {
return [true, ''];
Expand Down