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
[property-info] Detect invalid tags and throw error accordingly #36850
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -83,6 +83,10 @@ public function getShortDescription($class, $property, array $context = []) | |||||
} | ||||||
|
||||||
foreach ($docBlock->getTagsByName('var') as $var) { | ||||||
if (is_a($var, 'phpDocumentor\Reflection\DocBlock\Tags\InvalidTag')) { | ||||||
throw new \InvalidArgumentException(sprintf('Failed to get the description of the @var tag "%s" for class "%s". Please check that the @var tag is correctly defined.', $property, $class)); | ||||||
} | ||||||
|
||||||
$varDescription = $var->getDescription()->render(); | ||||||
|
||||||
if (!empty($varDescription)) { | ||||||
|
@@ -137,6 +141,10 @@ public function getTypes($class, $property, array $context = []) | |||||
$types = []; | ||||||
/** @var DocBlock\Tags\Var_|DocBlock\Tags\Return_|DocBlock\Tags\Param $tag */ | ||||||
foreach ($docBlock->getTagsByName($tag) as $tag) { | ||||||
if (is_a($tag, 'phpDocumentor\Reflection\DocBlock\Tags\InvalidTag')) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return null; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we throw here too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Throwing here would break applications with invalid docblocks. |
||||||
} | ||||||
|
||||||
if ($tag && null !== $tag->getType()) { | ||||||
$types = array_merge($types, $this->phpDocTypeHelper->getTypes($tag->getType())); | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(add the appropriate
use
too)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
InvalidTag
is introduced in v5 of phpdocumentor/reflection-docblock. A use statement would be a BC break with v3 and v4 since those are autoloaded?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no. Use statements don't imply that a class exist. And
::class
does not either (it is not an actual constant access on the class, but a compile-time thing)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha I did't know that.