mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-14 12:29:43 +01:00
remove unused methods from ClassManipulator
This commit is contained in:
parent
06de6d708a
commit
67104fdca3
7
ecs.yaml
7
ecs.yaml
@ -1,5 +1,6 @@
|
||||
services:
|
||||
ClassCognitive:
|
||||
Symplify\CodingStandard\Sniffs\CleanCode\ClassCognitiveComplexitySniff:
|
||||
max_class_cognitive_complexity: 100
|
||||
|
||||
Symplify\CodingStandard\Sniffs\CleanCode\CognitiveComplexitySniff:
|
||||
max_cognitive_complexity: 9
|
||||
@ -83,6 +84,10 @@ parameters:
|
||||
# hidden API
|
||||
- 'src/Rector/AbstractRector.php'
|
||||
|
||||
Symplify\CodingStandard\Sniffs\CleanCode\ClassCognitiveComplexitySniff:
|
||||
# node printing
|
||||
- 'utils/documentation-generator/src/Command/DumpNodesCommand.php'
|
||||
|
||||
Symplify\CodingStandard\Sniffs\CleanCode\CognitiveComplexitySniff:
|
||||
# todo
|
||||
- "packages/better-php-doc-parser/src/Printer/WhitespaceDetector.php"
|
||||
|
@ -13,7 +13,6 @@ use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use Rector\Core\PhpParser\Node\Manipulator\ClassManipulator;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
@ -25,16 +24,6 @@ use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
*/
|
||||
final class Php4ConstructorRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var ClassManipulator
|
||||
*/
|
||||
private $classManipulator;
|
||||
|
||||
public function __construct(ClassManipulator $classManipulator)
|
||||
{
|
||||
$this->classManipulator = $classManipulator;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition(
|
||||
@ -94,7 +83,7 @@ PHP
|
||||
}
|
||||
|
||||
// does it already have a __construct method?
|
||||
if (! $this->classManipulator->hasClassMethod($classNode, '__construct')) {
|
||||
if ($classNode->getMethod('__construct') === null) {
|
||||
$node->name = new Identifier('__construct');
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ final class ClassManipulator
|
||||
|
||||
/**
|
||||
* @param Stmt[] $nodes
|
||||
* @return Stmt[] $nodes
|
||||
* @return Stmt[]
|
||||
*/
|
||||
public function insertBeforeAndFollowWithNewline(array $nodes, Stmt $stmt, int $key): array
|
||||
{
|
||||
@ -131,17 +131,6 @@ final class ClassManipulator
|
||||
return $this->insertBefore($nodes, new Nop(), $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Stmt[] $nodes
|
||||
* @return Stmt[] $nodes
|
||||
*/
|
||||
public function insertBefore(array $nodes, Stmt $stmt, int $key): array
|
||||
{
|
||||
array_splice($nodes, $key, 0, [$stmt]);
|
||||
|
||||
return $nodes;
|
||||
}
|
||||
|
||||
public function addConstantToClass(Class_ $class, string $constantName, ClassConst $classConst): void
|
||||
{
|
||||
if ($this->hasClassConstant($class, $constantName)) {
|
||||
@ -253,13 +242,6 @@ final class ClassManipulator
|
||||
return false;
|
||||
}
|
||||
|
||||
public function hasClassMethod(Class_ $classNode, string $methodName): bool
|
||||
{
|
||||
$methodNames = $this->getClassMethodNames($classNode);
|
||||
|
||||
return in_array($methodName, $methodNames, true);
|
||||
}
|
||||
|
||||
public function removeProperty(Class_ $class, string $propertyName): void
|
||||
{
|
||||
$this->removeProperties($class, [$propertyName]);
|
||||
@ -514,6 +496,17 @@ final class ClassManipulator
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Stmt[] $nodes
|
||||
* @return Stmt[]
|
||||
*/
|
||||
private function insertBefore(array $nodes, Stmt $stmt, int $key): array
|
||||
{
|
||||
array_splice($nodes, $key, 0, [$stmt]);
|
||||
|
||||
return $nodes;
|
||||
}
|
||||
|
||||
private function tryInsertBeforeFirstMethod(Class_ $classNode, Stmt $stmt): bool
|
||||
{
|
||||
foreach ($classNode->stmts as $key => $classStmt) {
|
||||
@ -585,24 +578,6 @@ final class ClassManipulator
|
||||
$classMethod->stmts[] = new Expression($assign);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function getClassMethodNames(Class_ $classNode): array
|
||||
{
|
||||
$classMethodNames = [];
|
||||
foreach ($classNode->getMethods() as $classMethod) {
|
||||
$methodName = $this->nodeNameResolver->getName($classMethod);
|
||||
if (! is_string($methodName)) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
$classMethodNames[] = $methodName;
|
||||
}
|
||||
|
||||
return $classMethodNames;
|
||||
}
|
||||
|
||||
private function hasClassParentClassMethod(Class_ $class, string $methodName): bool
|
||||
{
|
||||
$parentClassName = $class->getAttribute(AttributeKey::PARENT_CLASS_NAME);
|
||||
|
Loading…
x
Reference in New Issue
Block a user