diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index a3bfedc6..18a7493e 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -18,6 +18,7 @@
+
diff --git a/src/Collector/ClassDefinitionCollector.php b/src/Collector/ClassDefinitionCollector.php
index 8dc257a5..ba168cf8 100644
--- a/src/Collector/ClassDefinitionCollector.php
+++ b/src/Collector/ClassDefinitionCollector.php
@@ -34,7 +34,7 @@
* interfaces: array,
* }>
*/
-class ClassDefinitionCollector implements Collector
+final class ClassDefinitionCollector implements Collector
{
private ReflectionProvider $reflectionProvider;
diff --git a/src/Collector/ConstantFetchCollector.php b/src/Collector/ConstantFetchCollector.php
index f135130b..a4fa014d 100644
--- a/src/Collector/ConstantFetchCollector.php
+++ b/src/Collector/ConstantFetchCollector.php
@@ -29,7 +29,7 @@
/**
* @implements Collector>
*/
-class ConstantFetchCollector implements Collector
+final class ConstantFetchCollector implements Collector
{
use BufferedUsageCollector;
diff --git a/src/Collector/MethodCallCollector.php b/src/Collector/MethodCallCollector.php
index 8907c927..b33f7619 100644
--- a/src/Collector/MethodCallCollector.php
+++ b/src/Collector/MethodCallCollector.php
@@ -30,7 +30,7 @@
/**
* @implements Collector>
*/
-class MethodCallCollector implements Collector
+final class MethodCallCollector implements Collector
{
use BufferedUsageCollector;
diff --git a/src/Collector/ProvidedUsagesCollector.php b/src/Collector/ProvidedUsagesCollector.php
index 2f306eca..b10a2135 100644
--- a/src/Collector/ProvidedUsagesCollector.php
+++ b/src/Collector/ProvidedUsagesCollector.php
@@ -17,7 +17,7 @@
/**
* @implements Collector>
*/
-class ProvidedUsagesCollector implements Collector
+final class ProvidedUsagesCollector implements Collector
{
use BufferedUsageCollector;
diff --git a/src/Compatibility/BackwardCompatibilityChecker.php b/src/Compatibility/BackwardCompatibilityChecker.php
index 5d474f54..507025fa 100644
--- a/src/Compatibility/BackwardCompatibilityChecker.php
+++ b/src/Compatibility/BackwardCompatibilityChecker.php
@@ -9,7 +9,7 @@
use function implode;
use function var_export;
-class BackwardCompatibilityChecker
+final class BackwardCompatibilityChecker
{
/**
diff --git a/src/Debug/DebugUsagePrinter.php b/src/Debug/DebugUsagePrinter.php
index 9e7fbdae..0517e86b 100644
--- a/src/Debug/DebugUsagePrinter.php
+++ b/src/Debug/DebugUsagePrinter.php
@@ -28,7 +28,7 @@
use function strpos;
use function substr;
-class DebugUsagePrinter
+final class DebugUsagePrinter
{
public const ANY_MEMBER = "\0";
diff --git a/src/Excluder/MixedUsageExcluder.php b/src/Excluder/MixedUsageExcluder.php
index b6b3eb42..6c7d76b4 100644
--- a/src/Excluder/MixedUsageExcluder.php
+++ b/src/Excluder/MixedUsageExcluder.php
@@ -6,7 +6,7 @@
use PHPStan\Analyser\Scope;
use ShipMonk\PHPStan\DeadCode\Graph\ClassMemberUsage;
-class MixedUsageExcluder implements MemberUsageExcluder
+final class MixedUsageExcluder implements MemberUsageExcluder
{
private bool $enabled;
diff --git a/src/Excluder/TestsUsageExcluder.php b/src/Excluder/TestsUsageExcluder.php
index 7048af0d..105c4433 100644
--- a/src/Excluder/TestsUsageExcluder.php
+++ b/src/Excluder/TestsUsageExcluder.php
@@ -24,7 +24,7 @@
use function strpos;
use const JSON_ERROR_NONE;
-class TestsUsageExcluder implements MemberUsageExcluder
+final class TestsUsageExcluder implements MemberUsageExcluder
{
private ReflectionProvider $reflectionProvider;
diff --git a/src/Formatter/RemoveDeadCodeFormatter.php b/src/Formatter/RemoveDeadCodeFormatter.php
index 4f23a3d0..28d5498b 100644
--- a/src/Formatter/RemoveDeadCodeFormatter.php
+++ b/src/Formatter/RemoveDeadCodeFormatter.php
@@ -15,7 +15,7 @@
use function array_keys;
use function count;
-class RemoveDeadCodeFormatter implements ErrorFormatter
+final class RemoveDeadCodeFormatter implements ErrorFormatter
{
private FileSystem $fileSystem;
diff --git a/src/Hierarchy/ClassHierarchy.php b/src/Hierarchy/ClassHierarchy.php
index dba6a7d5..7eda7cf8 100644
--- a/src/Hierarchy/ClassHierarchy.php
+++ b/src/Hierarchy/ClassHierarchy.php
@@ -4,7 +4,7 @@
use function array_keys;
-class ClassHierarchy
+final class ClassHierarchy
{
/**
diff --git a/src/Output/OutputEnhancer.php b/src/Output/OutputEnhancer.php
index a9628831..6b56ead6 100644
--- a/src/Output/OutputEnhancer.php
+++ b/src/Output/OutputEnhancer.php
@@ -8,7 +8,7 @@
use function sprintf;
use function str_replace;
-class OutputEnhancer
+final class OutputEnhancer
{
private RelativePathHelper $relativePathHelper;
diff --git a/src/Provider/ApiPhpDocUsageProvider.php b/src/Provider/ApiPhpDocUsageProvider.php
index e2b1d5e3..49fb64d9 100644
--- a/src/Provider/ApiPhpDocUsageProvider.php
+++ b/src/Provider/ApiPhpDocUsageProvider.php
@@ -9,7 +9,7 @@
use ShipMonk\PHPStan\DeadCode\Reflection\ReflectionHelper;
use function strpos;
-class ApiPhpDocUsageProvider extends ReflectionBasedMemberUsageProvider
+final class ApiPhpDocUsageProvider extends ReflectionBasedMemberUsageProvider
{
private ReflectionProvider $reflectionProvider;
diff --git a/src/Provider/BuiltinUsageProvider.php b/src/Provider/BuiltinUsageProvider.php
index a4483cf9..8051f081 100644
--- a/src/Provider/BuiltinUsageProvider.php
+++ b/src/Provider/BuiltinUsageProvider.php
@@ -7,7 +7,7 @@
use ReflectionMethod;
use Reflector;
-class BuiltinUsageProvider extends ReflectionBasedMemberUsageProvider
+final class BuiltinUsageProvider extends ReflectionBasedMemberUsageProvider
{
private bool $enabled;
diff --git a/src/Provider/DoctrineUsageProvider.php b/src/Provider/DoctrineUsageProvider.php
index 21ad56ee..42670cec 100644
--- a/src/Provider/DoctrineUsageProvider.php
+++ b/src/Provider/DoctrineUsageProvider.php
@@ -20,7 +20,7 @@
use ShipMonk\PHPStan\DeadCode\Graph\ClassMethodUsage;
use ShipMonk\PHPStan\DeadCode\Graph\UsageOrigin;
-class DoctrineUsageProvider implements MemberUsageProvider
+final class DoctrineUsageProvider implements MemberUsageProvider
{
private bool $enabled;
@@ -147,7 +147,7 @@ private function getUsagesOfEventSubscriber(
return $usages;
}
- protected function shouldMarkMethodAsUsed(ReflectionMethod $method): ?string
+ private function shouldMarkMethodAsUsed(ReflectionMethod $method): ?string
{
$methodName = $method->getName();
$class = $method->getDeclaringClass();
@@ -171,7 +171,7 @@ protected function shouldMarkMethodAsUsed(ReflectionMethod $method): ?string
return null;
}
- protected function isLifecycleEventMethod(ReflectionMethod $method): bool
+ private function isLifecycleEventMethod(ReflectionMethod $method): bool
{
return $this->hasAttribute($method, 'Doctrine\ORM\Mapping\PostLoad')
|| $this->hasAttribute($method, 'Doctrine\ORM\Mapping\PostPersist')
@@ -186,7 +186,7 @@ protected function isLifecycleEventMethod(ReflectionMethod $method): bool
* Ideally, we would need to parse DIC xml to know this for sure just like phpstan-symfony does.
* - see Doctrine\ORM\Events::*
*/
- protected function isProbablyDoctrineListener(string $methodName): bool
+ private function isProbablyDoctrineListener(string $methodName): bool
{
return $methodName === 'preRemove'
|| $methodName === 'postRemove'
@@ -203,7 +203,7 @@ protected function isProbablyDoctrineListener(string $methodName): bool
|| $methodName === 'onClear';
}
- protected function hasAttribute(
+ private function hasAttribute(
ReflectionMethod $method,
string $attributeClass
): bool
@@ -211,7 +211,7 @@ protected function hasAttribute(
return $method->getAttributes($attributeClass) !== [];
}
- protected function isPartOfAsEntityListener(
+ private function isPartOfAsEntityListener(
ReflectionClass $class,
string $methodName
): bool
@@ -227,7 +227,7 @@ protected function isPartOfAsEntityListener(
return false;
}
- protected function isEntityRepositoryConstructor(
+ private function isEntityRepositoryConstructor(
ReflectionClass $class,
ReflectionMethod $method
): bool
diff --git a/src/Provider/EnumUsageProvider.php b/src/Provider/EnumUsageProvider.php
index 79b4a173..bfa76dbd 100644
--- a/src/Provider/EnumUsageProvider.php
+++ b/src/Provider/EnumUsageProvider.php
@@ -24,7 +24,7 @@
use function is_int;
use function is_string;
-class EnumUsageProvider implements MemberUsageProvider
+final class EnumUsageProvider implements MemberUsageProvider
{
private bool $enabled;
diff --git a/src/Provider/NetteUsageProvider.php b/src/Provider/NetteUsageProvider.php
index 20339206..cdc9a8b8 100644
--- a/src/Provider/NetteUsageProvider.php
+++ b/src/Provider/NetteUsageProvider.php
@@ -18,7 +18,7 @@
use function ucfirst;
use const PREG_SET_ORDER;
-class NetteUsageProvider extends ReflectionBasedMemberUsageProvider
+final class NetteUsageProvider extends ReflectionBasedMemberUsageProvider
{
private ReflectionProvider $reflectionProvider;
diff --git a/src/Provider/PhpStanUsageProvider.php b/src/Provider/PhpStanUsageProvider.php
index 765504fe..a8dbec9f 100644
--- a/src/Provider/PhpStanUsageProvider.php
+++ b/src/Provider/PhpStanUsageProvider.php
@@ -5,7 +5,7 @@
use PHPStan\DependencyInjection\Container;
use ReflectionMethod;
-class PhpStanUsageProvider extends ReflectionBasedMemberUsageProvider
+final class PhpStanUsageProvider extends ReflectionBasedMemberUsageProvider
{
private bool $enabled;
diff --git a/src/Provider/PhpUnitUsageProvider.php b/src/Provider/PhpUnitUsageProvider.php
index 30457fec..5fd55b8a 100644
--- a/src/Provider/PhpUnitUsageProvider.php
+++ b/src/Provider/PhpUnitUsageProvider.php
@@ -18,7 +18,7 @@
use function is_string;
use function strpos;
-class PhpUnitUsageProvider implements MemberUsageProvider
+final class PhpUnitUsageProvider implements MemberUsageProvider
{
private bool $enabled;
diff --git a/src/Provider/ReflectionUsageProvider.php b/src/Provider/ReflectionUsageProvider.php
index 62e946de..7bc53b26 100644
--- a/src/Provider/ReflectionUsageProvider.php
+++ b/src/Provider/ReflectionUsageProvider.php
@@ -23,7 +23,7 @@
use function count;
use function in_array;
-class ReflectionUsageProvider implements MemberUsageProvider
+final class ReflectionUsageProvider implements MemberUsageProvider
{
private bool $enabled;
diff --git a/src/Provider/SymfonyUsageProvider.php b/src/Provider/SymfonyUsageProvider.php
index 10763dad..575c65e9 100644
--- a/src/Provider/SymfonyUsageProvider.php
+++ b/src/Provider/SymfonyUsageProvider.php
@@ -47,7 +47,7 @@
use function sprintf;
use function strpos;
-class SymfonyUsageProvider implements MemberUsageProvider
+final class SymfonyUsageProvider implements MemberUsageProvider
{
private bool $enabled;
@@ -353,7 +353,7 @@ private function getMethodUsagesFromAttributeReflection(
return $usages;
}
- protected function shouldMarkAsUsed(ReflectionMethod $method): ?string
+ private function shouldMarkAsUsed(ReflectionMethod $method): ?string
{
if ($this->isBundleConstructor($method)) {
return 'Bundle constructor (created by Kernel)';
@@ -390,7 +390,7 @@ protected function shouldMarkAsUsed(ReflectionMethod $method): ?string
return null;
}
- protected function fillDicClasses(string $containerXmlPath): void
+ private function fillDicClasses(string $containerXmlPath): void
{
$fileContents = file_get_contents($containerXmlPath);
@@ -480,17 +480,17 @@ private function buildXmlServiceMap(SimpleXMLElement $serviceDefinitions): array
return $serviceMap;
}
- protected function isBundleConstructor(ReflectionMethod $method): bool
+ private function isBundleConstructor(ReflectionMethod $method): bool
{
return $method->isConstructor() && $method->getDeclaringClass()->isSubclassOf('Symfony\Component\HttpKernel\Bundle\Bundle');
}
- protected function isAutowiredWithRequiredAttribute(ReflectionMethod $method): bool
+ private function isAutowiredWithRequiredAttribute(ReflectionMethod $method): bool
{
return $this->hasAttribute($method, 'Symfony\Contracts\Service\Attribute\Required');
}
- protected function isEventListenerMethodWithAsEventListenerAttribute(ReflectionMethod $method): bool
+ private function isEventListenerMethodWithAsEventListenerAttribute(ReflectionMethod $method): bool
{
$class = $method->getDeclaringClass();
@@ -498,19 +498,19 @@ protected function isEventListenerMethodWithAsEventListenerAttribute(ReflectionM
|| $this->hasAttribute($method, 'Symfony\Component\EventDispatcher\Attribute\AsEventListener');
}
- protected function isConstructorWithAsCommandAttribute(ReflectionMethod $method): bool
+ private function isConstructorWithAsCommandAttribute(ReflectionMethod $method): bool
{
$class = $method->getDeclaringClass();
return $method->isConstructor() && $this->hasAttribute($class, 'Symfony\Component\Console\Attribute\AsCommand');
}
- protected function isConstructorWithAsControllerAttribute(ReflectionMethod $method): bool
+ private function isConstructorWithAsControllerAttribute(ReflectionMethod $method): bool
{
$class = $method->getDeclaringClass();
return $method->isConstructor() && $this->hasAttribute($class, 'Symfony\Component\HttpKernel\Attribute\AsController');
}
- protected function isMethodWithRouteAttribute(ReflectionMethod $method): bool
+ private function isMethodWithRouteAttribute(ReflectionMethod $method): bool
{
$isInstanceOf = 2; // ReflectionAttribute::IS_INSTANCEOF, since PHP 8.0
@@ -518,7 +518,7 @@ protected function isMethodWithRouteAttribute(ReflectionMethod $method): bool
|| $this->hasAttribute($method, 'Symfony\Component\Routing\Annotation\Route', $isInstanceOf);
}
- protected function isMethodWithCallbackConstraintAttribute(ReflectionMethod $method): bool
+ private function isMethodWithCallbackConstraintAttribute(ReflectionMethod $method): bool
{
$attributes = $method->getDeclaringClass()->getAttributes('Symfony\Component\Validator\Constraints\Callback');
@@ -538,7 +538,7 @@ protected function isMethodWithCallbackConstraintAttribute(ReflectionMethod $met
/**
* Ideally, we would need to parse DIC xml to know this for sure just like phpstan-symfony does.
*/
- protected function isProbablySymfonyListener(ReflectionMethod $method): bool
+ private function isProbablySymfonyListener(ReflectionMethod $method): bool
{
$methodName = $method->getName();
@@ -555,7 +555,7 @@ protected function isProbablySymfonyListener(ReflectionMethod $method): bool
* @param ReflectionClass|ReflectionMethod $classOrMethod
* @param ReflectionAttribute::IS_*|0 $flags
*/
- protected function hasAttribute(
+ private function hasAttribute(
Reflector $classOrMethod,
string $attributeClass,
int $flags = 0
diff --git a/src/Provider/TwigUsageProvider.php b/src/Provider/TwigUsageProvider.php
index c72056eb..bacbca8b 100644
--- a/src/Provider/TwigUsageProvider.php
+++ b/src/Provider/TwigUsageProvider.php
@@ -21,7 +21,7 @@
use function explode;
use function in_array;
-class TwigUsageProvider implements MemberUsageProvider
+final class TwigUsageProvider implements MemberUsageProvider
{
private bool $enabled;
@@ -178,7 +178,7 @@ private function getMethodUsagesFromReflection(InClassNode $node): array
return $usages;
}
- protected function shouldMarkAsUsed(ReflectionMethod $method): ?string
+ private function shouldMarkAsUsed(ReflectionMethod $method): ?string
{
if ($this->isMethodWithAsTwigFilterAttribute($method)) {
return 'Twig filter method via #[AsTwigFilter] attribute';
@@ -195,22 +195,22 @@ protected function shouldMarkAsUsed(ReflectionMethod $method): ?string
return null;
}
- protected function isMethodWithAsTwigFilterAttribute(ReflectionMethod $method): bool
+ private function isMethodWithAsTwigFilterAttribute(ReflectionMethod $method): bool
{
return $this->hasAttribute($method, 'Twig\Attribute\AsTwigFilter');
}
- protected function isMethodWithAsTwigFunctionAttribute(ReflectionMethod $method): bool
+ private function isMethodWithAsTwigFunctionAttribute(ReflectionMethod $method): bool
{
return $this->hasAttribute($method, 'Twig\Attribute\AsTwigFunction');
}
- protected function isMethodWithAsTwigTestAttribute(ReflectionMethod $method): bool
+ private function isMethodWithAsTwigTestAttribute(ReflectionMethod $method): bool
{
return $this->hasAttribute($method, 'Twig\Attribute\AsTwigTest');
}
- protected function hasAttribute(
+ private function hasAttribute(
ReflectionMethod $method,
string $attributeClass
): bool
diff --git a/src/Provider/VendorUsageProvider.php b/src/Provider/VendorUsageProvider.php
index 47fc5dc0..74db0262 100644
--- a/src/Provider/VendorUsageProvider.php
+++ b/src/Provider/VendorUsageProvider.php
@@ -12,7 +12,7 @@
use function strpos;
use function substr;
-class VendorUsageProvider extends ReflectionBasedMemberUsageProvider
+final class VendorUsageProvider extends ReflectionBasedMemberUsageProvider
{
/**
diff --git a/src/Rule/DeadCodeRule.php b/src/Rule/DeadCodeRule.php
index 0a8fffe8..7b6b1cab 100644
--- a/src/Rule/DeadCodeRule.php
+++ b/src/Rule/DeadCodeRule.php
@@ -46,7 +46,7 @@
/**
* @implements Rule
*/
-class DeadCodeRule implements Rule, DiagnoseExtension
+final class DeadCodeRule implements Rule, DiagnoseExtension
{
public const IDENTIFIER_METHOD = 'shipmonk.deadMethod';
diff --git a/src/Transformer/FileSystem.php b/src/Transformer/FileSystem.php
index 0a34df30..0bd55397 100644
--- a/src/Transformer/FileSystem.php
+++ b/src/Transformer/FileSystem.php
@@ -6,7 +6,7 @@
use function file_get_contents;
use function file_put_contents;
-class FileSystem
+class FileSystem // phpcs:ignore SlevomatCodingStandard.Classes.RequireAbstractOrFinal -- mocking needed
{
public function read(string $path): string
diff --git a/src/Transformer/RemoveClassMemberVisitor.php b/src/Transformer/RemoveClassMemberVisitor.php
index 41baf89e..1ed32c0a 100644
--- a/src/Transformer/RemoveClassMemberVisitor.php
+++ b/src/Transformer/RemoveClassMemberVisitor.php
@@ -16,7 +16,7 @@
use function array_fill_keys;
use function ltrim;
-class RemoveClassMemberVisitor extends NodeVisitorAbstract
+final class RemoveClassMemberVisitor extends NodeVisitorAbstract
{
private string $currentNamespace = '';
diff --git a/src/Transformer/RemoveDeadCodeTransformer.php b/src/Transformer/RemoveDeadCodeTransformer.php
index edbc526d..ae62da9d 100644
--- a/src/Transformer/RemoveDeadCodeTransformer.php
+++ b/src/Transformer/RemoveDeadCodeTransformer.php
@@ -10,7 +10,7 @@
use PhpParser\Parser\Php8;
use PhpParser\PrettyPrinter\Standard as PhpPrinter;
-class RemoveDeadCodeTransformer
+final class RemoveDeadCodeTransformer
{
private Lexer $phpLexer;
diff --git a/tests/AllServicesInConfigTest.php b/tests/AllServicesInConfigTest.php
index 43bc7b7b..471d6ace 100644
--- a/tests/AllServicesInConfigTest.php
+++ b/tests/AllServicesInConfigTest.php
@@ -26,7 +26,7 @@
use function str_replace;
use function trait_exists;
-class AllServicesInConfigTest extends PHPStanTestCase
+final class AllServicesInConfigTest extends PHPStanTestCase
{
/**
diff --git a/tests/Graph/SerializationTest.php b/tests/Graph/SerializationTest.php
index f073f8d0..0ab3ccac 100644
--- a/tests/Graph/SerializationTest.php
+++ b/tests/Graph/SerializationTest.php
@@ -5,7 +5,7 @@
use PHPStan\TrinaryLogic;
use PHPUnit\Framework\TestCase;
-class SerializationTest extends TestCase
+final class SerializationTest extends TestCase
{
/**
diff --git a/tests/ParamsArePassedToServicesTest.php b/tests/ParamsArePassedToServicesTest.php
index b42ad5ec..50dc18ef 100644
--- a/tests/ParamsArePassedToServicesTest.php
+++ b/tests/ParamsArePassedToServicesTest.php
@@ -8,7 +8,7 @@
use function is_array;
use function strpos;
-class ParamsArePassedToServicesTest extends PHPStanTestCase
+final class ParamsArePassedToServicesTest extends PHPStanTestCase
{
/**
diff --git a/tests/Rule/DeadCodeRuleTest.php b/tests/Rule/DeadCodeRuleTest.php
index 120e9c80..ad6a476a 100644
--- a/tests/Rule/DeadCodeRuleTest.php
+++ b/tests/Rule/DeadCodeRuleTest.php
@@ -75,7 +75,7 @@
/**
* @extends RuleTestCase
*/
-class DeadCodeRuleTest extends RuleTestCase
+final class DeadCodeRuleTest extends RuleTestCase
{
/**