mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-28 23:10:51 +00:00
66cc09e8b6
d118ae38e2
Use phpstan-deprecation-rules (#3330)
80 lines
2.0 KiB
PHP
80 lines
2.0 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\Contract\Rector\DeprecatedRectorInterface;
|
|
use Rector\Core\Rector\AbstractScopeAwareRector;
|
|
use RectorPrefix202302\Symfony\Component\Console\Style\SymfonyStyle;
|
|
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
|
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|
/**
|
|
* @deprecated Use specific rules working with strict type declarations instead of this docs blocks non-reliable one
|
|
*/
|
|
final class AddArrayReturnDocTypeRector extends AbstractScopeAwareRector implements DeprecatedRectorInterface
|
|
{
|
|
/**
|
|
* @readonly
|
|
* @var \Symfony\Component\Console\Style\SymfonyStyle
|
|
*/
|
|
private $symfonyStyle;
|
|
public function __construct(SymfonyStyle $symfonyStyle)
|
|
{
|
|
$this->symfonyStyle = $symfonyStyle;
|
|
}
|
|
public function getRuleDefinition() : RuleDefinition
|
|
{
|
|
return new RuleDefinition('Adds @return annotation to array parameters inferred from the rest of the code', [new CodeSample(<<<'CODE_SAMPLE'
|
|
class SomeClass
|
|
{
|
|
/**
|
|
* @var int[]
|
|
*/
|
|
private $values;
|
|
|
|
public function getValues(): array
|
|
{
|
|
return $this->values;
|
|
}
|
|
}
|
|
CODE_SAMPLE
|
|
, <<<'CODE_SAMPLE'
|
|
class SomeClass
|
|
{
|
|
/**
|
|
* @var int[]
|
|
*/
|
|
private $values;
|
|
|
|
/**
|
|
* @return int[]
|
|
*/
|
|
public function getValues(): array
|
|
{
|
|
return $this->values;
|
|
}
|
|
}
|
|
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
|
|
{
|
|
$this->symfonyStyle->error('The AddArrayReturnDocTypeRector rule is deprecated, as it works with doc block types that are not reliable and might infer incorrect types');
|
|
\sleep(5);
|
|
return null;
|
|
}
|
|
}
|