Skip to content

Commit

Permalink
Tools - fix building xml for psalm v4
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zdenekdrahos committed Feb 3, 2021
1 parent 148151c commit 4df3a71
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
9 changes: 1 addition & 8 deletions src/Tools/Analyzer/Phpcpd.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand All @@ -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', '<');
}
}
4 changes: 1 addition & 3 deletions src/Tools/Analyzer/Phpstan.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
5 changes: 5 additions & 0 deletions src/Tools/Analyzer/Psalm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
7 changes: 7 additions & 0 deletions src/Tools/Tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4df3a71

Please sign in to comment.