diff --git a/.phpqa.yml b/.phpqa.yml
index bfd5bb9..ac814b7 100644
--- a/.phpqa.yml
+++ b/.phpqa.yml
@@ -64,6 +64,7 @@ phpmetrics:
phpstan:
level: 0
+ errorFormat: checkstyle
# https://github.com/phpstan/phpstan/issues/1880
memoryLimit: null
# https://github.com/phpstan/phpstan#configuration
diff --git a/README.md b/README.md
index d0cdf3f..7bcd32b 100644
--- a/README.md
+++ b/README.md
@@ -329,7 +329,7 @@ Tool | Settings | Default Value | Your value
[phpmd.standard](http://phpmd.org/documentation/creating-a-ruleset.html) | Ruleset | [Edgedesign's standard](/app/phpmd.xml) | Path to ruleset. To specify [multiple rule sets](https://phpmd.org/documentation/index.html#using-multiple-rule-sets), you can use an array
[phpmd.ignoreParsingErrors](https://github.com/EdgedesignCZ/phpqa/issues/230) | If parsing errors affect exit code, or just violations | `true` | Boolean value
[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, memory limit | Level 0, `%currentWorkingDirectory%/phpstan.neon`, memoryLimit: null | Take a look at [phpqa config in tests/.ci](/tests/.ci/) |
+[phpstan](https://github.com/phpstan/phpstan#configuration) | Level, error format, config file, memory limit | Level 0, checkstyle, `%currentWorkingDirectory%/phpstan.neon`, memoryLimit: null | Take a look at [phpqa config in tests/.ci](/tests/.ci/) |
[phpunit.binary](https://github.com/EdgedesignCZ/phpqa/blob/4947416/.phpqa.yml#L40) | Phpunit binary | phpqa's phpunit | Path to phpunit executable in your project, typically [`vendor/bin/phpunit`](https://gitlab.com/costlocker/integrations/blob/master/basecamp/backend/.phpqa.yml#L2) |
[phpunit.config](https://phpunit.de/manual/current/en/organizing-tests.html#organizing-tests.xml-configuration) | PHPUnit configuration, `analyzedDirs` and `ignoredDirs` are not used, you have to specify test suites in XML file | `null` | Path to `phpunit.xml` file
[phpunit.reports](https://phpunit.de/manual/current/en/textui.html) | Report types | no report | List of reports and formats, corresponds with CLI option, e.g. `--log-junit` is `log: [junit]` in `.phpqa.yml` |
diff --git a/src/RunningTool.php b/src/RunningTool.php
index 99a7b8b..8b87cf3 100644
--- a/src/RunningTool.php
+++ b/src/RunningTool.php
@@ -2,6 +2,8 @@
namespace Edge\QA;
+use Edge\QA\Tools\Analyzer\Phpstan;
+
class RunningTool
{
private $tool;
@@ -64,6 +66,9 @@ private function isAtLeastOneClassInstalled(array $classes)
public function hasOutput($outputMode)
{
+ if (!$this->outputMode && $this->tool === 'phpstan') {
+ $this->outputMode = Phpstan::$SETTINGS['outputMode'];
+ }
return $this->outputMode == $outputMode;
}
diff --git a/src/Tools/Analyzer/Phpstan.php b/src/Tools/Analyzer/Phpstan.php
index 1a63a90..7e4a9de 100644
--- a/src/Tools/Analyzer/Phpstan.php
+++ b/src/Tools/Analyzer/Phpstan.php
@@ -8,7 +8,7 @@ class Phpstan extends \Edge\QA\Tools\Tool
{
public static $SETTINGS = array(
'optionSeparator' => ' ',
- 'outputMode' => OutputMode::XML_CONSOLE_OUTPUT,
+ 'outputMode' => null, // hotfix for dynamic output mode that depends on errorFormat
'xml' => ['phpstan.xml'],
'errorsXPath' => '//checkstyle/file/error',
'composer' => 'phpstan/phpstan',
@@ -42,10 +42,14 @@ function ($relativeDir) {
$phpstanConfig = "# Configuration generated in phpqa\n" . \Nette\Neon\Neon::encode($config);
$neonFile = $this->saveDynamicConfig($phpstanConfig, 'neon');
+ $errorFormat = $this->config->value('phpstan.errorFormat') ?: 'checkstyle';
+ self::$SETTINGS['outputMode'] = $errorFormat === 'checkstyle'
+ ? OutputMode::XML_CONSOLE_OUTPUT : OutputMode::RAW_CONSOLE_OUTPUT;
+
$args = array(
'analyze',
'ansi' => '',
- $this->getErrorFormatOption() => 'checkstyle',
+ $this->getErrorFormatOption() => $errorFormat,
'level' => $this->config->value('phpstan.level'),
'configuration' => $neonFile,
$this->options->getAnalyzedDirs(' '),
diff --git a/tests/.ci/.phpqa.yml b/tests/.ci/.phpqa.yml
index ce34c82..fe83b8a 100644
--- a/tests/.ci/.phpqa.yml
+++ b/tests/.ci/.phpqa.yml
@@ -49,6 +49,8 @@ psalm:
phpstan:
level: 5 # last level without type hints
+ # only checkstyle has pretty html report in phqpa - https://phpstan.org/user-guide/output-format
+ errorFormat: table
# memoryLimit: 1G
# https://github.com/phpstan/phpstan#configuration
standard: phpstan.neon
diff --git a/tests/.ci/phpmd.xml b/tests/.ci/phpmd.xml
index 898654e..90e294c 100644
--- a/tests/.ci/phpmd.xml
+++ b/tests/.ci/phpmd.xml
@@ -8,6 +8,7 @@
+
diff --git a/tests/Config/ConfigTest.php b/tests/Config/ConfigTest.php
index c626435..6421578 100644
--- a/tests/Config/ConfigTest.php
+++ b/tests/Config/ConfigTest.php
@@ -25,6 +25,7 @@ public function testLoadDefaultConfig()
assertThat($config->value('phpmd.ignoreParsingErrors'), is(true));
assertThat($config->value('phpstan.level'), identicalTo(0));
assertThat($config->value('phpstan.memoryLimit'), is(nullValue()));
+ assertThat($config->value('phpstan.errorFormat'), is('checkstyle'));
assertThat($config->value('phpunit.config'), is(nullValue()));
assertThat($config->value('phpunit.reports.file'), is(emptyArray()));
assertThat($config->value('psalm.config'), is(nonEmptyString()));
@@ -38,6 +39,7 @@ public function testLoadDefaultConfig()
assertThat($config->value('phpmetrics.git'), identicalTo(false));
assertThat($config->value('pdepend.coverageReport'), is(nullValue()));
assertThat($config->value('deptrac.depfile'), is(nullValue()));
+ assertThat($config->value('deptrac.reportUncovered'), is(true));
assertThat($config->value('security-checker.composerLock'), is(nullValue()));
}
diff --git a/tests/RunningToolTest.php b/tests/RunningToolTest.php
index d18b98c..a2e3351 100644
--- a/tests/RunningToolTest.php
+++ b/tests/RunningToolTest.php
@@ -2,6 +2,8 @@
namespace Edge\QA;
+use Edge\QA\Tools\Analyzer\Phpstan;
+
/** @SuppressWarnings(PHPMD.TooManyPublicMethods) */
class RunningToolTest extends \PHPUnit_Framework_TestCase
{
@@ -128,4 +130,13 @@ public function testCreateUniqueIdForUserReport()
$report = $tool->getHtmlRootReports()[0];
assertThat($report['id'], is('phpcs-dir-path-php'));
}
+
+ public function testDynamicOutputModePhpstan()
+ {
+ $tool = new RunningTool('phpstan', [
+ 'outputMode' => null,
+ ]);
+ Phpstan::$SETTINGS['outputMode'] = OutputMode::RAW_CONSOLE_OUTPUT;
+ assertThat($tool->hasOutput(OutputMode::RAW_CONSOLE_OUTPUT), is(true));
+ }
}