Skip to content

Commit c5a5ade

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

File tree

4 files changed

+158
-2
lines changed

4 files changed

+158
-2
lines changed

compare.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
foreach ($errors['files'] as $file => $data) {
18+
$contents = file_get_contents($file);
19+
$contentsLines = explode("\n", $contents);
20+
21+
foreach ($contentsLines as $line => $row) {
22+
$newLine = preg_replace('~ ?// error.*$~', '', $row);
23+
$contentsLines[$line] = $newLine;
24+
}
25+
26+
foreach ($data['messages'] as $error) {
27+
$line = $error['line'];
28+
$contentsLines[$line - 1] .= ' // error: ' . transformMessage($error['message']);
29+
}
30+
31+
file_put_contents($file, implode("\n", $contentsLines));
32+
}

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)