Skip to content

Commit

Permalink
Updated Rector to commit 2891d15d933ec11f741a1c88139165b42987c940
Browse files Browse the repository at this point in the history
rectorphp/rector-src@2891d15 [Php84] Do not reprint node type on ExplicitNullableParamTypeRector (#6250)
  • Loading branch information
TomasVotruba committed Aug 22, 2024
1 parent 0981ded commit e2ba97a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
26 changes: 25 additions & 1 deletion rules/Php84/Rector/Param/ExplicitNullableParamTypeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
declare (strict_types=1);
namespace Rector\Php84\Rector\Param;

use PHPStan\Type\MixedType;
use PhpParser\Node;
use PhpParser\Node\ComplexType;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\IntersectionType;
use PhpParser\Node\Name;
use PhpParser\Node\NullableType;
use PhpParser\Node\Param;
use PhpParser\Node\UnionType;
use PHPStan\Type\TypeCombinator;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
Expand Down Expand Up @@ -64,8 +70,26 @@ public function refactor(Node $node) : ?Param
if (TypeCombinator::containsNull($nodeType)) {
return null;
}
// mixed can't be nullable, ref https://3v4l.org/YUkhH/rfc#vgit.master
if ($nodeType instanceof MixedType) {
return null;
}
$newNodeType = TypeCombinator::addNull($nodeType);
$node->type = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($newNodeType, TypeKind::PARAM);
$paramType = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($newNodeType, TypeKind::PARAM);
// ensure it process valid Node, otherwise, just return null
if (!$paramType instanceof Node) {
return null;
}
// re-use existing node instead of reprint Node that may cause unnecessary FQCN
if ($node->type instanceof UnionType) {
$node->type->types[] = new Name('null');
} elseif ($node->type instanceof ComplexType) {
/** @var IntersectionType $nodeType */
$nodeType = $node->type;
$node->type = new UnionType([$nodeType, new Name('null')]);
} else {
$node->type = new NullableType($node->type);
}
return $node;
}
public function provideMinPhpVersion() : int
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '05f832313c704757b3ff3925f6c0da45b5fb3cc7';
public const PACKAGE_VERSION = '2891d15d933ec11f741a1c88139165b42987c940';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-08-22 21:16:19';
public const RELEASE_DATE = '2024-08-22 23:52:43';
/**
* @var int
*/
Expand Down

0 comments on commit e2ba97a

Please sign in to comment.