mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
cs fixes, drop duplicated NodeVisitor
This commit is contained in:
parent
28a3835acf
commit
32b90c75c6
@ -10,7 +10,7 @@ gc_disable();
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// Build DI container
|
||||
$container = (new ContainerFactory())->create();
|
||||
$container = (new ContainerFactory)->create();
|
||||
|
||||
// Run Console Application
|
||||
/** @var Application $application */
|
||||
|
@ -1,7 +1,8 @@
|
||||
includes:
|
||||
- vendor/symplify/easy-coding-standard/config/psr2-checkers.neon
|
||||
- vendor/symplify/easy-coding-standard/config/symfony-checkers.neon
|
||||
- vendor/symplify/easy-coding-standard/config/php70-checkers.neon
|
||||
- vendor/symplify/easy-coding-standard/config/php71-checkers.neon
|
||||
- vendor/symplify/easy-coding-standard/config/symplify-checkers.neon
|
||||
- vendor/symplify/easy-coding-standard/config/common.neon
|
||||
- vendor/symplify/easy-coding-standard/config/spaces.neon
|
||||
|
||||
@ -13,11 +14,9 @@ checkers:
|
||||
allowFullyQualifiedNameForCollidingClasses: false
|
||||
allowFullyQualifiedGlobalClasses: true
|
||||
|
||||
# Files
|
||||
# Metrics
|
||||
PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff:
|
||||
absoluteLineLimit: 120
|
||||
|
||||
# Code Analysis
|
||||
PHP_CodeSniffer\Standards\Generic\Sniffs\Metrics\CyclomaticComplexitySniff:
|
||||
absoluteComplexity: 5
|
||||
PHP_CodeSniffer\Standards\Generic\Sniffs\Metrics\NestingLevelSniff:
|
||||
@ -35,8 +34,22 @@ checkers:
|
||||
use_yoda_style: false
|
||||
|
||||
parameters:
|
||||
exclude_checkers:
|
||||
- PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer
|
||||
- PhpCsFixer\Fixer\Operator\NewWithBracesFixer
|
||||
- PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer
|
||||
- PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer
|
||||
|
||||
skip:
|
||||
SlevomatCodingStandard\Sniffs\TypeHints\TypeHintDeclarationSniff:
|
||||
- src/Contract/Rector/RectorInterface.php
|
||||
- *src/Rector/Contrib/Nette/*Rector.php
|
||||
- *src/NodeVisitor/Traverse/*Visitor.php
|
||||
Symplify\CodingStandard\Fixer\Php\ClassStringToClassConstantFixer:
|
||||
# class might not exist
|
||||
- src/Rector/Contrib/Nette/RemoveConfiguratorConstantsRector.php
|
||||
- src/Rector/Contrib/Nette/NetteObjectToSmartTraitRector.php
|
||||
|
||||
Symplify\CodingStandard\Sniffs\Debug\CommentedOutCodeSniff:
|
||||
# examples of code to be found
|
||||
- src/NodeVisitor/DependencyInjection/NamedServicesToConstructor/GetterToPropertyRector.php
|
||||
|
@ -64,7 +64,7 @@ final class StatementGlue
|
||||
private function insertBefore(Class_ $classNode, Node $node, $key): void
|
||||
{
|
||||
Arrays::insertBefore($classNode->stmts, $key, [
|
||||
'before_' . $key => $node
|
||||
'before_' . $key => $node,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ interface DeprecationInterface
|
||||
|
||||
/**
|
||||
* Version this deprecations is active since.
|
||||
* E.g. 2.3
|
||||
* E.g. 2.3.
|
||||
*/
|
||||
public function sinceVersion(): float;
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ use PhpParser\NodeTraverser;
|
||||
use PhpParser\NodeVisitor;
|
||||
use PhpParser\NodeVisitor\CloningVisitor;
|
||||
use Rector\NodeVisitor\Traverse\NodeConnectorNodeVisitor;
|
||||
use Rector\NodeVisitor\Traverse\ParentConnectorNodeVisitor;
|
||||
|
||||
final class NodeTraverserFactory
|
||||
{
|
||||
@ -20,8 +19,7 @@ final class NodeTraverserFactory
|
||||
*/
|
||||
private $priorityNodeVisitorClasses = [
|
||||
CloningVisitor::class,
|
||||
ParentConnectorNodeVisitor::class,
|
||||
NodeConnectorNodeVisitor::class
|
||||
NodeConnectorNodeVisitor::class,
|
||||
];
|
||||
|
||||
public function addNodeVisitor(NodeVisitor $nodeVisitor): void
|
||||
|
@ -76,6 +76,7 @@ final class PropertyRector extends NodeVisitorAbstract
|
||||
}
|
||||
|
||||
$this->tokenSwitcher->enable();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -120,7 +121,7 @@ final class PropertyRector extends NodeVisitorAbstract
|
||||
$propertyType = $propertyDocBlock->getAnnotationsOfType('var')[0]
|
||||
->getTypes()[0];
|
||||
|
||||
$propertyName = (string)$propertyNode->props[0]->name;
|
||||
$propertyName = (string) $propertyNode->props[0]->name;
|
||||
|
||||
$this->classPropertyCollector->addPropertyForClass($this->className, $propertyType, $propertyName);
|
||||
}
|
||||
|
@ -75,6 +75,7 @@ final class GetterToPropertyRector extends NodeVisitorAbstract
|
||||
{
|
||||
if ($this->isCandidate($node)) {
|
||||
$this->reconstruct($node);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
|
@ -7,39 +7,29 @@ use PhpParser\NodeVisitorAbstract;
|
||||
|
||||
final class NodeConnectorNodeVisitor extends NodeVisitorAbstract
|
||||
{
|
||||
/**
|
||||
* @var Node[]
|
||||
*/
|
||||
private $stack = [];
|
||||
|
||||
/**
|
||||
* @var Node
|
||||
*/
|
||||
private $prev;
|
||||
|
||||
/**
|
||||
* @param Node[] $nodes
|
||||
*/
|
||||
public function beforeTraverse(array $nodes): void
|
||||
{
|
||||
$this->stack = [];
|
||||
$this->prev = null;
|
||||
}
|
||||
|
||||
public function enterNode(Node $node): void
|
||||
{
|
||||
if (! empty($this->stack)) {
|
||||
$node->setAttribute('parent', $this->stack[count($this->stack)-1]);
|
||||
}
|
||||
|
||||
if ($this->prev && $this->prev->getAttribute('parent') === $node->getAttribute('parent')) {
|
||||
if ($this->prev) {
|
||||
$node->setAttribute('prev', $this->prev);
|
||||
$this->prev->setAttribute('next', $node);
|
||||
}
|
||||
|
||||
$this->stack[] = $node;
|
||||
}
|
||||
|
||||
public function leaveNode(Node $node): void
|
||||
{
|
||||
$this->prev = $node;
|
||||
array_pop($this->stack);
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\NodeVisitor\Traverse;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\NodeVisitorAbstract;
|
||||
|
||||
final class ParentConnectorNodeVisitor extends NodeVisitorAbstract
|
||||
{
|
||||
/**
|
||||
* @var Node[]
|
||||
*/
|
||||
private $stack = [];
|
||||
|
||||
public function beforeTraverse(array $nodes): void
|
||||
{
|
||||
$this->stack = [];
|
||||
}
|
||||
|
||||
public function enterNode(Node $node): void
|
||||
{
|
||||
if (! empty($this->stack)) {
|
||||
$node->setAttribute('parent', $this->stack[count($this->stack)-1]);
|
||||
}
|
||||
|
||||
$this->stack[] = $node;
|
||||
}
|
||||
|
||||
public function leaveNode(Node $node): void
|
||||
{
|
||||
array_pop($this->stack);
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ use Rector\NodeTraverser\TokenSwitcher;
|
||||
use Rector\Rector\AbstractRector;
|
||||
|
||||
/**
|
||||
* Covers https://doc.nette.org/en/2.4/migration-2-4#toc-nette-smartobject
|
||||
* Covers https://doc.nette.org/en/2.4/migration-2-4#toc-nette-smartobject.
|
||||
*/
|
||||
final class NetteObjectToSmartTraitRector extends AbstractRector
|
||||
{
|
||||
@ -55,6 +55,7 @@ final class NetteObjectToSmartTraitRector extends AbstractRector
|
||||
}
|
||||
|
||||
$this->tokenSwitcher->enable();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -78,7 +79,7 @@ final class NetteObjectToSmartTraitRector extends AbstractRector
|
||||
private function createTraitUse(string $traitName): TraitUse
|
||||
{
|
||||
return new TraitUse([
|
||||
new FullyQualified($traitName)
|
||||
new FullyQualified($traitName),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,9 @@ final class FileReconstructor
|
||||
$this->tokenSwitcher = $tokenSwitcher;
|
||||
}
|
||||
|
||||
// ref: https://github.com/nikic/PHP-Parser/issues/344#issuecomment-298162516
|
||||
/**
|
||||
* See https://github.com/nikic/PHP-Parser/issues/344#issuecomment-298162516.
|
||||
*/
|
||||
public function processFile(SplFileInfo $file): string
|
||||
{
|
||||
$fileContent = file_get_contents($file->getRealPath());
|
||||
|
Loading…
x
Reference in New Issue
Block a user