Skip to content

Commit 12fd572

Browse files
authored
Merge pull request #9 from moufmouf/master
Methods of extended classes are now properly ignored.
2 parents 5e12b22 + a92ead0 commit 12fd572

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

src/Rules/TypeHints/AbstractMissingTypeHintRule.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ private function isInherited(ReflectionMethod $method, ReflectionClass $class =
313313

314314
$parentClass = $class->getParentClass();
315315
if ($parentClass !== null) {
316+
if ($parentClass->hasMethod($method->getName())) {
317+
return true;
318+
}
316319
return $this->isInherited($method, $parentClass);
317320
}
318321

tests/Rules/TypeHints/MissingTypeHintRuleInMethodTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public function testCheckCatchedException()
2121
'In method "Foo::test", parameter $no_type_hint has no type-hint and no @param annotation.',
2222
5,
2323
],
24-
]);
24+
[
25+
'In method "Baz::notInherited", parameter $no_type_hint has no type-hint and no @param annotation.',
26+
36,
27+
],
28+
29+
]);
2530
}
2631
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
4+
namespace TheCodingMachine\PHPStan\Rules\TypeHints\data;
5+
6+
class ParentStubClass
7+
{
8+
public function bazbaz($no_type_hint) {
9+
10+
}
11+
}
12+
13+
14+
class StubClass extends ParentStubClass
15+
{
16+
public function baz($no_type_hint) {
17+
18+
}
19+
}

tests/Rules/TypeHints/data/typehints_in_methods.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,22 @@ public function foo($no_type_hint): void
1919
{
2020
}
2121
}
22+
23+
class BazClass extends \TheCodingMachine\PHPStan\Rules\TypeHints\data\StubClass
24+
{
25+
// Extended function
26+
public function baz($no_type_hint)
27+
{
28+
29+
}
30+
31+
public function bazbaz($no_type_hint)
32+
{
33+
34+
}
35+
36+
public function notInherited($no_type_hint): void
37+
{
38+
39+
}
40+
}

0 commit comments

Comments
 (0)