Skip to content

Methods of extended classes are now properly ignored. #9

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 1 commit into from
Jul 17, 2017
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
3 changes: 3 additions & 0 deletions src/Rules/TypeHints/AbstractMissingTypeHintRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ private function isInherited(ReflectionMethod $method, ReflectionClass $class =

$parentClass = $class->getParentClass();
if ($parentClass !== null) {
if ($parentClass->hasMethod($method->getName())) {
return true;
}
return $this->isInherited($method, $parentClass);
}

Expand Down
7 changes: 6 additions & 1 deletion tests/Rules/TypeHints/MissingTypeHintRuleInMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public function testCheckCatchedException()
'In method "Foo::test", parameter $no_type_hint has no type-hint and no @param annotation.',
5,
],
]);
[
'In method "Baz::notInherited", parameter $no_type_hint has no type-hint and no @param annotation.',
36,
],

]);
}
}
19 changes: 19 additions & 0 deletions tests/Rules/TypeHints/data/StubClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php


namespace TheCodingMachine\PHPStan\Rules\TypeHints\data;

class ParentStubClass
{
public function bazbaz($no_type_hint) {

}
}


class StubClass extends ParentStubClass
{
public function baz($no_type_hint) {

}
}
19 changes: 19 additions & 0 deletions tests/Rules/TypeHints/data/typehints_in_methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,22 @@ public function foo($no_type_hint): void
{
}
}

class BazClass extends \TheCodingMachine\PHPStan\Rules\TypeHints\data\StubClass
{
// Extended function
public function baz($no_type_hint)
{

}

public function bazbaz($no_type_hint)
{

}

public function notInherited($no_type_hint): void
{

}
}