rector/rules/TypeDeclaration/Rector/ClassMethod/ArrayShapeFromConstantArrayReturnRector.php
Tomas Votruba 773600ee65 Updated Rector to commit 09fe7f5c1ebe6b6eacddc9765284dce921bd9191
09fe7f5c1e [TypeDeclaration] Deprecate ArrayShapeFromConstantArrayReturnRector as uses docblocks that we move away from since 0.15 (#4571)
2023-07-21 14:06:17 +00:00

57 lines
1.4 KiB
PHP

<?php
declare (strict_types=1);
namespace Rector\TypeDeclaration\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @deprecated As we're moving from docblock types as unreliable and work only with native type declarations. See https://getrector.com/blog/new-in-rector-015-complete-safe-and-known-type-declarations
*/
final class ArrayShapeFromConstantArrayReturnRector extends AbstractScopeAwareRector
{
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Add array shape exact types based on constant keys of array', [new CodeSample(<<<'CODE_SAMPLE'
final class SomeClass
{
public function run(string $name)
{
return ['name' => $name];
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
final class SomeClass
{
/**
* @return array{name: string}
*/
public function run(string $name)
{
return ['name' => $name];
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [ClassMethod::class];
}
/**
* @param ClassMethod $node
*/
public function refactorWithScope(Node $node, Scope $scope) : ?Node
{
return null;
}
}