mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-29 07:20:52 +00:00
773600ee65
09fe7f5c1e
[TypeDeclaration] Deprecate ArrayShapeFromConstantArrayReturnRector as uses docblocks that we move away from since 0.15 (#4571)
57 lines
1.4 KiB
PHP
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;
|
|
}
|
|
}
|