[TypeDeclaration] Skip curly {@inheritdoc} on AddArrayReturnDocTypeRector (#2359)

This commit is contained in:
Abdul Malik Ikhsan 2022-05-25 14:26:56 +07:00 committed by GitHub
parent 4c53b206a4
commit 9c6b3d708c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 14 deletions

View File

@ -12,6 +12,7 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocChildNode;
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;
@ -443,7 +444,21 @@ final class PhpDocInfo
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;
}
/**

View File

@ -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
]
];
}
}

View File

@ -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
@ -18,15 +20,3 @@ class SkipInheritDoc extends ParentClassWithDefinedReturnSecond
];
}
}
abstract class ParentClassWithDefinedReturnSecond
{
/**
* @return mixed[]
*/
public function getData()
{
return ['...'];
}
}

View File

@ -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 ['...'];
}
}