[TypeDeclaration] Skip ParamTypeDeclarationRector on interface with extends (#5292)

* Add failing test fixture for ParamTypeDeclarationRector

# Failing Test for ParamTypeDeclarationRector

Based on https://getrector.org/demo/56b352cf-6ba5-4fd5-8186-dd071d1e4010

* Fix namespace position

* Update rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/vat_rate.php.inc

Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com>

* Update rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/vat_rate.php.inc

Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com>

* Update interfaces' names

* Rename vat_rate.php.inc to skip_different_with_interface.php.inc

* Close #5274 Fixes #5270

* cs fix

Co-authored-by: Adamo Crespi <hello@aerendir.me>
This commit is contained in:
Abdul Malik Ikhsan 2021-01-23 18:38:30 +07:00 committed by GitHub
parent d08f63fb1b
commit 8cd6dbea3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View File

@ -9,11 +9,13 @@ use PhpParser\Node\FunctionLike;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Interface_;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeWithClassName;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
use Rector\TypeDeclaration\ChildPopulator\ChildParamPopulator;
@ -176,6 +178,11 @@ CODE_SAMPLE
return;
}
$parentNode = $functionLike->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode instanceof Interface_ && $parentNode->extends !== []) {
return;
}
$param->type = $paramTypeNode;
$this->childParamPopulator->populateChildClassMethod($functionLike, $position, $inferedType);
}

View File

@ -0,0 +1,29 @@
<?php
namespace Rector\TypeDeclaration\Tests\Rector\FunctionLike\ParamTypeDeclarationRector\Fixture;
interface ParentInterface
{
/**
* @param float|int|string $value
*/
public function __construct($value);
}
interface IntermediateInterface extends ParentInterface
{
/**
* @param string $countryCode
*/
public function __construct($countryCode);
}
final class SkipInterfaceExtends implements IntermediateInterface
{
/**
* @param string $countryCode
*/
public function __construct($countryCode)
{
}
}
?>