mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 14:27:14 +01:00
[DeadCode] Skip @api in unused public constastants
This commit is contained in:
parent
dc4d5adc9d
commit
d4fb908810
@ -6,6 +6,7 @@ namespace Rector\DeadCode\Rector\ClassConst;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassConst;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\Caching\Contract\Rector\ZeroCacheRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
@ -103,11 +104,25 @@ PHP
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassConst $node
|
||||
*/
|
||||
private function shouldSkip(Node $node): bool
|
||||
{
|
||||
if ($this->isOpenSourceProjectType()) {
|
||||
return true;
|
||||
}
|
||||
return count($node->consts) !== 1;
|
||||
|
||||
if (count($node->consts) !== 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @var PhpDocInfo|null $phpDocInfo */
|
||||
$phpDocInfo = $node->getAttribute(AttributeKey::PHP_DOC_INFO);
|
||||
if ($phpDocInfo === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $phpDocInfo->hasByName('api');
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DeadCode\Tests\Rector\ClassConst\RemoveUnusedClassConstantRector\Fixture;
|
||||
|
||||
class SkipApi
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
public const USED_PUBLICLY_IN_ANOTHER_PROJECT = 'publicly';
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user