From 4df3a718bc6c368af63f56b887d956dd988f1313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zdene=CC=8Ck=20Drahos=CC=8C?= Date: Wed, 3 Feb 2021 11:06:40 +0100 Subject: [PATCH] Tools - fix building xml for psalm v4 https://github.com/EdgedesignCZ/phpqa/pull/218/checks?check_run_id=1821520385#step:7:28 Could not resolve config path to /home/runner/work/phpqa/phpqa/build//vendor https://github.com/vimeo/psalm/releases/tag/4.0.0 Change default on resolveFromConfigFile to "true". This means if your Psalm config is not in the same directory that you run Psalm from, and you want to keep all the paths correct, you'll need to add resolveFromConfigFile="false" to maintain existing path resolution https://github.com/EdgedesignCZ/phpqa/pull/218/checks?check_run_id=1821586719#step:7:28 Element '{https://getpsalm.org/schema/config}resolveFromConfigFile': This element is not expected. https://github.com/EdgedesignCZ/phpqa/pull/218/checks?check_run_id=1821638632#step:7:23 psalm v1: The attribute 'resolveFromConfigFile' is not allowed. --- src/Tools/Analyzer/Phpcpd.php | 9 +-------- src/Tools/Analyzer/Phpstan.php | 4 +--- src/Tools/Analyzer/Psalm.php | 5 +++++ src/Tools/Tool.php | 7 +++++++ 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Tools/Analyzer/Phpcpd.php b/src/Tools/Analyzer/Phpcpd.php index da519d41..53e3ee27 100644 --- a/src/Tools/Analyzer/Phpcpd.php +++ b/src/Tools/Analyzer/Phpcpd.php @@ -21,7 +21,7 @@ public function __invoke() 'min-lines' => $this->config->value('phpcpd.minLines'), 'min-tokens' => $this->config->value('phpcpd.minTokens'), ); - $isOlderVersion = $this->isOlderVersionThanV6(); + $isOlderVersion = $this->toolVersionIs('<', '6'); $phpcpdNames = array_map( function ($extension) use ($isOlderVersion) { return $isOlderVersion ? "*.{$extension}" : ".{$extension}"; @@ -40,11 +40,4 @@ function ($extension) use ($isOlderVersion) { } return $args; } - - private function isOlderVersionThanV6() - { - $versions = new GetVersions(); - $composerVersion = $versions->getToolVersion(self::$SETTINGS); - return $composerVersion && version_compare($composerVersion, '6', '<'); - } } diff --git a/src/Tools/Analyzer/Phpstan.php b/src/Tools/Analyzer/Phpstan.php index 2a11834f..c8775861 100644 --- a/src/Tools/Analyzer/Phpstan.php +++ b/src/Tools/Analyzer/Phpstan.php @@ -65,8 +65,6 @@ function ($relativeDir) { private function getErrorFormatOption() { - $versions = new GetVersions(); - $phsptanVersion = $versions->getToolVersion(self::$SETTINGS); - return $phsptanVersion && version_compare($phsptanVersion, '0.10.3', '<') ? 'errorFormat' : 'error-format'; + return $this->toolVersionIs('<', '0.10.3') ? 'errorFormat' : 'error-format'; } } diff --git a/src/Tools/Analyzer/Psalm.php b/src/Tools/Analyzer/Psalm.php index 9280bc1b..aefd9a9d 100644 --- a/src/Tools/Analyzer/Psalm.php +++ b/src/Tools/Analyzer/Psalm.php @@ -47,6 +47,11 @@ private function updateProjectFiles($rawXml) { $xml = new SimpleXMLElement($rawXml); + $attributes = $xml->attributes(); + if (!isset($attributes['resolveFromConfigFile']) && $this->toolVersionIs('>=', '4')) { + $xml->addAttribute('resolveFromConfigFile', 'false'); + } + if (!isset($xml->projectFiles)) { $xml->addChild('projectFiles'); } diff --git a/src/Tools/Tool.php b/src/Tools/Tool.php index 3e2567f8..df9b0ab7 100644 --- a/src/Tools/Tool.php +++ b/src/Tools/Tool.php @@ -35,6 +35,13 @@ protected function saveDynamicConfig($config, $fileExtension) return \Edge\QA\escapePath($file); } + protected function toolVersionIs($operator, $version) + { + $versions = new GetVersions(); + $composerVersion = $versions->getToolVersion(static::$SETTINGS); + return $composerVersion && version_compare($composerVersion, $version, $operator); + } + protected function writeln($text) { $this->presenter->__invoke($text);