Skip to content
Merged
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 config/level/coding-style/coding-style.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ services:
Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector: ~
Rector\CodingStyle\Rector\ClassConst\SplitGroupedConstantsAndPropertiesRector: ~
Rector\CodingStyle\Rector\String_\SplitStringClassConstantToClassConstFetchRector: ~
Rector\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector: ~
2 changes: 2 additions & 0 deletions ecs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ parameters:
- 'packages/Laravel/src/Rector/FuncCall/HelperFunctionToConstructorInjectionRector.php'
- 'packages/PhpSpecToPHPUnit/src/Rector/MethodCall/PhpSpecPromisesToPHPUnitAssertRector.php'
- 'packages/NetteTesterToPHPUnit/src/AssertManipulator.php'
# aliases
- 'packages/CodingStyle/src/Rector/Namespace_/ImportFullyQualifiedNamesRector.php'

# copied 3rd party logic
- 'packages/Php/src/EregToPcreTransformer.php'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
namespace Rector\CodeQuality\Rector\Array_;

use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\ClosureUse;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Return_;
use Rector\NodeContainer\ParsedNodesByType;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;
Expand Down Expand Up @@ -75,7 +84,7 @@ private function compareSize($first, $second)
*/
public function getNodeTypes(): array
{
return [Node\Expr\Array_::class];
return [Array_::class];
}

/**
Expand All @@ -95,21 +104,21 @@ public function refactor(Node $node): ?Node
return null;
}

$anonymousFunction = new Node\Expr\Closure();
$anonymousFunction = new Closure();
$anonymousFunction->params = $classMethod->params;

$innerMethodCall = new Node\Expr\MethodCall($objectVariable, $classMethod->name);
$innerMethodCall = new MethodCall($objectVariable, $classMethod->name);
$innerMethodCall->args = $this->convertParamsToArgs($classMethod->params);

if ($classMethod->returnType) {
$anonymousFunction->returnType = $classMethod->returnType;
}

$anonymousFunction->stmts[] = new Node\Stmt\Return_($innerMethodCall);
$anonymousFunction->stmts[] = new Return_($innerMethodCall);

if ($objectVariable instanceof Node\Expr\Variable) {
if ($objectVariable instanceof Variable) {
if (! $this->isName($objectVariable, 'this')) {
$anonymousFunction->uses[] = new Node\Expr\ClosureUse($objectVariable);
$anonymousFunction->uses[] = new ClosureUse($objectVariable);
}
}

Expand All @@ -124,13 +133,13 @@ private function convertParamsToArgs(array $params): array
{
$args = [];
foreach ($params as $key => $param) {
$args[$key] = new Node\Arg($param->var);
$args[$key] = new Arg($param->var);
}

return $args;
}

private function matchCallableMethod(Node\Expr $objectExpr, Node\Expr $methodExpr): ?Node\Stmt\ClassMethod
private function matchCallableMethod(Expr $objectExpr, Expr $methodExpr): ?ClassMethod
{
$methodName = $this->getValue($methodExpr);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use PhpParser\Node;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\BooleanNot;
use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\CodeSample;
use Rector\RectorDefinition\RectorDefinition;
Expand Down Expand Up @@ -58,7 +60,7 @@ public function run()
*/
public function getNodeTypes(): array
{
return [Identical::class, Node\Expr\BooleanNot::class];
return [Identical::class, BooleanNot::class];
}

/**
Expand All @@ -80,13 +82,13 @@ public function refactor(Node $node): ?Node
return null;
}

return new Node\Expr\BinaryOp\NotIdentical($identical->left, $identical->right);
return new NotIdentical($identical->left, $identical->right);
}

return null;
}

private function processIdentical(Identical $identical): ?Node\Expr\BinaryOp\NotIdentical
private function processIdentical(Identical $identical): ?NotIdentical
{
if (! $this->isBoolType($identical->left)) {
return null;
Expand All @@ -96,8 +98,8 @@ private function processIdentical(Identical $identical): ?Node\Expr\BinaryOp\Not
return null;
}

if ($identical->left instanceof Node\Expr\BooleanNot) {
return new Node\Expr\BinaryOp\NotIdentical($identical->left->expr, $identical->right);
if ($identical->left instanceof BooleanNot) {
return new NotIdentical($identical->left->expr, $identical->right);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Rector\CodeQuality\Rector\Identical;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\BooleanNot;
Expand Down Expand Up @@ -65,7 +66,7 @@ public function refactor(Node $node): ?Node
return null;
}

private function processBoolTypeToNotBool(Node $node, Node\Expr $leftExpr, Node\Expr $rightExpr): ?Node\Expr
private function processBoolTypeToNotBool(Node $node, Expr $leftExpr, Expr $rightExpr): ?Expr
{
if ($node instanceof Identical) {
if ($this->isTrue($rightExpr)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if ($node instanceof Node\Stmt\ClassConst) {
if ($node instanceof ClassConst) {
if (count($node->consts) < 2) {
return null;
}
Expand All @@ -73,9 +73,7 @@ public function refactor(Node $node): ?Node
$node->consts = [$firstConstant];

foreach ($allConstants as $anotherConstant) {
$nextClassConst = new Node\Stmt\ClassConst([
$anotherConstant,
], $node->flags, $node->getAttributes());
$nextClassConst = new ClassConst([$anotherConstant], $node->flags, $node->getAttributes());
$this->addNodeAfterNode($nextClassConst, $node);
}

Expand All @@ -92,7 +90,7 @@ public function refactor(Node $node): ?Node
$node->props = [$firstProperty];

foreach ($allProperties as $anotherProperty) {
$nextProperty = new Node\Stmt\Property($node->flags, [$anotherProperty], $node->getAttributes());
$nextProperty = new Property($node->flags, [$anotherProperty], $node->getAttributes());
$this->addNodeAfterNode($nextProperty, $node);
}

Expand Down
Loading