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
8 changes: 1 addition & 7 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ includes:

parameters:
level: 8

errorFormat: symplify
reportUnmatchedIgnoredErrors: false

Expand Down Expand Up @@ -98,18 +99,11 @@ parameters:
identifier: symplify.seeAnnotationToTest
path: rules/DowngradePhp85/Rector/StmtsAwareInterface/DowngradePipeOperatorRector.php

# handle next
-
identifier: method.parentMethodFinalByPhpDoc
path: rules/DowngradePhp80/Rector/NullsafeMethodCall/DowngradeNullsafeToTernaryOperatorRector.php

# keep for simplicity
-
identifier: rector.avoidFeatureSetAttributeInRector
paths:
- rules/DowngradePhp80/Rector/FuncCall/DowngradeSubstrFalsyRector.php
- rules/DowngradePhp72/Rector/ConstFetch/DowngradePhp72JsonConstRector.php
- rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php
- rules/DowngradePhp74/Rector/MethodCall/DowngradeReflectionGetTypeRector.php
- rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionGetAttributesRector.php
- rules/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php
Expand Down
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NamedVariableFactory::createVariable() should make increment variable name consistent per file

public function createVariable(string $variableName, Expression $expression): Variable

, I will create PR for it.

Copy link
Member

@samsonasik samsonasik Dec 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scope seems can't detect variable exists on new just created variable node so the counter seems need on file level, so static flag may needed, something like:

        static $currentFile = $this->file;

        if ($currentFile !== $this->file) {
            $this->counter = 0;
            $currentFile = $this->file;
        }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

}

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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class ShortCircuit4
{
public function run(bool $param)
{
return ($nullsafeVariable1 = $this->clock) ? $nullsafeVariable1->now->format('U.u') : null;
return ($nullsafeVariable15 = $this->clock) ? $nullsafeVariable15->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 ShortCircuit5
{
public function run(bool $param)
{
return ($nullsafeVariable1 = $this->clock) ? $nullsafeVariable1->now()->format : null;
return ($nullsafeVariable16 = $this->clock) ? $nullsafeVariable16->now()->format : null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Rector\DowngradePhp72\NodeManipulator\JsonConstCleaner;
use Rector\Enum\JsonConstant;
use Rector\NodeAnalyzer\DefineFuncCallAnalyzer;
use Rector\PhpParser\NodeTraverser\SimpleNodeTraverser;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -94,9 +95,6 @@ private function markConstantKnownInInnerStmts(If_ $if): void
return;
}

$this->traverseNodesWithCallable($if, static function (Node $node): null {
$node->setAttribute(self::PHP72_JSON_CONSTANT_IS_KNOWN, true);
return null;
});
SimpleNodeTraverser::decorateWithAttributeValue($if, self::PHP72_JSON_CONSTANT_IS_KNOWN, true);
}
}
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