Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture;

final class RemoveNullable
{
public function go()
{
$this->run($this->getNames());
}

private function run(array $items)
{
}

/**
* @return string[]|null
*/
private function getNames(): ?array
{
return ['Jim', 'Rohn'];
}
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture;

final class RemoveNullable
{
public function go()
{
$this->run($this->getNames());
}

/**
* @param string[] $items
*/
private function run(array $items)
{
}

/**
* @return string[]|null
*/
private function getNames(): ?array
{
return ['Jim', 'Rohn'];
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\PhpParser\NodeFinder\LocalMethodCallFinder;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -112,10 +113,14 @@ public function refactor(Node $node): ?Node
if (! $resolvedParameterType instanceof Type) {
continue;
}

if ($resolvedParameterType instanceof MixedType) {
continue;
}

// in case of array type declaration, null cannot be passed or is already casted
$resolvedParameterType = TypeCombinator::removeNull($resolvedParameterType);

$hasClassMethodChanged = $this->nodeDocblockTypeDecorator->decorateGenericIterableParamType(
$resolvedParameterType,
$classMethodPhpDocInfo,
Expand Down
Loading