mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-30 16:00:52 +00:00
66cc09e8b6
d118ae38e2
Use phpstan-deprecation-rules (#3330)
79 lines
1.9 KiB
PHP
79 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\TypeDeclaration\Rector\ClassMethod;
|
|
|
|
use PhpParser\Node;
|
|
use PhpParser\Node\Stmt\ClassMethod;
|
|
use Rector\Core\Contract\Rector\DeprecatedRectorInterface;
|
|
use Rector\Core\Rector\AbstractRector;
|
|
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.
|
|
*/
|
|
final class AddArrayParamDocTypeRector extends AbstractRector 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 @param annotation to array parameters inferred from the rest of the code', [new CodeSample(<<<'CODE_SAMPLE'
|
|
class SomeClass
|
|
{
|
|
/**
|
|
* @var int[]
|
|
*/
|
|
private $values;
|
|
|
|
public function __construct(array $values)
|
|
{
|
|
$this->values = $values;
|
|
}
|
|
}
|
|
CODE_SAMPLE
|
|
, <<<'CODE_SAMPLE'
|
|
class SomeClass
|
|
{
|
|
/**
|
|
* @var int[]
|
|
*/
|
|
private $values;
|
|
|
|
/**
|
|
* @param int[] $values
|
|
*/
|
|
public function __construct(array $values)
|
|
{
|
|
$this->values = $values;
|
|
}
|
|
}
|
|
CODE_SAMPLE
|
|
)]);
|
|
}
|
|
/**
|
|
* @return array<class-string<Node>>
|
|
*/
|
|
public function getNodeTypes() : array
|
|
{
|
|
return [ClassMethod::class];
|
|
}
|
|
/**
|
|
* @param ClassMethod $node
|
|
*/
|
|
public function refactor(Node $node) : ?Node
|
|
{
|
|
$this->symfonyStyle->error('The AddArrayParamDocTypeRector rule is deprecated, as it works with doc block types that are not reliable and might infer incorrect types');
|
|
\sleep(5);
|
|
return null;
|
|
}
|
|
}
|