"DocBlock" -> add "getTagsWithTypeByName()"

-> because I saw errors like this ```Call to undefined method phpDocumentor\Reflection\DocBlock\Tags\InvalidTag::getType()```

-> https://github.com/Roave/BetterReflection/blob/5b4d1c53768e2a3bc32ab348752663733fd70546/src/TypesFinder/FindReturnType.php#L53
This commit is contained in:
Lars Moelleken
2020-10-24 10:27:35 +02:00
parent 069a785b21
commit 8c3953ef86
2 changed files with 46 additions and 0 deletions
+22
View File
@@ -14,6 +14,7 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\Tags\TagWithType;
use Webmozart\Assert\Assert;
final class DocBlock
@@ -161,6 +162,27 @@ final class DocBlock
return $result;
}
/**
* Returns an array of tags with type matching the given name. If no tags are found
* an empty array is returned.
*
* @param string $name String to search by.
*
* @return TagWithType[]
*/
public function getTagsWithTypeByName(string $name) : array
{
$result = [];
foreach ($this->getTagsByName($name) as $tag) {
if ($tag instanceof TagWithType) {
$result[] = $tag;
}
}
return $result;
}
/**
* Checks if a tag of a certain type is present in this DocBlock.
*