mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 13:28:18 +01:00
[Downgrade PHP 7.2] Cover nullable param in DowngradeParameterTypeWideningRector (#6225)
This commit is contained in:
parent
cf58d68f6a
commit
aa2c142038
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\DowngradePhp72\Rector\Class_\DowngradeParameterTypeWideningRector\Fixture;
|
||||
|
||||
interface SomeAskingInterfaceWithNullable
|
||||
{
|
||||
public function ask(?callable $callable = null);
|
||||
}
|
||||
|
||||
final class AskForMore implements SomeAskingInterfaceWithNullable
|
||||
{
|
||||
public function ask($callable = null)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\DowngradePhp72\Rector\Class_\DowngradeParameterTypeWideningRector\Fixture;
|
||||
|
||||
interface SomeAskingInterfaceWithNullable
|
||||
{
|
||||
/**
|
||||
* @param callable|null $callable
|
||||
*/
|
||||
public function ask($callable = null);
|
||||
}
|
||||
|
||||
final class AskForMore implements SomeAskingInterfaceWithNullable
|
||||
{
|
||||
public function ask($callable = null)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -7,6 +7,7 @@ namespace Rector\DowngradePhp72\PhpDoc;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\TypeCombinator;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
|
||||
@ -67,7 +68,9 @@ final class NativeParamToPhpDocDecorator
|
||||
$mappedCurrentParamType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->type);
|
||||
|
||||
// add default null type
|
||||
if ($param->default !== null && $this->valueResolver->isNull($param->default)) {
|
||||
if ($param->default !== null && $this->valueResolver->isNull($param->default) && ! TypeCombinator::containsNull(
|
||||
$mappedCurrentParamType
|
||||
)) {
|
||||
$mappedCurrentParamType = new UnionType([$mappedCurrentParamType, new NullType()]);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user