Skip to content

Commit 33cf2c2

Browse files
authored
Report dead method line at its name (#192)
1 parent 6619705 commit 33cf2c2

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

src/Collector/ClassDefinitionCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function processNode(
7676

7777
foreach ($node->getMethods() as $method) {
7878
$methods[$method->name->toString()] = [
79-
'line' => $method->getStartLine(),
79+
'line' => $method->name->getStartLine(),
8080
'params' => count($method->params),
8181
'abstract' => $method->isAbstract() || $node instanceof Interface_,
8282
'visibility' => $method->flags & (Visibility::PUBLIC | Visibility::PROTECTED | Visibility::PRIVATE),

tests/Rule/DeadCodeRuleTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ public static function provideGroupingFiles(): Traversable
546546
[
547547
[
548548
'Unused AttributeGrouping\Foo::endpoint',
549-
9,
549+
10,
550550
],
551551
],
552552
];
@@ -761,6 +761,9 @@ public static function provideFiles(): Traversable
761761
yield 'mixed-member-const-traits-10' => [__DIR__ . '/data/mixed-member/traits-const-10.php'];
762762
yield 'mixed-member-const-traits-14' => [__DIR__ . '/data/mixed-member/traits-const-14.php'];
763763
yield 'mixed-member-const-traits-21' => [__DIR__ . '/data/mixed-member/traits-const-21.php'];
764+
765+
// other
766+
yield 'report-lines' => [__DIR__ . '/data/other/report-lines.php'];
764767
}
765768

766769
/**
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace ReportLines;
4+
5+
class Foo
6+
{
7+
public
8+
const
9+
BAR // error: Unused ReportLines\Foo::BAR
10+
=
11+
1
12+
;
13+
14+
#[
15+
Bar
16+
]
17+
public
18+
function
19+
endpoint // error: Unused ReportLines\Foo::endpoint
20+
()
21+
:
22+
void
23+
{
24+
}
25+
26+
}

tests/Rule/data/providers/symfony.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ private function setDependency(): void
3131
{
3232
}
3333

34-
#[Unknown] // error: Unused Symfony\SomeController::dead
35-
public function dead(): void
34+
#[Unknown]
35+
public function dead(): void // error: Unused Symfony\SomeController::dead
3636
{
3737
}
3838

0 commit comments

Comments
 (0)