Skip to content
Open
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
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<exclude name="SlevomatCodingStandard.Commenting.ForbiddenAnnotations.AnnotationForbidden"/><!-- It removes @dataProvider, but PHPUnit 9 does not yet have #[DataProvider] -->
</rule>

<rule ref="SlevomatCodingStandard.Classes.RequireAbstractOrFinal"/>
<rule ref="SlevomatCodingStandard.Functions.DisallowTrailingCommaInDeclaration">
<properties>
<property name="onlySingleLine" value="false"/>
Expand Down
2 changes: 1 addition & 1 deletion src/Collector/ClassDefinitionCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* interfaces: array<string, null>,
* }>
*/
class ClassDefinitionCollector implements Collector
final class ClassDefinitionCollector implements Collector
{

private ReflectionProvider $reflectionProvider;
Expand Down
2 changes: 1 addition & 1 deletion src/Collector/ConstantFetchCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/**
* @implements Collector<Node, list<string>>
*/
class ConstantFetchCollector implements Collector
final class ConstantFetchCollector implements Collector
{

use BufferedUsageCollector;
Expand Down
2 changes: 1 addition & 1 deletion src/Collector/MethodCallCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* @implements Collector<Node, list<string>>
*/
class MethodCallCollector implements Collector
final class MethodCallCollector implements Collector
{

use BufferedUsageCollector;
Expand Down
2 changes: 1 addition & 1 deletion src/Collector/ProvidedUsagesCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* @implements Collector<Node, list<string>>
*/
class ProvidedUsagesCollector implements Collector
final class ProvidedUsagesCollector implements Collector
{

use BufferedUsageCollector;
Expand Down
2 changes: 1 addition & 1 deletion src/Compatibility/BackwardCompatibilityChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use function implode;
use function var_export;

class BackwardCompatibilityChecker
final class BackwardCompatibilityChecker
{

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/DebugUsagePrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
use function strpos;
use function substr;

class DebugUsagePrinter
final class DebugUsagePrinter
{

public const ANY_MEMBER = "\0";
Expand Down
2 changes: 1 addition & 1 deletion src/Excluder/MixedUsageExcluder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Excluder/TestsUsageExcluder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use function strpos;
use const JSON_ERROR_NONE;

class TestsUsageExcluder implements MemberUsageExcluder
final class TestsUsageExcluder implements MemberUsageExcluder
{

private ReflectionProvider $reflectionProvider;
Expand Down
2 changes: 1 addition & 1 deletion src/Formatter/RemoveDeadCodeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use function array_keys;
use function count;

class RemoveDeadCodeFormatter implements ErrorFormatter
final class RemoveDeadCodeFormatter implements ErrorFormatter
{

private FileSystem $fileSystem;
Expand Down
2 changes: 1 addition & 1 deletion src/Hierarchy/ClassHierarchy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use function array_keys;

class ClassHierarchy
final class ClassHierarchy
{

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Output/OutputEnhancer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use function sprintf;
use function str_replace;

class OutputEnhancer
final class OutputEnhancer
{

private RelativePathHelper $relativePathHelper;
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/ApiPhpDocUsageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/BuiltinUsageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use ReflectionMethod;
use Reflector;

class BuiltinUsageProvider extends ReflectionBasedMemberUsageProvider
final class BuiltinUsageProvider extends ReflectionBasedMemberUsageProvider
{

private bool $enabled;
Expand Down
14 changes: 7 additions & 7 deletions src/Provider/DoctrineUsageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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')
Expand All @@ -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'
Expand All @@ -203,15 +203,15 @@ protected function isProbablyDoctrineListener(string $methodName): bool
|| $methodName === 'onClear';
}

protected function hasAttribute(
private function hasAttribute(
ReflectionMethod $method,
string $attributeClass
): bool
{
return $method->getAttributes($attributeClass) !== [];
}

protected function isPartOfAsEntityListener(
private function isPartOfAsEntityListener(
ReflectionClass $class,
string $methodName
): bool
Expand All @@ -227,7 +227,7 @@ protected function isPartOfAsEntityListener(
return false;
}

protected function isEntityRepositoryConstructor(
private function isEntityRepositoryConstructor(
ReflectionClass $class,
ReflectionMethod $method
): bool
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/EnumUsageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use function is_int;
use function is_string;

class EnumUsageProvider implements MemberUsageProvider
final class EnumUsageProvider implements MemberUsageProvider
{

private bool $enabled;
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/NetteUsageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use function ucfirst;
use const PREG_SET_ORDER;

class NetteUsageProvider extends ReflectionBasedMemberUsageProvider
final class NetteUsageProvider extends ReflectionBasedMemberUsageProvider
{

private ReflectionProvider $reflectionProvider;
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/PhpStanUsageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use PHPStan\DependencyInjection\Container;
use ReflectionMethod;

class PhpStanUsageProvider extends ReflectionBasedMemberUsageProvider
final class PhpStanUsageProvider extends ReflectionBasedMemberUsageProvider
{

private bool $enabled;
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/PhpUnitUsageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use function is_string;
use function strpos;

class PhpUnitUsageProvider implements MemberUsageProvider
final class PhpUnitUsageProvider implements MemberUsageProvider
{

private bool $enabled;
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/ReflectionUsageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use function count;
use function in_array;

class ReflectionUsageProvider implements MemberUsageProvider
final class ReflectionUsageProvider implements MemberUsageProvider
{

private bool $enabled;
Expand Down
24 changes: 12 additions & 12 deletions src/Provider/SymfonyUsageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
use function sprintf;
use function strpos;

class SymfonyUsageProvider implements MemberUsageProvider
final class SymfonyUsageProvider implements MemberUsageProvider
{

private bool $enabled;
Expand Down Expand Up @@ -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)';
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -480,45 +480,45 @@ 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();

return $this->hasAttribute($class, 'Symfony\Component\EventDispatcher\Attribute\AsEventListener')
|| $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

return $this->hasAttribute($method, 'Symfony\Component\Routing\Attribute\Route', $isInstanceOf)
|| $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');

Expand All @@ -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();

Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/Provider/TwigUsageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use function explode;
use function in_array;

class TwigUsageProvider implements MemberUsageProvider
final class TwigUsageProvider implements MemberUsageProvider
{

private bool $enabled;
Expand Down Expand Up @@ -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';
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/VendorUsageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use function strpos;
use function substr;

class VendorUsageProvider extends ReflectionBasedMemberUsageProvider
final class VendorUsageProvider extends ReflectionBasedMemberUsageProvider
{

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/DeadCodeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
/**
* @implements Rule<CollectedDataNode>
*/
class DeadCodeRule implements Rule, DiagnoseExtension
final class DeadCodeRule implements Rule, DiagnoseExtension
{

public const IDENTIFIER_METHOD = 'shipmonk.deadMethod';
Expand Down
Loading