mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 06:18:07 +01:00
Make DocBlockAnalyzer::getTagByName() always return a tag
This commit is contained in:
parent
fe7ab04430
commit
5337e6cf84
@ -229,11 +229,12 @@ final class MergeIsCandidateRector extends AbstractRector
|
||||
private function resolveSingleParamTypesFromClassMethod(ClassMethod $classMethod): array
|
||||
{
|
||||
// add getNodeType() by $refactorClassMethod "@param" doc type
|
||||
$paramNode = $this->docBlockAnalyzer->getTagByName($classMethod, 'param');
|
||||
if ($paramNode === null) {
|
||||
if (! $this->docBlockAnalyzer->hasTag($classMethod, 'param')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$paramNode = $this->docBlockAnalyzer->getTagByName($classMethod, 'param');
|
||||
|
||||
/** @var ParamTagValueNode $paramTagValueNode */
|
||||
$paramTagValueNode = $paramNode->value;
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\NodeTypeResolver\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
final class MissingTagException extends Exception
|
||||
{
|
||||
}
|
@ -7,6 +7,7 @@ use PhpParser\Comment\Doc;
|
||||
use PhpParser\Node;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
use Rector\NodeTypeResolver\Exception\MissingTagException;
|
||||
use Rector\PhpParser\CurrentNodeProvider;
|
||||
use Symplify\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Symplify\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
@ -149,9 +150,13 @@ final class DocBlockAnalyzer
|
||||
/**
|
||||
* @final
|
||||
*/
|
||||
public function getTagByName(Node $node, string $name): ?PhpDocTagNode
|
||||
public function getTagByName(Node $node, string $name): PhpDocTagNode
|
||||
{
|
||||
return $this->getTagsByName($node, $name)[0] ?? null;
|
||||
if (! $this->hasTag($node, $name)) {
|
||||
throw new MissingTagException('Tag "%s" was not found at "%s" node.', $name, get_class($node));
|
||||
}
|
||||
|
||||
return $this->getTagsByName($node, $name)[0];
|
||||
}
|
||||
|
||||
private function updateNodeWithPhpDocInfo(Node $node, PhpDocInfo $phpDocInfo): void
|
||||
|
Loading…
x
Reference in New Issue
Block a user