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,38 @@
<?php

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

class NotZeroPosition
{
public function go()
{
$this->run([], ['item1', 'item2']);
}

private function run(array $data, array $items)
{
}
}

?>
-----
<?php

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

class NotZeroPosition
{
public function go()
{
$this->run([], ['item1', 'item2']);
}

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

?>
12 changes: 4 additions & 8 deletions rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,13 @@ private function unionToSingleType(array $staticTypesByArgumentPosition): array
$staticTypeByArgumentPosition[$position] = $this->narrowParentObjectTreeToSingleObjectChildType(
$unionedType
);
}

if (count($staticTypeByArgumentPosition) !== 1) {
return $staticTypeByArgumentPosition;
}

if (! $staticTypeByArgumentPosition[0]->isNull()->yes()) {
return $staticTypeByArgumentPosition;
if ($staticTypeByArgumentPosition[$position]->isNull()->yes()) {
$staticTypeByArgumentPosition[$position] = new MixedType();
}
}

return [new MixedType()];
return $staticTypeByArgumentPosition;
}

private function narrowParentObjectTreeToSingleObjectChildType(Type $type): Type
Expand Down
Loading