mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-28 23:10:51 +00:00
Remove buggy rules that depend on false condition of all class and calls analysis, to improve static reflection (#5958)
Co-authored-by: kaizen-ci <info@kaizen-ci.org>
This commit is contained in:
parent
c13d234e7d
commit
27e9ad030a
|
@ -32,9 +32,9 @@ It supports all versions of PHP from 5.3 and major open-source projects:
|
|||
<p align="center">
|
||||
<img src="/docs/images/php.png">
|
||||
<img src="/docs/images/space.png" width=30>
|
||||
<img src="/docs/images/phpunit.png">
|
||||
<a href="https://github.com/rectorphp/rector-phpunit"><img src="/docs/images/phpunit.png"></a>
|
||||
<img src="/docs/images/space.png" width=30>
|
||||
<img src="/docs/images/symfony.png">
|
||||
<a href="https://github.com/rectorphp/rector-symfony"><img src="/docs/images/symfony.png"></a>
|
||||
<img src="/docs/images/space.png" width=30>
|
||||
<a href="https://github.com/palantirnet/drupal-rector">
|
||||
<img src="/docs/images/drupal.png" alt="Drupal Rector rules">
|
||||
|
@ -42,7 +42,7 @@ It supports all versions of PHP from 5.3 and major open-source projects:
|
|||
<br>
|
||||
<img src="/docs/images/space.png" height=15>
|
||||
<br>
|
||||
<img src="/docs/images/cakephp.png">
|
||||
<a href="https://github.com/rectorphp/rector-cakephp"><img src="/docs/images/cakephp.png"></a>
|
||||
<img src="/docs/images/space.png" width=30>
|
||||
<a href="https://github.com/sabbelasichon/typo3-rector">
|
||||
<img src="/docs/images/typo3.png">
|
||||
|
@ -64,7 +64,7 @@ It supports all versions of PHP from 5.3 and major open-source projects:
|
|||
|
||||
## Documentation
|
||||
|
||||
- [Explore 660+ Rector Rules](/docs/rector_rules_overview.md)
|
||||
- [Explore 450+ Rector Rules](/docs/rector_rules_overview.md)
|
||||
- [How Does Rector Work?](/docs/how_it_works.md)
|
||||
- [PHP Parser Nodes](https://github.com/rectorphp/php-parser-nodes-docs/)
|
||||
|
||||
|
|
|
@ -10,10 +10,8 @@ use Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector;
|
|||
use Rector\DeadCode\Rector\BinaryOp\RemoveDuplicatedInstanceOfRector;
|
||||
use Rector\DeadCode\Rector\BooleanAnd\RemoveAndTrueRector;
|
||||
use Rector\DeadCode\Rector\Cast\RecastingRemovalRector;
|
||||
use Rector\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector;
|
||||
use Rector\DeadCode\Rector\ClassConst\RemoveUnusedPrivateConstantRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveDeadConstructorRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveDeadRecursiveClassMethodRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveDelegatingParentCallRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector;
|
||||
|
@ -26,7 +24,6 @@ use Rector\DeadCode\Rector\Expression\SimplifyMirrorAssignRector;
|
|||
use Rector\DeadCode\Rector\For_\RemoveDeadIfForeachForRector;
|
||||
use Rector\DeadCode\Rector\For_\RemoveDeadLoopRector;
|
||||
use Rector\DeadCode\Rector\Foreach_\RemoveUnusedForeachKeyRector;
|
||||
use Rector\DeadCode\Rector\Function_\RemoveUnusedFunctionRector;
|
||||
use Rector\DeadCode\Rector\FunctionLike\RemoveCodeAfterReturnRector;
|
||||
use Rector\DeadCode\Rector\FunctionLike\RemoveDeadReturnRector;
|
||||
use Rector\DeadCode\Rector\FunctionLike\RemoveDuplicatedIfReturnRector;
|
||||
|
@ -61,10 +58,10 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
$services->set(RemoveUnusedForeachKeyRector::class);
|
||||
$services->set(RemoveParentCallWithoutParentRector::class);
|
||||
$services->set(RemoveEmptyClassMethodRector::class);
|
||||
$services->set(RemoveUnusedPrivatePropertyRector::class);
|
||||
$services->set(RemoveDoubleAssignRector::class);
|
||||
$services->set(SimplifyMirrorAssignRector::class);
|
||||
$services->set(RemoveOverriddenValuesRector::class);
|
||||
$services->set(RemoveUnusedPrivatePropertyRector::class);
|
||||
$services->set(RemoveUnusedPrivateConstantRector::class);
|
||||
$services->set(RemoveUnusedPrivateMethodRector::class);
|
||||
$services->set(RemoveCodeAfterReturnRector::class);
|
||||
|
@ -85,13 +82,10 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
$services->set(TernaryToBooleanOrFalseToBooleanAndRector::class);
|
||||
$services->set(RemoveEmptyTestMethodRector::class);
|
||||
$services->set(RemoveDeadTryCatchRector::class);
|
||||
$services->set(RemoveUnusedClassConstantRector::class);
|
||||
$services->set(RemoveUnusedVariableAssignRector::class);
|
||||
$services->set(RemoveDuplicatedIfReturnRector::class);
|
||||
$services->set(RemoveUnusedFunctionRector::class);
|
||||
$services->set(RemoveUnusedNonEmptyArrayBeforeForeachRector::class);
|
||||
$services->set(RemoveAssignOfVoidReturnFunctionRector::class);
|
||||
$services->set(RemoveDeadRecursiveClassMethodRector::class);
|
||||
$services->set(RemoveEmptyMethodCallRector::class);
|
||||
$services->set(RemoveDeadConditionAboveReturnRector::class);
|
||||
$services->set(RemoveUnusedConstructorParamRector::class);
|
||||
|
|
|
@ -7,11 +7,8 @@ use Rector\Privatization\Rector\Class_\ChangeReadOnlyVariableWithDefaultValueToC
|
|||
use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector;
|
||||
use Rector\Privatization\Rector\Class_\MakeUnusedClassesWithChildrenAbstractRector;
|
||||
use Rector\Privatization\Rector\Class_\RepeatedLiteralToClassConstantRector;
|
||||
use Rector\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector;
|
||||
use Rector\Privatization\Rector\ClassMethod\ChangeGlobalVariablesToPropertiesRector;
|
||||
use Rector\Privatization\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector;
|
||||
use Rector\Privatization\Rector\ClassMethod\PrivatizeFinalClassMethodRector;
|
||||
use Rector\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector;
|
||||
use Rector\Privatization\Rector\MethodCall\PrivatizeLocalGetterToPropertyRector;
|
||||
use Rector\Privatization\Rector\Property\ChangeReadOnlyPropertyWithDefaultValueToConstantRector;
|
||||
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
|
||||
|
@ -27,14 +24,11 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
$services->set(ChangeReadOnlyPropertyWithDefaultValueToConstantRector::class);
|
||||
$services->set(ChangeReadOnlyVariableWithDefaultValueToConstantRector::class);
|
||||
$services->set(RepeatedLiteralToClassConstantRector::class);
|
||||
|
||||
// $services->set(ChangeLocalPropertyToVariableRector::class);
|
||||
|
||||
$services->set(PrivatizeLocalOnlyMethodRector::class);
|
||||
$services->set(PrivatizeLocalGetterToPropertyRector::class);
|
||||
$services->set(PrivatizeLocalPropertyToPrivatePropertyRector::class);
|
||||
$services->set(PrivatizeLocalClassConstantRector::class);
|
||||
$services->set(PrivatizeFinalClassPropertyRector::class);
|
||||
$services->set(PrivatizeFinalClassMethodRector::class);
|
||||
$services->set(MakeOnlyUsedByChildrenProtectedRector::class);
|
||||
|
||||
// buggy, requires more work
|
||||
// $services->set(ChangeLocalPropertyToVariableRector::class);
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||
namespace Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
|
||||
use PhpParser\Comment\Doc;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Nop;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
|
@ -28,11 +27,6 @@ final class PhpDocInfoTest extends AbstractKernelTestCase
|
|||
*/
|
||||
private $phpDocInfoPrinter;
|
||||
|
||||
/**
|
||||
* @var Node
|
||||
*/
|
||||
private $node;
|
||||
|
||||
/**
|
||||
* @var SmartFileSystem
|
||||
*/
|
||||
|
@ -86,9 +80,9 @@ final class PhpDocInfoTest extends AbstractKernelTestCase
|
|||
$phpDocInfoFactory = $this->getService(PhpDocInfoFactory::class);
|
||||
$phpDocContent = $this->smartFileSystem->readFile($path);
|
||||
|
||||
$this->node = new Nop();
|
||||
$this->node->setDocComment(new Doc($phpDocContent));
|
||||
$nop = new Nop();
|
||||
$nop->setDocComment(new Doc($phpDocContent));
|
||||
|
||||
return $phpDocInfoFactory->createFromNode($this->node);
|
||||
return $phpDocInfoFactory->createFromNode($nop);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Caching\Contract\Rector;
|
||||
|
||||
/**
|
||||
* Rectors implementing this interface require to run with --clear-cache, so full application is analysed.
|
||||
* Such rules can be remove unused public method, remove unused class etc. They need full app to decide correctly.
|
||||
*/
|
||||
interface ZeroCacheRectorInterface
|
||||
{
|
||||
}
|
|
@ -30,7 +30,6 @@ use PhpParser\Node\Stmt\Function_;
|
|||
use PhpParser\Node\Stmt\Interface_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\Stmt\Trait_;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Reflection\MethodReflection;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Type\MixedType;
|
||||
|
@ -66,11 +65,6 @@ final class NodeRepository
|
|||
*/
|
||||
private $functionsByName = [];
|
||||
|
||||
/**
|
||||
* @var array<string, FuncCall[]>
|
||||
*/
|
||||
private $funcCallsByName = [];
|
||||
|
||||
/**
|
||||
* @var array<class-string, array<array<MethodCall|StaticCall>>>
|
||||
*/
|
||||
|
@ -103,11 +97,6 @@ final class NodeRepository
|
|||
*/
|
||||
private $parsedPropertyFetchNodeCollector;
|
||||
|
||||
/**
|
||||
* @var ParsedClassConstFetchNodeCollector
|
||||
*/
|
||||
private $parsedClassConstFetchNodeCollector;
|
||||
|
||||
/**
|
||||
* @var ParsedNodeCollector
|
||||
*/
|
||||
|
@ -137,7 +126,6 @@ final class NodeRepository
|
|||
ArrayCallableMethodReferenceAnalyzer $arrayCallableMethodReferenceAnalyzer,
|
||||
ParsedPropertyFetchNodeCollector $parsedPropertyFetchNodeCollector,
|
||||
NodeNameResolver $nodeNameResolver,
|
||||
ParsedClassConstFetchNodeCollector $parsedClassConstFetchNodeCollector,
|
||||
ParsedNodeCollector $parsedNodeCollector,
|
||||
TypeUnwrapper $typeUnwrapper,
|
||||
ReflectionProvider $reflectionProvider,
|
||||
|
@ -146,7 +134,6 @@ final class NodeRepository
|
|||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->arrayCallableMethodReferenceAnalyzer = $arrayCallableMethodReferenceAnalyzer;
|
||||
$this->parsedPropertyFetchNodeCollector = $parsedPropertyFetchNodeCollector;
|
||||
$this->parsedClassConstFetchNodeCollector = $parsedClassConstFetchNodeCollector;
|
||||
$this->parsedNodeCollector = $parsedNodeCollector;
|
||||
$this->typeUnwrapper = $typeUnwrapper;
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
|
@ -175,11 +162,6 @@ final class NodeRepository
|
|||
$this->functionsByName[$functionName] = $node;
|
||||
}
|
||||
|
||||
if ($node instanceof FuncCall) {
|
||||
$functionName = $this->nodeNameResolver->getName($node);
|
||||
$this->funcCallsByName[$functionName][] = $node;
|
||||
}
|
||||
|
||||
if ($node instanceof Attribute) {
|
||||
$attributeClass = $this->nodeNameResolver->getName($node->name);
|
||||
$this->attributes[$attributeClass][] = $node;
|
||||
|
@ -297,11 +279,6 @@ final class NodeRepository
|
|||
return null;
|
||||
}
|
||||
|
||||
public function isFunctionUsed(string $functionName): bool
|
||||
{
|
||||
return isset($this->funcCallsByName[$functionName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MethodCall[]
|
||||
*/
|
||||
|
@ -375,52 +352,6 @@ final class NodeRepository
|
|||
return $this->findCallsByClassAndMethod($class, $method);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ClassReflection[]
|
||||
*/
|
||||
public function findDirectClassConstantFetches(ClassReflection $classReflection, string $desiredConstantName): array
|
||||
{
|
||||
$classConstantFetchByClassAndName = $this->parsedClassConstFetchNodeCollector->getClassConstantFetchByClassAndName();
|
||||
$classTypes = $classConstantFetchByClassAndName[$classReflection->getName()][$desiredConstantName] ?? [];
|
||||
|
||||
return $this->resolveClassReflectionsFromClassTypes($classTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ClassReflection[]
|
||||
*/
|
||||
public function findIndirectClassConstantFetches(
|
||||
ClassReflection $classReflection,
|
||||
string $desiredConstantName
|
||||
): array {
|
||||
$classConstantFetchByClassAndName = $this->parsedClassConstFetchNodeCollector->getClassConstantFetchByClassAndName();
|
||||
|
||||
foreach ($classConstantFetchByClassAndName as $className => $classesByConstantName) {
|
||||
if (! $this->reflectionProvider->hasClass($className)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$currentClassReflection = $this->reflectionProvider->getClass($className);
|
||||
if (! isset($classesByConstantName[$desiredConstantName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $classReflection->isSubclassOf($currentClassReflection->getName()) &&
|
||||
! $currentClassReflection->isSubclassOf($classReflection->getName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// include child usages and parent usages
|
||||
if ($currentClassReflection->getName() === $classReflection->getName()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $this->resolveClassReflectionsFromClassTypes($classesByConstantName[$desiredConstantName]);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public function hasClassChildren(Class_ $desiredClass): bool
|
||||
{
|
||||
$desiredClassName = $desiredClass->getAttribute(AttributeKey::CLASS_NAME);
|
||||
|
@ -856,24 +787,6 @@ final class NodeRepository
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string[] $classTypes
|
||||
* @return ClassReflection[]
|
||||
*/
|
||||
private function resolveClassReflectionsFromClassTypes(array $classTypes): array
|
||||
{
|
||||
$classReflections = [];
|
||||
foreach ($classTypes as $classType) {
|
||||
if (! $this->reflectionProvider->hasClass($classType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$classReflections[] = $this->reflectionProvider->getClass($classType);
|
||||
}
|
||||
|
||||
return $classReflections;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MethodCall|StaticCall $node
|
||||
*/
|
||||
|
|
|
@ -1,160 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\NodeCollector\NodeCollector;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\TypeUtils;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
|
||||
final class ParsedClassConstFetchNodeCollector
|
||||
{
|
||||
/**
|
||||
* @var array<string, array<string, class-string[]>>
|
||||
*/
|
||||
private $classConstantFetchByClassAndName = [];
|
||||
|
||||
/**
|
||||
* @var NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
|
||||
/**
|
||||
* @var NodeTypeResolver
|
||||
*/
|
||||
private $nodeTypeResolver;
|
||||
|
||||
/**
|
||||
* @var ReflectionProvider
|
||||
*/
|
||||
private $reflectionProvider;
|
||||
|
||||
public function __construct(
|
||||
NodeNameResolver $nodeNameResolver, ReflectionProvider $reflectionProvider,
|
||||
NodeTypeResolver $nodeTypeResolver
|
||||
) {
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
$this->nodeTypeResolver = $nodeTypeResolver;
|
||||
}
|
||||
|
||||
public function collect(Node $node): void
|
||||
{
|
||||
if (! $node instanceof ClassConstFetch) {
|
||||
return;
|
||||
}
|
||||
|
||||
$constantName = $this->nodeNameResolver->getName($node->name);
|
||||
if ($constantName === 'class') {
|
||||
// this is not a manual constant
|
||||
return;
|
||||
}
|
||||
if ($constantName === null) {
|
||||
// this is not a manual constant
|
||||
return;
|
||||
}
|
||||
|
||||
$resolvedClassType = $this->nodeTypeResolver->resolve($node->class);
|
||||
|
||||
$className = $this->resolveClassTypeThatContainsConstantOrFirstUnioned($resolvedClassType, $constantName);
|
||||
if ($className === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// current class
|
||||
$classOfUse = $node->getAttribute(AttributeKey::CLASS_NAME);
|
||||
if ($classOfUse === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->classConstantFetchByClassAndName[$className][$constantName][] = $classOfUse;
|
||||
|
||||
$this->classConstantFetchByClassAndName[$className][$constantName] = array_unique(
|
||||
$this->classConstantFetchByClassAndName[$className][$constantName]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<string, class-string[]>>
|
||||
*/
|
||||
public function getClassConstantFetchByClassAndName(): array
|
||||
{
|
||||
return $this->classConstantFetchByClassAndName;
|
||||
}
|
||||
|
||||
private function resolveClassTypeThatContainsConstantOrFirstUnioned(
|
||||
Type $resolvedClassType,
|
||||
string $constantName
|
||||
): ?string {
|
||||
$className = $this->matchClassTypeThatContainsConstant($resolvedClassType, $constantName);
|
||||
if ($className !== null) {
|
||||
return $className;
|
||||
}
|
||||
|
||||
// we need at least one original user class
|
||||
if (! $resolvedClassType instanceof UnionType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($resolvedClassType->getTypes() as $unionedType) {
|
||||
if (! $unionedType instanceof ObjectType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $unionedType->getClassName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function matchClassTypeThatContainsConstant(Type $type, string $constant): ?string
|
||||
{
|
||||
if ($type instanceof ObjectType) {
|
||||
return $type->getClassName();
|
||||
}
|
||||
|
||||
$classNames = TypeUtils::getDirectClassNames($type);
|
||||
|
||||
foreach ($classNames as $className) {
|
||||
$currentClassConstants = $this->getConstantsDefinedInClass($className);
|
||||
if (! in_array($constant, $currentClassConstants, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $className;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function getConstantsDefinedInClass(string $className): array
|
||||
{
|
||||
if (! $this->reflectionProvider->hasClass($className)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$classReflection = $this->reflectionProvider->getClass($className);
|
||||
$reflectionClass = $classReflection->getNativeReflection();
|
||||
|
||||
$constants = $reflectionClass->getConstants();
|
||||
|
||||
$currentClassConstants = array_keys($constants);
|
||||
if ($classReflection->getParentClass() !== false) {
|
||||
return $currentClassConstants;
|
||||
}
|
||||
|
||||
$parentClassConstants = array_keys($constants);
|
||||
return array_diff($currentClassConstants, $parentClassConstants);
|
||||
}
|
||||
}
|
|
@ -7,7 +7,6 @@ namespace Rector\NodeCollector\NodeVisitor;
|
|||
use PhpParser\Node;
|
||||
use PhpParser\NodeVisitorAbstract;
|
||||
use Rector\NodeCollector\NodeCollector\NodeRepository;
|
||||
use Rector\NodeCollector\NodeCollector\ParsedClassConstFetchNodeCollector;
|
||||
use Rector\NodeCollector\NodeCollector\ParsedNodeCollector;
|
||||
use Rector\NodeCollector\NodeCollector\ParsedPropertyFetchNodeCollector;
|
||||
|
||||
|
@ -28,13 +27,7 @@ final class NodeCollectorNodeVisitor extends NodeVisitorAbstract
|
|||
*/
|
||||
private $parsedPropertyFetchNodeCollector;
|
||||
|
||||
/**
|
||||
* @var ParsedClassConstFetchNodeCollector
|
||||
*/
|
||||
private $parsedClassConstFetchNodeCollector;
|
||||
|
||||
public function __construct(
|
||||
ParsedClassConstFetchNodeCollector $parsedClassConstFetchNodeCollector,
|
||||
NodeRepository $nodeRepository,
|
||||
ParsedNodeCollector $parsedNodeCollector,
|
||||
ParsedPropertyFetchNodeCollector $parsedPropertyFetchNodeCollector
|
||||
|
@ -42,7 +35,6 @@ final class NodeCollectorNodeVisitor extends NodeVisitorAbstract
|
|||
$this->nodeRepository = $nodeRepository;
|
||||
$this->parsedNodeCollector = $parsedNodeCollector;
|
||||
$this->parsedPropertyFetchNodeCollector = $parsedPropertyFetchNodeCollector;
|
||||
$this->parsedClassConstFetchNodeCollector = $parsedClassConstFetchNodeCollector;
|
||||
}
|
||||
|
||||
public function enterNode(Node $node)
|
||||
|
@ -53,7 +45,6 @@ final class NodeCollectorNodeVisitor extends NodeVisitorAbstract
|
|||
|
||||
$this->nodeRepository->collect($node);
|
||||
$this->parsedPropertyFetchNodeCollector->collect($node);
|
||||
$this->parsedClassConstFetchNodeCollector->collect($node);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,91 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\VendorLocker\NodeVendorLocker;
|
||||
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Privatization\VisibilityGuard\ClassMethodVisibilityGuard;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Merge with @see ClassMethodVisibilityGuard
|
||||
*/
|
||||
final class ClassMethodVisibilityVendorLockResolver
|
||||
{
|
||||
/**
|
||||
* @var NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
|
||||
/**
|
||||
* @var FamilyRelationsAnalyzer
|
||||
*/
|
||||
private $familyRelationsAnalyzer;
|
||||
|
||||
public function __construct(NodeNameResolver $nodeNameResolver, FamilyRelationsAnalyzer $familyRelationsAnalyzer)
|
||||
{
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->familyRelationsAnalyzer = $familyRelationsAnalyzer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for:
|
||||
* - interface required methods
|
||||
* - abstract classes required method
|
||||
* - child classes required method
|
||||
*
|
||||
* Prevents:
|
||||
* - changing visibility conflicting with children
|
||||
*/
|
||||
public function isParentLockedMethod(ClassMethod $classMethod): bool
|
||||
{
|
||||
/** @var Scope $scope */
|
||||
$scope = $classMethod->getAttribute(AttributeKey::SCOPE);
|
||||
|
||||
$classReflection = $scope->getClassReflection();
|
||||
if (! $classReflection instanceof ClassReflection) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$methodName = $this->nodeNameResolver->getName($classMethod);
|
||||
|
||||
/** @var ClassReflection[] $parentClassReflections */
|
||||
$parentClassReflections = array_merge($classReflection->getParents(), $classReflection->getInterfaces());
|
||||
|
||||
foreach ($parentClassReflections as $parentClassReflection) {
|
||||
if ($parentClassReflection->hasMethod($methodName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isChildLockedMethod(ClassMethod $classMethod): bool
|
||||
{
|
||||
/** @var Scope $scope */
|
||||
$scope = $classMethod->getAttribute(AttributeKey::SCOPE);
|
||||
|
||||
$classReflection = $scope->getClassReflection();
|
||||
if (! $classReflection instanceof ClassReflection) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$methodName = $this->nodeNameResolver->getName($classMethod);
|
||||
|
||||
$childrenClassReflections = $this->familyRelationsAnalyzer->getChildrenOfClassReflection($classReflection);
|
||||
foreach ($childrenClassReflections as $childClassReflection) {
|
||||
if ($childClassReflection->hasMethod($methodName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector\Fixture;
|
||||
|
||||
class ExternalPublic
|
||||
{
|
||||
public const SOME_CONST = 'dead';
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector\Fixture;
|
||||
|
||||
class ExternalPublic
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
||||
private const SOME_CONST = 'dead';
|
||||
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector\Fixture;
|
||||
|
||||
class SkipApi
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
public const USED_PUBLICLY_IN_ANOTHER_PROJECT = 'publicly';
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector\Fixture;
|
||||
|
||||
use Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector\Source\AbstractEnum;
|
||||
|
||||
class SkipEnum extends AbstractEnum
|
||||
{
|
||||
public const ENUM_MAGIC = 'yes';
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector\Fixture;
|
||||
|
||||
class SkipExternalUsed
|
||||
{
|
||||
public const SOME_CONST = 'dead';
|
||||
}
|
||||
|
||||
class SomeUsed
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return SkipExternalUsed::SOME_CONST;
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector\Fixture;
|
||||
|
||||
class SkipMultipleConstants
|
||||
{
|
||||
public const SOME_CONST = 'dead', NOT_USED_EITHER = 'dead';
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector\Fixture;
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
class SkipOnClassApi
|
||||
{
|
||||
public const USED_PUBLICLY_IN_ANOTHER_PROJECT = 'publicly';
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector\Fixture;
|
||||
|
||||
class SkipPublic
|
||||
{
|
||||
public const SOME_CONST = 'dead';
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class OpenSourceRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<SmartFileInfo>
|
||||
*/
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureOpenSource');
|
||||
}
|
||||
|
||||
public function provideConfigFilePath(): string
|
||||
{
|
||||
return __DIR__ . '/config/project_open_source.php';
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class RemoveUnusedClassConstantRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<SmartFileInfo>
|
||||
*/
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
public function provideConfigFilePath(): string
|
||||
{
|
||||
return __DIR__ . '/config/configured_rule.php';
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector\Source;
|
||||
|
||||
abstract class AbstractEnum
|
||||
{
|
||||
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(RemoveUnusedClassConstantRector::class);
|
||||
};
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Rector\Core\ValueObject\ProjectType;
|
||||
use Rector\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$parameters = $containerConfigurator->parameters();
|
||||
$parameters->set(Option::PROJECT_TYPE, ProjectType::OPEN_SOURCE);
|
||||
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(RemoveUnusedClassConstantRector::class);
|
||||
};
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedPrivateClassConstantRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
||||
private const SOME_CONST = 'dead';
|
||||
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedPrivateClassConstantRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedPrivateClassConstantRector\Fixture;
|
||||
|
||||
class SkipApi
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
private const USED_PUBLICLY_IN_ANOTHER_PROJECT = 'publicly';
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedPrivateClassConstantRector\Fixture;
|
||||
|
||||
use Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedPrivateClassConstantRector\Source\AbstractEnum;
|
||||
|
||||
class SkipEnum extends AbstractEnum
|
||||
{
|
||||
private const ENUM_MAGIC = 'yes';
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedPrivateClassConstantRector\Fixture;
|
||||
|
||||
class SkipMultipleConstants
|
||||
{
|
||||
private const SOME_CONST = 'dead', NOT_USED_EITHER = 'dead';
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedPrivateClassConstantRector\Fixture;
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
class SkipOnClassApi
|
||||
{
|
||||
private const USED_PUBLICLY_IN_ANOTHER_PROJECT = 'publicly';
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedPrivateClassConstantRector\Fixture;
|
||||
|
||||
final class SkipUsedConstant
|
||||
{
|
||||
private const SOME_CONST = 'dead';
|
||||
|
||||
public function run()
|
||||
{
|
||||
return self::SOME_CONST;
|
||||
}
|
||||
}
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\Function_\RemoveUnusedFunctionRector;
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedPrivateClassConstantRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class RemoveUnusedFunctionRectorTest extends AbstractRectorTestCase
|
||||
final class RemoveUnusedPrivateClassConstantRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassConst\RemoveUnusedPrivateClassConstantRector\Source;
|
||||
|
||||
abstract class AbstractEnum
|
||||
{
|
||||
|
||||
}
|
|
@ -2,11 +2,10 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector;
|
||||
use Rector\DeadCode\Rector\ClassConst\RemoveUnusedPrivateClassConstantRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(PrivatizeLocalClassConstantRector::class);
|
||||
$services->set(RemoveUnusedPrivateClassConstantRector::class);
|
||||
};
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveDeadRecursiveClassMethodRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return $this->run();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveDeadRecursiveClassMethodRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveDeadRecursiveClassMethodRector\Fixture;
|
||||
|
||||
class PrivateToo
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return $this->run();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveDeadRecursiveClassMethodRector\Fixture;
|
||||
|
||||
class PrivateToo
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveDeadRecursiveClassMethodRector\Fixture;
|
||||
|
||||
interface SkipInterface
|
||||
{
|
||||
public function process();
|
||||
}
|
||||
|
||||
class ImplementerOfTheInterface implements SkipInterface
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
$this->process();
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveDeadRecursiveClassMethodRector\Fixture;
|
||||
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
class FileRemover
|
||||
{
|
||||
/**
|
||||
* @var SmartFileInfo[]
|
||||
*/
|
||||
private $removedFiles;
|
||||
|
||||
public function removeFile(SmartFileInfo $smartFileInfo): void
|
||||
{
|
||||
$this->removedFiles[$smartFileInfo->getRealPath()] = $smartFileInfo;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AbstractClassUsingFileRemover
|
||||
{
|
||||
/**
|
||||
* @var FileRemover
|
||||
*/
|
||||
private $removeFile;
|
||||
|
||||
protected function removeFile(SmartFileInfo $smartFileInfo): void
|
||||
{
|
||||
$this->removeFile->removeFile($smartFileInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class ClassExtendingClass extends AbstractClassUsingFileRemover
|
||||
{
|
||||
public function run($smartFileInfo)
|
||||
{
|
||||
$this->removeFile($smartFileInfo);
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveDeadRecursiveClassMethodRector\Fixture;
|
||||
|
||||
class SkipUsed
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return $this->run();
|
||||
}
|
||||
|
||||
public function skipUsed()
|
||||
{
|
||||
$this->run();
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveDeadRecursiveClassMethodRector\Fixture;
|
||||
|
||||
class SomeStaticCall
|
||||
{
|
||||
public static function run()
|
||||
{
|
||||
return self::run();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveDeadRecursiveClassMethodRector\Fixture;
|
||||
|
||||
class SomeStaticCall
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveDeadRecursiveClassMethodRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class RemoveDeadRecursiveClassMethodRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<SmartFileInfo>
|
||||
*/
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
public function provideConfigFilePath(): string
|
||||
{
|
||||
return __DIR__ . '/config/configured_rule.php';
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveDeadRecursiveClassMethodRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(RemoveDeadRecursiveClassMethodRector::class);
|
||||
};
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodRector\Fixture;
|
||||
|
||||
class Dependency
|
||||
{
|
||||
public function unusedpublicMethod()
|
||||
{
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
final class DependencyInjection
|
||||
{
|
||||
public function __construct(Dependency $dependency)
|
||||
{
|
||||
$dependency->run();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodRector\Fixture;
|
||||
|
||||
class Dependency
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
final class DependencyInjection
|
||||
{
|
||||
public function __construct(Dependency $dependency)
|
||||
{
|
||||
$dependency->run();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,49 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodRector\Fixture;
|
||||
|
||||
final class Fixture
|
||||
{
|
||||
public function unusedpublicMethod()
|
||||
{
|
||||
}
|
||||
|
||||
private function keep()
|
||||
{
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$obj = new self;
|
||||
$obj->execute();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodRector\Fixture;
|
||||
|
||||
final class Fixture
|
||||
{
|
||||
private function keep()
|
||||
{
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$obj = new self;
|
||||
$obj->execute();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodRector\Fixture;
|
||||
|
||||
final class SkipConstructor
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
new SkipConstructor();
|
||||
?>
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodRector\Fixture;
|
||||
|
||||
final class SkipInvoke
|
||||
{
|
||||
public function __invoke()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
(new SkipInvoke())();
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodRector\Fixture;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\NodeVisitorAbstract;
|
||||
use Rector\Core\Contract\Rector\PhpRectorInterface;
|
||||
|
||||
final class SkipRequiredByContract extends NodeVisitorAbstract implements PhpRectorInterface
|
||||
{
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
}
|
||||
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class SkipTestDataProvider extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(): void
|
||||
{
|
||||
$this->assertTrue('yes');
|
||||
}
|
||||
|
||||
public function provideData()
|
||||
{
|
||||
return [1, 2, 3];
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class SkipTests extends TestCase
|
||||
{
|
||||
public function test(): void
|
||||
{
|
||||
$this->assertTrue('yes');
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodRector\Fixture;
|
||||
|
||||
final class UsedOutsideClass
|
||||
{
|
||||
public function unusedpublicMethod()
|
||||
{
|
||||
}
|
||||
|
||||
private function keep()
|
||||
{
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
(function() {
|
||||
$obj = new UsedOutsideClass();
|
||||
$obj->execute();
|
||||
});
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodRector\Fixture;
|
||||
|
||||
final class UsedOutsideClass
|
||||
{
|
||||
private function keep()
|
||||
{
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
(function() {
|
||||
$obj = new UsedOutsideClass();
|
||||
$obj->execute();
|
||||
});
|
||||
|
||||
?>
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class RemoveUnusedPublicMethodRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<SmartFileInfo>
|
||||
*/
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
public function provideConfigFilePath(): string
|
||||
{
|
||||
return __DIR__ . '/config/configured_rule.php';
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(RemoveUnusedPublicMethodRector::class);
|
||||
};
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\Function_\RemoveUnusedFunctionRector\Fixture;
|
||||
|
||||
function removeMe()
|
||||
{
|
||||
}
|
||||
|
||||
function useMe()
|
||||
{
|
||||
}
|
||||
|
||||
useMe();
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\Function_\RemoveUnusedFunctionRector\Fixture;
|
||||
|
||||
function useMe()
|
||||
{
|
||||
}
|
||||
|
||||
useMe();
|
||||
|
||||
?>
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\DeadCode\Rector\Function_\RemoveUnusedFunctionRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(RemoveUnusedFunctionRector::class);
|
||||
};
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class ClassWithConstantUsedSomewhereElse
|
||||
{
|
||||
const NON_LOCAL_ONLY = true;
|
||||
}
|
||||
|
||||
class ForeignConstantAddictUser
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return ClassWithConstantUsedSomewhereElse::NON_LOCAL_ONLY;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class ClassWithConstantUsedSomewhereElse
|
||||
{
|
||||
public const NON_LOCAL_ONLY = true;
|
||||
}
|
||||
|
||||
class ForeignConstantAddictUser
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return ClassWithConstantUsedSomewhereElse::NON_LOCAL_ONLY;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
||||
const LOCAL_ONLY = true;
|
||||
|
||||
public function isLocalOnly()
|
||||
{
|
||||
return self::LOCAL_ONLY;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
||||
private const LOCAL_ONLY = true;
|
||||
|
||||
public function isLocalOnly()
|
||||
{
|
||||
return self::LOCAL_ONLY;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
interface InterfaceWithConstant
|
||||
{
|
||||
const LOCAL_ONLY = true;
|
||||
}
|
||||
|
||||
class ClassExtendingInterface implements InterfaceWithConstant
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return self::LOCAL_ONLY;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
interface InterfaceWithConstant
|
||||
{
|
||||
public const LOCAL_ONLY = true;
|
||||
}
|
||||
|
||||
class ClassExtendingInterface implements InterfaceWithConstant
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return self::LOCAL_ONLY;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
interface YetAnotherInterfaceWithConstant
|
||||
{
|
||||
const LOCAL_ONLY = true;
|
||||
}
|
||||
|
||||
class YetAnotherClassExtendingInterface implements YetAnotherInterfaceWithConstant
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return self::LOCAL_ONLY;
|
||||
}
|
||||
}
|
||||
|
||||
class YetForeigner
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return YetAnotherClassExtendingInterface::LOCAL_ONLY;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
interface YetAnotherInterfaceWithConstant
|
||||
{
|
||||
public const LOCAL_ONLY = true;
|
||||
}
|
||||
|
||||
class YetAnotherClassExtendingInterface implements YetAnotherInterfaceWithConstant
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return self::LOCAL_ONLY;
|
||||
}
|
||||
}
|
||||
|
||||
class YetForeigner
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return YetAnotherClassExtendingInterface::LOCAL_ONLY;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
interface AnotherInterfaceWithConstant
|
||||
{
|
||||
const LOCAL_ONLY = true;
|
||||
}
|
||||
|
||||
class AnotherClassExtendingInterface implements AnotherInterfaceWithConstant
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return self::LOCAL_ONLY;
|
||||
}
|
||||
}
|
||||
|
||||
class Foreigner
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return AnotherInterfaceWithConstant::LOCAL_ONLY;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
interface AnotherInterfaceWithConstant
|
||||
{
|
||||
public const LOCAL_ONLY = true;
|
||||
}
|
||||
|
||||
class AnotherClassExtendingInterface implements AnotherInterfaceWithConstant
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return self::LOCAL_ONLY;
|
||||
}
|
||||
}
|
||||
|
||||
class Foreigner
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return AnotherInterfaceWithConstant::LOCAL_ONLY;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class MakeConstantProtected
|
||||
{
|
||||
const CHILD_ONLY = true;
|
||||
}
|
||||
|
||||
class ConstantUser extends MakeConstantProtected
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$is = self::CHILD_ONLY;
|
||||
$isAgain = parent::CHILD_ONLY;
|
||||
|
||||
return static::CHILD_ONLY;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class MakeConstantProtected
|
||||
{
|
||||
protected const CHILD_ONLY = true;
|
||||
}
|
||||
|
||||
class ConstantUser extends MakeConstantProtected
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$is = self::CHILD_ONLY;
|
||||
$isAgain = parent::CHILD_ONLY;
|
||||
|
||||
return static::CHILD_ONLY;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class SkipApi
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const SHORT_NAME = 'use_me_anywhere';
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
use Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source\AbstractInBetweenVariableParentClassUser;
|
||||
use Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source\AbstractVariableParentClassUser;
|
||||
|
||||
class SkipMultiInheritance extends AbstractInBetweenVariableParentClassUser
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const SHORT_NAME = '@Id';
|
||||
}
|
||||
|
||||
class TheVariableUse
|
||||
{
|
||||
public function run(AbstractVariableParentClassUser $value)
|
||||
{
|
||||
return $value::SHORT_NAME;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class SkipMultiOvercomplex
|
||||
{
|
||||
const LOCAL_ONLY = true, AND_ALSO = false;
|
||||
}
|
||||
|
||||
class ExternalMultiUser
|
||||
{
|
||||
public function useMe()
|
||||
{
|
||||
return SkipMulti::AND_ALSO;
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
use Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source\SomeProtectedParentClass;
|
||||
|
||||
class SkipParentClassProtected extends SomeProtectedParentClass
|
||||
{
|
||||
protected const SOME_CONST = 'changed_value';
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
use Rector\Tests\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector\Fixture\ParentClass;
|
||||
|
||||
class SkipUsedByParentClass extends ParentClassUser
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const SHORT_NAME = '@Assert\Type';
|
||||
}
|
||||
|
||||
class ParentClassUser
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class TheUse
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return ParentClassUser::SHORT_NAME;
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class SkipUsedInAnotherClass
|
||||
{
|
||||
private const SOME = ConstainsConstant::KEEP_PUBLIC . '_pcs';
|
||||
}
|
||||
|
||||
class ConstainsConstant
|
||||
{
|
||||
public const KEEP_PUBLIC = 'cms';
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class PrivatizeLocalClassConstantRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<SmartFileInfo>
|
||||
*/
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
public function provideConfigFilePath(): string
|
||||
{
|
||||
return __DIR__ . '/config/configured_rule.php';
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source;
|
||||
|
||||
abstract class AbstractInBetweenVariableParentClassUser extends AbstractVariableParentClassUser
|
||||
{
|
||||
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source;
|
||||
|
||||
abstract class AbstractVariableParentClassUser
|
||||
{
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source;
|
||||
|
||||
abstract class SomeProtectedParentClass
|
||||
{
|
||||
protected const SOME_CONST = '...';
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector\Fixture;
|
||||
|
||||
class AbstractSomeClassTop
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class AbstractSomeClassSecond extends AbstractSomeClassTop
|
||||
{
|
||||
}
|
||||
|
||||
class DeepChild extends AbstractSomeClassSecond
|
||||
{
|
||||
public function go()
|
||||
{
|
||||
$this->run();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector\Fixture;
|
||||
|
||||
class AbstractSomeClassTop
|
||||
{
|
||||
protected function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class AbstractSomeClassSecond extends AbstractSomeClassTop
|
||||
{
|
||||
}
|
||||
|
||||
class DeepChild extends AbstractSomeClassSecond
|
||||
{
|
||||
public function go()
|
||||
{
|
||||
$this->run();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector\Fixture;
|
||||
|
||||
class AbstractSomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class Fixture extends AbstractSomeClass
|
||||
{
|
||||
public function go()
|
||||
{
|
||||
$this->run();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector\Fixture;
|
||||
|
||||
class AbstractSomeClass
|
||||
{
|
||||
protected function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class Fixture extends AbstractSomeClass
|
||||
{
|
||||
public function go()
|
||||
{
|
||||
$this->run();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector\Fixture;
|
||||
|
||||
class SkipFinalClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
echo 'first';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector\Fixture;
|
||||
|
||||
class SkipNotHasChildren
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector\Fixture;
|
||||
|
||||
class SkipNotPublic
|
||||
{
|
||||
private function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector\Fixture;
|
||||
|
||||
trait SkipTrait
|
||||
{
|
||||
private function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector\Fixture;
|
||||
|
||||
abstract class SomeParent
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
final class ChildClass extends SomeParent
|
||||
{
|
||||
}
|
||||
|
||||
final class SkipUsedByChildInstance
|
||||
{
|
||||
public function useIt(ChildClass $childClass)
|
||||
{
|
||||
// the method is used, so it should be skipped
|
||||
$childClass->run();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector\Fixture;
|
||||
|
||||
class SkipUsedByExternal
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class External
|
||||
{
|
||||
public function go()
|
||||
{
|
||||
$obj = new SkipUsedByExternal();
|
||||
$obj->run();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector\Fixture;
|
||||
|
||||
class SkipUsedByExternalInClosure
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
function () {
|
||||
$obj = new SkipUsedByExternalInClosure();
|
||||
$obj->run();
|
||||
};
|
||||
|
||||
?>
|
|
@ -1,14 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector\FixtureOpenSource;
|
||||
|
||||
abstract class SkipAbstractClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
final class SomeChild extends SkipAbstractClass
|
||||
{
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class MakeOnlyUsedByChildrenProtectedRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<SmartFileInfo>
|
||||
*/
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
public function provideConfigFilePath(): string
|
||||
{
|
||||
return __DIR__ . '/config/configured_rule.php';
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class OpenSourceRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<SmartFileInfo>
|
||||
*/
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureOpenSource');
|
||||
}
|
||||
|
||||
public function provideConfigFilePath(): string
|
||||
{
|
||||
return __DIR__ . '/config/configured_rule.php';
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Privatization\Rector\ClassMethod\MakeOnlyUsedByChildrenProtectedRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(MakeOnlyUsedByChildrenProtectedRector::class);
|
||||
};
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
return $this->useMe();
|
||||
}
|
||||
|
||||
public function useMe()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
return $this->useMe();
|
||||
}
|
||||
|
||||
private function useMe()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
abstract class SkipAbstract
|
||||
{
|
||||
public abstract function run(ExternalClass $externalClass);
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
use PhpParser\NodeTraverser;
|
||||
|
||||
class SkipAnonymousClass
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$anonymousClass = new class() extends NodeTraverser
|
||||
{
|
||||
public function traverse(array $nodes): array
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
class SkipApiClassAnnotation
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return '1234';
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
class SkipArrayCallMethod
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
register_shutdown_function([$this, 'my_method']);
|
||||
}
|
||||
|
||||
public function my_method()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
class SkipClassExtended extends AbstractParentClass
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
public function stop()
|
||||
{
|
||||
$this->run();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AbstractParentClass
|
||||
{
|
||||
protected function run()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
use Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Source\SomeContractWithGo;
|
||||
|
||||
class SkipContract implements SomeContractWithGo
|
||||
{
|
||||
public function go()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
class SkipController
|
||||
{
|
||||
public function actionStop()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SkipEntity
|
||||
{
|
||||
public function getId(): int
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
class SkipEventSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return ['event_name' => 'methodName'];
|
||||
}
|
||||
|
||||
public function methodName()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
use Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Source\ExternalClass;
|
||||
|
||||
class SkipExternalCall
|
||||
{
|
||||
/**
|
||||
* @var ExternalClass
|
||||
*/
|
||||
private $externalClass;
|
||||
|
||||
public function __construct(ExternalClass $externalClass)
|
||||
{
|
||||
$this->externalClass = $externalClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->externalClass->run();
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
interface SkipInterface
|
||||
{
|
||||
public function go();
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
class SkipInterfaceImplemented
|
||||
{
|
||||
/**
|
||||
* @var SomeInterface
|
||||
*/
|
||||
private $classImplementing;
|
||||
|
||||
public function __construct(SomeInterface $classImplementing)
|
||||
{
|
||||
$this->classImplementing = $classImplementing;
|
||||
}
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->classImplementing->run();
|
||||
}
|
||||
}
|
||||
|
||||
class ClassImplementingInterface implements SomeInterface
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
interface SomeInterface
|
||||
{
|
||||
public function run();
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class SkipParentClassProtected extends Command
|
||||
{
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
class SkipPresenter
|
||||
{
|
||||
public function actionStop()
|
||||
{
|
||||
}
|
||||
|
||||
public function renderStop()
|
||||
{
|
||||
}
|
||||
|
||||
public function handleStop()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @inject
|
||||
*/
|
||||
public function autowireThat()
|
||||
{
|
||||
}
|
||||
|
||||
public function injectThat()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class SkipSymfonyRoute
|
||||
{
|
||||
/** @Route("", name="homepage") */
|
||||
public function homeAction() : Response
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
trait SkipTrait
|
||||
{
|
||||
public function go()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
|
||||
class SkipUsedInTrait
|
||||
{
|
||||
public function go()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
trait SomeTrait
|
||||
{
|
||||
/**
|
||||
* @var SkipUsedInTrait
|
||||
*/
|
||||
private $skipUsedInTrait;
|
||||
|
||||
public function run()
|
||||
{
|
||||
$this->skipUsedInTrait->go();
|
||||
}
|
||||
}
|
||||
|
||||
class AnotherClassUsingTheTraitJustToMakePHPStanWork
|
||||
{
|
||||
use SomeTrait;
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\FixturePhp8;
|
||||
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
final class SkipSymfonyRouteAttribute
|
||||
{
|
||||
#[Route(path: '', name: 'asymfonypageexamplerouting')]
|
||||
public function asymfonypageexampleAction() : Response
|
||||
{
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user