diff --git a/src/PublicClassMethodMatcher.php b/src/PublicClassMethodMatcher.php index c3d6572..448003b 100644 --- a/src/PublicClassMethodMatcher.php +++ b/src/PublicClassMethodMatcher.php @@ -62,7 +62,7 @@ public function isUsedByParentClassOrInterface(ClassReflection $classReflection, public function shouldSkipClassMethod(ClassMethod $classMethod): bool { - if (! $classMethod->isPublic()) { + if ($classMethod->isPrivate()) { return true; } diff --git a/tests/Rules/UnusedPublicClassMethodRule/Fixture/SkipLocallyUsedProtectedMethod.php b/tests/Rules/UnusedPublicClassMethodRule/Fixture/SkipLocallyUsedProtectedMethod.php new file mode 100644 index 0000000..3aa8761 --- /dev/null +++ b/tests/Rules/UnusedPublicClassMethodRule/Fixture/SkipLocallyUsedProtectedMethod.php @@ -0,0 +1,17 @@ +runHere(); + } +} diff --git a/tests/Rules/UnusedPublicClassMethodRule/Fixture/StaticProtectedMethod.php b/tests/Rules/UnusedPublicClassMethodRule/Fixture/StaticProtectedMethod.php new file mode 100644 index 0000000..ff4f48f --- /dev/null +++ b/tests/Rules/UnusedPublicClassMethodRule/Fixture/StaticProtectedMethod.php @@ -0,0 +1,16 @@ +analyse($filePaths, $expectedErrorMessagesWithLines); @@ -76,6 +78,17 @@ public static function provideDataSymfony(): Iterator ], []]; } + public static function provideProtectedMethodData(): Iterator + { + yield [[__DIR__ . '/Fixture/SkipLocallyUsedProtectedMethod.php'], []]; + + $errorMessage = sprintf(UnusedPublicClassMethodRule::ERROR_MESSAGE, StaticProtectedMethod::class, 'runHere'); + yield [[ + __DIR__ . '/Source/StaticProtectedCalls.php', + __DIR__ . '/Fixture/StaticProtectedMethod.php', + ], [[$errorMessage, 9, RuleTips::SOLUTION_MESSAGE]]]; + } + public static function provideData(): Iterator { yield [[__DIR__ . '/Fixture/SkipLocallyUsedPublicMethod.php'], []];