Skip to content

Commit 23b3331

Browse files
committed
phpstan - spike dynamic output mode
It's hotfix that prevents xml error if checkstyle is not used: $ ./phpqa --config tests/.ci --tools phpstan simplexml_load_file(): build//phpstan.xml:1: parser error : Start tag expected, '<' not found
1 parent fd72ae9 commit 23b3331

5 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/RunningTool.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Edge\QA;
44

5+
use Edge\QA\Tools\Analyzer\Phpstan;
6+
57
class RunningTool
68
{
79
private $tool;
@@ -64,6 +66,9 @@ private function isAtLeastOneClassInstalled(array $classes)
6466

6567
public function hasOutput($outputMode)
6668
{
69+
if (!$this->outputMode && $this->tool === 'phpstan') {
70+
$this->outputMode = Phpstan::$SETTINGS['outputMode'];
71+
}
6772
return $this->outputMode == $outputMode;
6873
}
6974

src/Tools/Analyzer/Phpstan.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Phpstan extends \Edge\QA\Tools\Tool
88
{
99
public static $SETTINGS = array(
1010
'optionSeparator' => ' ',
11-
'outputMode' => OutputMode::XML_CONSOLE_OUTPUT,
11+
'outputMode' => null, // hotfix for dynamic output mode that depends on errorFormat
1212
'xml' => ['phpstan.xml'],
1313
'errorsXPath' => '//checkstyle/file/error',
1414
'composer' => 'phpstan/phpstan',
@@ -42,11 +42,14 @@ function ($relativeDir) {
4242
$phpstanConfig = "# Configuration generated in phpqa\n" . \Nette\Neon\Neon::encode($config);
4343
$neonFile = $this->saveDynamicConfig($phpstanConfig, 'neon');
4444

45+
$errorFormat = $this->config->value('phpstan.errorFormat') ?: 'checkstyle';
46+
self::$SETTINGS['outputMode'] = $errorFormat === 'checkstyle'
47+
? OutputMode::XML_CONSOLE_OUTPUT : OutputMode::RAW_CONSOLE_OUTPUT;
48+
4549
$args = array(
4650
'analyze',
4751
'ansi' => '',
48-
// TODO: disable xml output if errorFormat != checkstyle
49-
$this->getErrorFormatOption() => $this->config->value('phpstan.errorFormat') ?: 'checkstyle',
52+
$this->getErrorFormatOption() => $errorFormat,
5053
'level' => $this->config->value('phpstan.level'),
5154
'configuration' => $neonFile,
5255
$this->options->getAnalyzedDirs(' '),

tests/.ci/.phpqa.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ psalm:
4949

5050
phpstan:
5151
level: 5 # last level without type hints
52+
# only checkstyle has pretty html report in phqpa - https://phpstan.org/user-guide/output-format
53+
errorFormat: table
5254
# memoryLimit: 1G
5355
# https://github.com/phpstan/phpstan#configuration
5456
standard: phpstan.neon

tests/.ci/phpmd.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<rule ref="rulesets/codesize.xml" />
99
<rule ref="rulesets/controversial.xml">
1010
<exclude name="CamelCasePropertyName" />
11+
<exclude name="CamelCaseVariableName" />
1112
</rule>
1213
<rule ref="rulesets/design.xml" />
1314
<rule ref="rulesets/unusedcode.xml" />

tests/RunningToolTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Edge\QA;
44

5+
use Edge\QA\Tools\Analyzer\Phpstan;
6+
57
/** @SuppressWarnings(PHPMD.TooManyPublicMethods) */
68
class RunningToolTest extends \PHPUnit_Framework_TestCase
79
{
@@ -128,4 +130,13 @@ public function testCreateUniqueIdForUserReport()
128130
$report = $tool->getHtmlRootReports()[0];
129131
assertThat($report['id'], is('phpcs-dir-path-php'));
130132
}
133+
134+
public function testDynamicOutputModePhpstan()
135+
{
136+
$tool = new RunningTool('phpstan', [
137+
'outputMode' => null,
138+
]);
139+
Phpstan::$SETTINGS['outputMode'] = OutputMode::RAW_CONSOLE_OUTPUT;
140+
assertThat($tool->hasOutput(OutputMode::RAW_CONSOLE_OUTPUT), is(true));
141+
}
131142
}

0 commit comments

Comments
 (0)