Skip to content

Commit

Permalink
PhpDocParser: support phpstan and psalm prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JanTvrdik committed Oct 6, 2019
1 parent b3040ad commit b23fbb1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 25 deletions.
48 changes: 24 additions & 24 deletions src/Ast/PhpDoc/PhpDocNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public function getTagsByName(string $tagName): array
/**
* @return VarTagValueNode[]
*/
public function getVarTagValues(): array
public function getVarTagValues(string $tagName = '@var'): array
{
return array_column(
array_filter($this->getTagsByName('@var'), static function (PhpDocTagNode $tag): bool {
array_filter($this->getTagsByName($tagName), static function (PhpDocTagNode $tag): bool {
return $tag->value instanceof VarTagValueNode;
}),
'value'
Expand All @@ -59,10 +59,10 @@ public function getVarTagValues(): array
/**
* @return ParamTagValueNode[]
*/
public function getParamTagValues(): array
public function getParamTagValues(string $tagName = '@param'): array
{
return array_column(
array_filter($this->getTagsByName('@param'), static function (PhpDocTagNode $tag): bool {
array_filter($this->getTagsByName($tagName), static function (PhpDocTagNode $tag): bool {
return $tag->value instanceof ParamTagValueNode;
}),
'value'
Expand All @@ -73,10 +73,10 @@ public function getParamTagValues(): array
/**
* @return TemplateTagValueNode[]
*/
public function getTemplateTagValues(): array
public function getTemplateTagValues(string $tagName = '@template'): array
{
return array_column(
array_filter($this->getTagsByName('@template'), static function (PhpDocTagNode $tag): bool {
array_filter($this->getTagsByName($tagName), static function (PhpDocTagNode $tag): bool {
return $tag->value instanceof TemplateTagValueNode;
}),
'value'
Expand All @@ -87,10 +87,10 @@ public function getTemplateTagValues(): array
/**
* @return ExtendsTagValueNode[]
*/
public function getExtendsTagValues(): array
public function getExtendsTagValues(string $tagName = '@extends'): array
{
return array_column(
array_filter($this->getTagsByName('@extends'), static function (PhpDocTagNode $tag): bool {
array_filter($this->getTagsByName($tagName), static function (PhpDocTagNode $tag): bool {
return $tag->value instanceof ExtendsTagValueNode;
}),
'value'
Expand All @@ -101,10 +101,10 @@ public function getExtendsTagValues(): array
/**
* @return ImplementsTagValueNode[]
*/
public function getImplementsTagValues(): array
public function getImplementsTagValues(string $tagName = '@implements'): array
{
return array_column(
array_filter($this->getTagsByName('@implements'), static function (PhpDocTagNode $tag): bool {
array_filter($this->getTagsByName($tagName), static function (PhpDocTagNode $tag): bool {
return $tag->value instanceof ImplementsTagValueNode;
}),
'value'
Expand All @@ -115,10 +115,10 @@ public function getImplementsTagValues(): array
/**
* @return UsesTagValueNode[]
*/
public function getUsesTagValues(): array
public function getUsesTagValues(string $tagName = '@uses'): array
{
return array_column(
array_filter($this->getTagsByName('@uses'), static function (PhpDocTagNode $tag): bool {
array_filter($this->getTagsByName($tagName), static function (PhpDocTagNode $tag): bool {
return $tag->value instanceof UsesTagValueNode;
}),
'value'
Expand All @@ -129,10 +129,10 @@ public function getUsesTagValues(): array
/**
* @return ReturnTagValueNode[]
*/
public function getReturnTagValues(): array
public function getReturnTagValues(string $tagName = '@return'): array
{
return array_column(
array_filter($this->getTagsByName('@return'), static function (PhpDocTagNode $tag): bool {
array_filter($this->getTagsByName($tagName), static function (PhpDocTagNode $tag): bool {
return $tag->value instanceof ReturnTagValueNode;
}),
'value'
Expand All @@ -143,10 +143,10 @@ public function getReturnTagValues(): array
/**
* @return ThrowsTagValueNode[]
*/
public function getThrowsTagValues(): array
public function getThrowsTagValues(string $tagName = '@throws'): array
{
return array_column(
array_filter($this->getTagsByName('@throws'), static function (PhpDocTagNode $tag): bool {
array_filter($this->getTagsByName($tagName), static function (PhpDocTagNode $tag): bool {
return $tag->value instanceof ThrowsTagValueNode;
}),
'value'
Expand All @@ -171,10 +171,10 @@ public function getDeprecatedTagValues(): array
/**
* @return PropertyTagValueNode[]
*/
public function getPropertyTagValues(): array
public function getPropertyTagValues(string $tagName = '@property'): array
{
return array_column(
array_filter($this->getTagsByName('@property'), static function (PhpDocTagNode $tag): bool {
array_filter($this->getTagsByName($tagName), static function (PhpDocTagNode $tag): bool {
return $tag->value instanceof PropertyTagValueNode;
}),
'value'
Expand All @@ -185,10 +185,10 @@ public function getPropertyTagValues(): array
/**
* @return PropertyTagValueNode[]
*/
public function getPropertyReadTagValues(): array
public function getPropertyReadTagValues(string $tagName = '@property-read'): array
{
return array_column(
array_filter($this->getTagsByName('@property-read'), static function (PhpDocTagNode $tag): bool {
array_filter($this->getTagsByName($tagName), static function (PhpDocTagNode $tag): bool {
return $tag->value instanceof PropertyTagValueNode;
}),
'value'
Expand All @@ -199,10 +199,10 @@ public function getPropertyReadTagValues(): array
/**
* @return PropertyTagValueNode[]
*/
public function getPropertyWriteTagValues(): array
public function getPropertyWriteTagValues(string $tagName = '@property-write'): array
{
return array_column(
array_filter($this->getTagsByName('@property-write'), static function (PhpDocTagNode $tag): bool {
array_filter($this->getTagsByName($tagName), static function (PhpDocTagNode $tag): bool {
return $tag->value instanceof PropertyTagValueNode;
}),
'value'
Expand All @@ -213,10 +213,10 @@ public function getPropertyWriteTagValues(): array
/**
* @return MethodTagValueNode[]
*/
public function getMethodTagValues(): array
public function getMethodTagValues(string $tagName = '@method'): array
{
return array_column(
array_filter($this->getTagsByName('@method'), static function (PhpDocTagNode $tag): bool {
array_filter($this->getTagsByName($tagName), static function (PhpDocTagNode $tag): bool {
return $tag->value instanceof MethodTagValueNode;
}),
'value'
Expand Down
30 changes: 29 additions & 1 deletion src/Parser/PhpDocParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,20 @@ public function parseTagValue(TokenIterator $tokens, string $tag): Ast\PhpDoc\Ph

switch ($tag) {
case '@param':
case '@phpstan-param':
case '@psalm-param':
$tagValue = $this->parseParamTagValue($tokens);
break;

case '@var':
case '@phpstan-var':
case '@psalm-var':
$tagValue = $this->parseVarTagValue($tokens);
break;

case '@return':
case '@phpstan-return':
case '@psalm-return':
$tagValue = $this->parseReturnTagValue($tokens);
break;

Expand All @@ -137,21 +143,43 @@ public function parseTagValue(TokenIterator $tokens, string $tag): Ast\PhpDoc\Ph
case '@property':
case '@property-read':
case '@property-write':
case '@phpstan-property':
case '@phpstan-property-read':
case '@phpstan-property-write':
case '@psalm-property':
case '@psalm-property-read':
case '@psalm-property-write':
$tagValue = $this->parsePropertyTagValue($tokens);
break;

case '@method':
case '@phpstan-method':
case '@psalm-method':
$tagValue = $this->parseMethodTagValue($tokens);
break;

case '@template':
case '@phpstan-template':
case '@psalm-template':
$tagValue = $this->parseTemplateTagValue($tokens);
break;

case '@extends':
case '@phpstan-extends':
case '@template-extends':
$tagValue = $this->parseExtendsTagValue('@extends', $tokens);
break;

case '@implements':
case '@phpstan-implements':
case '@template-implements':
$tagValue = $this->parseExtendsTagValue('@implements', $tokens);
break;

case '@uses':
$tagValue = $this->parseExtendsTagValue($tag, $tokens);
case '@phpstan-uses':
case '@template-use':
$tagValue = $this->parseExtendsTagValue('@uses', $tokens);
break;

default:
Expand Down

0 comments on commit b23fbb1

Please sign in to comment.