Skip to content

Commit

Permalink
[DowngradePhp71] Using exact same type on PhpDocFromTypeDeclarationDe…
Browse files Browse the repository at this point in the history
…corator (#770)
  • Loading branch information
samsonasik committed Aug 26, 2021
1 parent 2665992 commit f39c01e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function decorateParamWithSpecificType(
return;
}

if (! $this->isTypeMatchOrSubType($param->type, $requireType)) {
if (! $this->isTypeMatch($param->type, $requireType)) {
return;
}

Expand All @@ -90,23 +90,24 @@ public function decorateReturnWithSpecificType(
return false;
}

if (! $this->isTypeMatchOrSubType($functionLike->returnType, $requireType)) {
if (! $this->isTypeMatch($functionLike->returnType, $requireType)) {
return false;
}

$this->decorate($functionLike);
return true;
}

private function isTypeMatchOrSubType(Node $typeNode, Type $requireType): bool
private function isTypeMatch(Node $typeNode, Type $requireType): bool
{
$returnType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($typeNode);

// cover nullable union types
if ($returnType instanceof UnionType) {
$returnType = $this->typeUnwrapper->unwrapNullableType($returnType);
}
return is_a($returnType, $requireType::class, true);

return $returnType::class === $requireType::class;
}

private function moveParamTypeToParamDoc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Rector\DowngradePhp80\Rector\ClassMethod;

use PhpParser\Node;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ReflectionProvider;
Expand Down Expand Up @@ -73,10 +72,6 @@ public function getStatic()
*/
public function refactor(Node $node): ?Node
{
if ($node->returnType instanceof Name && $this->nodeNameResolver->isNames($node->returnType, ['self', 'parent'])) {
return null;
}

$scope = $node->getAttribute(AttributeKey::SCOPE);
if ($scope === null) {
$className = $node->getAttribute(AttributeKey::CLASS_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use PhpParser\Node;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PHPStan\Type\MixedType;
Expand Down Expand Up @@ -70,10 +69,6 @@ public function someFunction($anything)
*/
public function refactor(Node $node): ?Node
{
if ($node->returnType instanceof Name && $this->nodeNameResolver->isName($node->returnType, 'parent')) {
return null;
}

$mixedType = new MixedType();

foreach ($node->getParams() as $param) {
Expand Down

0 comments on commit f39c01e

Please sign in to comment.