REDROOM
PHP 8.2.31
Path:
Logout
Edit File
Size: 3.22 KB
Close
//opt/cpanel/ea-wappspector/vendor/rector/rector/rules/DeadCode/Rector/ClassMethod/RemoveUnusedConstructorParamRector.php
Text
Base64
<?php declare (strict_types=1); namespace Rector\DeadCode\Rector\ClassMethod; use PhpParser\Node; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Reflection\ClassReflection; use Rector\DeadCode\NodeManipulator\ClassMethodParamRemover; use Rector\NodeAnalyzer\ParamAnalyzer; use Rector\Rector\AbstractRector; use Rector\Reflection\ReflectionResolver; use Rector\ValueObject\MethodName; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector\RemoveUnusedConstructorParamRectorTest */ final class RemoveUnusedConstructorParamRector extends AbstractRector { /** * @readonly * @var \Rector\NodeAnalyzer\ParamAnalyzer */ private $paramAnalyzer; /** * @readonly * @var \Rector\Reflection\ReflectionResolver */ private $reflectionResolver; /** * @readonly * @var \Rector\DeadCode\NodeManipulator\ClassMethodParamRemover */ private $classMethodParamRemover; public function __construct(ParamAnalyzer $paramAnalyzer, ReflectionResolver $reflectionResolver, ClassMethodParamRemover $classMethodParamRemover) { $this->paramAnalyzer = $paramAnalyzer; $this->reflectionResolver = $reflectionResolver; $this->classMethodParamRemover = $classMethodParamRemover; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Remove unused parameter in constructor', [new CodeSample(<<<'CODE_SAMPLE' final class SomeClass { private $hey; public function __construct($hey, $man) { $this->hey = $hey; } } CODE_SAMPLE , <<<'CODE_SAMPLE' final class SomeClass { private $hey; public function __construct($hey) { $this->hey = $hey; } } CODE_SAMPLE )]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [Class_::class]; } /** * @param Class_ $node */ public function refactor(Node $node) : ?Node { $constructorClassMethod = $node->getMethod(MethodName::CONSTRUCT); if (!$constructorClassMethod instanceof ClassMethod) { return null; } if ($constructorClassMethod->params === []) { return null; } if ($this->paramAnalyzer->hasPropertyPromotion($constructorClassMethod->params)) { return null; } if ($constructorClassMethod->isAbstract()) { return null; } $classReflection = $this->reflectionResolver->resolveClassReflection($node); if (!$classReflection instanceof ClassReflection) { return null; } $interfaces = $classReflection->getInterfaces(); foreach ($interfaces as $interface) { if ($interface->hasNativeMethod(MethodName::CONSTRUCT)) { return null; } } $changedConstructorClassMethod = $this->classMethodParamRemover->processRemoveParams($constructorClassMethod); if (!$changedConstructorClassMethod instanceof ClassMethod) { return null; } return $node; } }
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 0 × Files: 10
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
RemoveEmptyClassMethodRector.php
6.28 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
RemoveNullTagValueNodeRector.php
5.28 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
RemoveUnusedConstructorParamRector.php
3.22 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
RemoveUnusedPrivateMethodParameterRector.php
7.57 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
RemoveUnusedPrivateMethodRector.php
4.99 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
RemoveUnusedPromotedPropertyRector.php
7.18 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
RemoveUnusedPublicMethodParameterRector.php
4.00 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
RemoveUselessParamTagRector.php
2.25 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
RemoveUselessReturnExprInConstructRector.php
3.01 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
RemoveUselessReturnTagRector.php
2.39 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).