Skip to content

Use new "output" parameter instead of "xml-dump" in deptrac v0.19 #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"phpstan/phpstan-strict-rules": "^0.12",
"phpunit/phpunit": "^9.5",
"psalm/plugin-phpunit": "^0.15.0",
"qossmic/deptrac-shim": "^0.13.0",
"qossmic/deptrac-shim": "^0.19.0",
"rector/rector": "^0.8.56",
"squizlabs/php_codesniffer": "^3.5",
"symplify/easy-coding-standard-prefixed": "^9",
Expand Down
15 changes: 0 additions & 15 deletions depfile.yaml

This file was deleted.

16 changes: 16 additions & 0 deletions deptrac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
parameters:
paths:
- ./src
- ./tests
layers:
- name: Sources
collectors:
- type: directory
regex: src/.*
- name: Tests
collectors:
- type: directory
regex: tests/.*
ruleset:
Tests:
- Sources
22 changes: 21 additions & 1 deletion src/Tools/Deptrac.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Spaceemotion\PhpCodingStandard\Formatter\Result;
use Spaceemotion\PhpCodingStandard\Formatter\Violation;

use function preg_match;

class Deptrac extends Tool
{
/** @var string */
Expand All @@ -23,7 +25,9 @@ public function run(Context $context): bool
'--formatter=xml',
'--no-progress',
'--no-interaction',
"--xml-dump={$outputFile}",
$this->useNewOutputFormat()
? "--output={$outputFile}"
: "--xml-dump={$outputFile}",
]) === 0
) {
return true;
Expand Down Expand Up @@ -60,4 +64,20 @@ public function run(Context $context): bool

return false;
}

protected function useNewOutputFormat(): bool
{
$output = [];
$matches = [];

$this->execute(self::vendorBinary('deptrac'), ['--version'], $output);

preg_match('/(?<version>[\d.]+)/', implode(' ', $output), $matches);

if (isset($matches['version'])) {
return ((float) $matches['version']) >= 0.19;
}

return false;
}
}