Skip to content

Commit 4ae54c0

Browse files
committed
Compare tests with TomasVotruba/unused-public
1 parent 923ac93 commit 4ae54c0

File tree

4 files changed

+165
-2
lines changed

4 files changed

+165
-2
lines changed

compare.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
// usage: vendor/bin/phpstan analyse -v -c compare.phpstan.neon --error-format=prettyJson tests/Rule/data/DeadMethodRule/*.php | php compare.php
5+
6+
$errors = json_decode(file_get_contents("php://stdin"), true);
7+
8+
function transformMessage(string $message): string
9+
{
10+
$replace = [
11+
'Public method "' => 'Unused ',
12+
'()" is never used' => '',
13+
];
14+
return str_replace(array_keys($replace), array_values($replace), $message);
15+
}
16+
17+
$iterator = new DirectoryIterator(__DIR__ . '/tests/Rule/data/DeadMethodRule');
18+
19+
foreach ($iterator as $fileinfo) {
20+
if (!$fileinfo->isFile() || $fileinfo->getExtension() !== 'php') {
21+
continue;
22+
}
23+
$filePath = $fileinfo->getPathname();
24+
25+
$contents = file_get_contents($filePath);
26+
$contentsLines = explode("\n", $contents);
27+
28+
foreach ($contentsLines as $line => $row) {
29+
$newLine = preg_replace('~ ?// error.*$~', '', $row);
30+
$contentsLines[$line] = $newLine;
31+
}
32+
33+
foreach ($errors['files'][$filePath]['messages'] ?? [] as $error) {
34+
$line = $error['line'];
35+
$contentsLines[$line - 1] .= ' // error: ' . transformMessage($error['message']);
36+
}
37+
38+
file_put_contents($filePath, implode("\n", $contentsLines));
39+
}

compare.phpstan.neon

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
includes:
2+
- vendor/tomasvotruba/unused-public/config/extension.neon
3+
4+
parameters:
5+
customRulesetUsed: true
6+
7+
unused_public:
8+
methods: true

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"slevomat/coding-standard": "^8.15.0",
3333
"symfony/contracts": "^2.5 || ^3.0",
3434
"symfony/event-dispatcher": "^5.4 || ^6.0 || ^7.0",
35-
"symfony/routing": "^5.4 || ^6.0 || ^7.0"
35+
"symfony/routing": "^5.4 || ^6.0 || ^7.0",
36+
"tomasvotruba/unused-public": "^0.3.11"
3637
},
3738
"autoload": {
3839
"psr-4": {

composer.lock

Lines changed: 116 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)