Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PhpDoc] Add warning about missing PhpDocInfo name form tag value node #6134

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function narrowToFullyQualifiedOrAliasedObjectType(
if ($scope instanceof Scope) {
$namespaceName = $scope->getNamespace();
if ($namespaceName !== null) {
$newClassName = $namespaceName . '\\' .$className;
$newClassName = $namespaceName . '\\' . $className;
if ($this->reflectionProvider->hasClass($newClassName)) {
return new FullyQualifiedObjectType($newClassName);
}
Expand Down
11 changes: 10 additions & 1 deletion src/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\ExtendsTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\InvalidTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
Expand All @@ -30,6 +32,7 @@
use Rector\BetterPhpDocParser\ValueObject\Parser\BetterTokenIterator;
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
use Rector\BetterPhpDocParser\ValueObject\Type\ShortenedIdentifierTypeNode;
use Rector\Exception\ShouldNotHappenException;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
use Rector\StaticTypeMapper\StaticTypeMapper;

Expand All @@ -47,6 +50,8 @@ final class PhpDocInfo
VarTagValueNode::class => '@var',
MethodTagValueNode::class => '@method',
PropertyTagValueNode::class => '@property',
ExtendsTagValueNode::class => '@extends',
ImplementsTagValueNode::class => '@implements',
];

private bool $isSingleLine = false;
Expand Down Expand Up @@ -319,7 +324,11 @@ public function addTagValueNode(PhpDocTagValueNode $phpDocTagValueNode): void

$name = $this->resolveNameForPhpDocTagValueNode($phpDocTagValueNode);
if (! is_string($name)) {
return;
throw new ShouldNotHappenException(sprintf(
'Name could not be resolved for "%s" tag value node. Complete it to %s::TAGS_TYPES_TO_NAMES constant',
$phpDocTagValueNode::class,
self::class,
));
}

$phpDocTagNode = new PhpDocTagNode($name, $phpDocTagValueNode);
Expand Down