Skip to content
Open
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"phpstan/phpstan": "^2.1.32",
"phpstan/phpstan-webmozart-assert": "^2.0",
"phpunit/phpunit": "^11.5",
"rector/rector-src": "dev-main",
"rector/rector-src": "dev-tv-rector-avoid-before-traverser",
"rector/type-perfect": "^2.1",
"symplify/easy-coding-standard": "^12.3",
"symplify/phpstan-extensions": "^12.0",
Expand Down
12 changes: 1 addition & 11 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ parameters:

# see https://phpstan.org/writing-php-code/phpdoc-types#global-type-aliases
typeAliases:
StmtsAware: \PhpParser\Node\Stmt\Block | \PhpParser\Node\Expr\Closure | \PhpParser\Node\Stmt\Case_ | \PhpParser\Node\Stmt\Catch_ | \PhpParser\Node\Stmt\ClassMethod | \PhpParser\Node\Stmt\Do_ | \PhpParser\Node\Stmt\Else_ | \PhpParser\Node\Stmt\ElseIf_ | \PhpParser\Node\Stmt\Finally_ | \PhpParser\Node\Stmt\For_ | \PhpParser\Node\Stmt\Foreach_ | \PhpParser\Node\Stmt\Function_ | \PhpParser\Node\Stmt\If_ | \PhpParser\Node\Stmt\Namespace_ | \PhpParser\Node\Stmt\TryCatch | \PhpParser\Node\Stmt\While_ | \Rector\PhpParser\Node\CustomNode\FileWithoutNamespace
StmtsAware: \PhpParser\Node\Stmt\Block | \PhpParser\Node\Expr\Closure | \PhpParser\Node\Stmt\Case_ | \PhpParser\Node\Stmt\Catch_ | \PhpParser\Node\Stmt\ClassMethod | \PhpParser\Node\Stmt\Do_ | \PhpParser\Node\Stmt\Else_ | \PhpParser\Node\Stmt\ElseIf_ | \PhpParser\Node\Stmt\Finally_ | \PhpParser\Node\Stmt\For_ | \PhpParser\Node\Stmt\Foreach_ | \PhpParser\Node\Stmt\Function_ | \PhpParser\Node\Stmt\If_ | \PhpParser\Node\Stmt\Namespace_ | \PhpParser\Node\Stmt\TryCatch | \PhpParser\Node\Stmt\While_ | \Rector\PhpParser\Node\FileNode

# requires exact closure types
checkMissingCallableSignature: true
Expand Down Expand Up @@ -92,13 +92,3 @@ parameters:
-
identifier: symplify.forbiddenFuncCall
path: rules/DowngradePhp73/Rector/FuncCall/DowngradeArrayKeyFirstLastRector.php

# false positive
-
identifier: symplify.seeAnnotationToTest
path: rules/DowngradePhp85/Rector/StmtsAwareInterface/DowngradePipeOperatorRector.php

# handle next
-
identifier: method.parentMethodFinalByPhpDoc
path: rules/DowngradePhp80/Rector/NullsafeMethodCall/DowngradeNullsafeToTernaryOperatorRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class GetNullable
{
public function run($value)
{
return ($nullsafeVariable1 = $this->extractArrayItemByKey($value)) ? $nullsafeVariable1->value : null;
return ($nullsafeVariable6 = $this->extractArrayItemByKey($value)) ? $nullsafeVariable6->value : null;
}

protected function extractArrayItemByKey($value): ?ArrayItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ trait GetNullableInTrait
{
public function run($value)
{
return ($nullsafeVariable1 = $this->extractArrayItemByKey($value)) ? $nullsafeVariable1->value : null;
return ($nullsafeVariable7 = $this->extractArrayItemByKey($value)) ? $nullsafeVariable7->value : null;
}

protected function extractArrayItemByKey($value): ?ArrayItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class MultipleCall
{
public function run($object)
{
$result = ($nullsafeVariable1 = ($nullsafeVariable2 = $object->multiple($args1)) ? $nullsafeVariable2->call($args2) : null) ? $nullsafeVariable1->otherCall($args3) : null;
$result = ($nullsafeVariable3 = ($nullsafeVariable4 = ($nullsafeVariable5 = $object->multiple($args1)) ? $nullsafeVariable5->call($args2) : null) ? $nullsafeVariable4->otherCall($args3) : null) ? $nullsafeVariable3->anotherCall($args4) : null;
$result = ($nullsafeVariable8 = ($nullsafeVariable9 = $object->multiple($args1)) ? $nullsafeVariable9->call($args2) : null) ? $nullsafeVariable8->otherCall($args3) : null;
$result = ($nullsafeVariable10 = ($nullsafeVariable11 = ($nullsafeVariable12 = $object->multiple($args1)) ? $nullsafeVariable12->call($args2) : null) ? $nullsafeVariable11->otherCall($args3) : null) ? $nullsafeVariable10->anotherCall($args4) : null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class ShortCircuit
{
public function run(bool $param)
{
return ($nullsafeVariable1 = $this->clock) ? $nullsafeVariable1->now()->format('U.u') : null;
return ($nullsafeVariable13 = $this->clock) ? $nullsafeVariable13->now()->format('U.u') : null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class ShortCircuit3
{
public function run(bool $param)
{
return ($nullsafeVariable1 = $this->clock) ? $nullsafeVariable1->now->format : null;
return ($nullsafeVariable14 = $this->clock) ? $nullsafeVariable14->now->format : null;
}
}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ final class DowngradeNullsafeToTernaryOperatorRector extends AbstractRector
{
private int $counter = 0;

/**
* Hack-ish way to reset counter for a new file, to avoid rising counter for each file
*
* @param Node[] $nodes
* @return array|Node[]|null
*/
public function beforeTraverse(array $nodes): ?array
{
$this->counter = 0;
return parent::beforeTraverse($nodes);
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Change nullsafe operator to ternary operator rector', [
Expand Down Expand Up @@ -75,6 +63,7 @@ public function refactor(Node $node): ?Ternary
$node->var->name,
$node->var->args
), $node->name, $node->args);

return new Ternary($assign, $methodCallOrPropertyFetch, $this->nodeFactory->createNull());
}

Expand Down