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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use Rector\CodeQuality\Rector\Class_\ConvertStaticToSelfRector;
use Rector\Exception\ShouldNotHappenException;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand All @@ -16,11 +17,6 @@
*/
final class ConvertStaticPrivateConstantToSelfRector extends AbstractRector
{
public function __construct(
private readonly ConvertStaticToSelfRector $convertStaticToSelfRector
) {
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
Expand Down Expand Up @@ -72,6 +68,10 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Class_
{
return $this->convertStaticToSelfRector->refactor($node);
throw new ShouldNotHappenException(sprintf(
'The %s rule is deprecated. Use %s instead',
self::class,
ConvertStaticToSelfRector::class,
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassConstantReflection;
use PHPStan\TrinaryLogic;
use PhpParser\Node;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\StaticCall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use Rector\Exception\ShouldNotHappenException;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand All @@ -15,11 +16,6 @@
*/
final class StaticToSelfStaticMethodCallOnFinalClassRector extends AbstractRector
{
public function __construct(
private readonly ConvertStaticToSelfRector $convertStaticToSelfRector
) {
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Change `static::methodCall()` to `self::methodCall()` on final class', [
Expand Down Expand Up @@ -70,6 +66,10 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Class_
{
return $this->convertStaticToSelfRector->refactor($node);
throw new ShouldNotHappenException(sprintf(
'The %s rule is deprecated. Use %s instead',
self::class,
ConvertStaticToSelfRector::class,
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public function refactor(Node $node): ?Node
}

$scalarArrayTypes = [];
foreach ($returnedVariableNames as $variableName) {
$scalarType = $this->resolveScalarArrayTypeForVariable($node, $variableName);
foreach ($returnedVariableNames as $returnedVariableName) {
$scalarType = $this->resolveScalarArrayTypeForVariable($node, $returnedVariableName);
if ($scalarType instanceof Type) {
$scalarArrayTypes[] = $scalarType;
} else {
Expand Down Expand Up @@ -191,11 +191,9 @@ private function resolveScalarArrayTypeForVariable(ClassMethod|Function_ $node,
$arrayHasDimAssigns = false;

foreach ($assigns as $assign) {
if ($assign->var instanceof Variable && $this->isName($assign->var, $variableName)) {
if ($assign->expr instanceof Array_ && $assign->expr->items === []) {
$arrayHasInitialized = true;
continue;
}
if ($assign->var instanceof Variable && $this->isName($assign->var, $variableName) && ($assign->expr instanceof Array_ && $assign->expr->items === [])) {
$arrayHasInitialized = true;
continue;
}

if (! $assign->var instanceof ArrayDimFetch) {
Expand Down
Loading