Skip to content

Commit

Permalink
[TypeDeclaration] Skip curly {@inheritdoc} on AddArrayReturnDocTypeRe…
Browse files Browse the repository at this point in the history
…ctor (#2359)
  • Loading branch information
samsonasik committed May 25, 2022
1 parent 4c53b20 commit 9c6b3d7
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 14 deletions.
17 changes: 16 additions & 1 deletion packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode;
Expand Down Expand Up @@ -443,7 +444,21 @@ public function getTemplateTagValueNodes(): array

public function hasInheritDoc(): bool
{
return $this->hasByNames(['inheritdoc', 'inheritDoc']);
if ($this->hasByNames(['inheritdoc', 'inheritDoc'])) {
return true;
}

foreach ($this->phpDocNode->children as $children) {
if (! $children instanceof PhpDocTextNode) {
continue;
}

if (in_array($children->text, ['{@inheritdoc}', '{@inheritDoc}'], true)) {
return true;
}
}

return false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector\Fixture;

use Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector\Source\ParentClassWithDefinedReturnSecond;

class SkipCurlyInheritDoc extends ParentClassWithDefinedReturnSecond
{
/**
* {@inheritdoc}
*/
public function getData()
{
return [
[
'a' => 'string',
'b' => 1,
'c' => 1.0
]
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector\Fixture;

class SkipInheritDoc extends ParentClassWithDefinedReturnSecond
use Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector\Source\ParentClassWithDefinedReturnSecond;

class SkipCurlyInheritDoc extends ParentClassWithDefinedReturnSecond
{
/**
* @inheritdoc
Expand All @@ -18,15 +20,3 @@ class SkipInheritDoc extends ParentClassWithDefinedReturnSecond
];
}
}


abstract class ParentClassWithDefinedReturnSecond
{
/**
* @return mixed[]
*/
public function getData()
{
return ['...'];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector\Source;

abstract class ParentClassWithDefinedReturnSecond
{
/**
* @return mixed[]
*/
public function getData()
{
return ['...'];
}
}

0 comments on commit 9c6b3d7

Please sign in to comment.