Skip to content

Commit 9e917bd

Browse files
authored
[TypeDeclarationDocblocks] Skip mixed[] from empty array on ClassMethodArrayDocblockParamFromLocalCallsRector (#7349)
* [TypeDeclarationDocblocks] Skip mixed[] from empty array on ClassMethodArrayDocblockParamFromLocalCallsRector * Fix * fix
1 parent e062bee commit 9e917bd

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture;
4+
5+
final class SkipMixedFromEmptyArray
6+
{
7+
public function execute(array $data)
8+
{
9+
$data = [];
10+
$this->run($data);
11+
}
12+
13+
private function run(array $data)
14+
{
15+
}
16+
}

rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
use PhpParser\Node\VariadicPlaceholder;
1414
use PHPStan\Reflection\ReflectionProvider;
1515
use PHPStan\Type\ArrayType;
16+
use PHPStan\Type\Constant\ConstantArrayType;
1617
use PHPStan\Type\MixedType;
18+
use PHPStan\Type\NeverType;
1719
use PHPStan\Type\ObjectType;
1820
use PHPStan\Type\ThisType;
1921
use PHPStan\Type\Type;
@@ -222,14 +224,14 @@ private function isEmptyArray(Expr $expr): bool
222224

223225
private function isArrayMixedMixedType(Type $type): bool
224226
{
225-
if (! $type instanceof ArrayType) {
227+
if (! $type instanceof ArrayType && ! $type instanceof ConstantArrayType) {
226228
return false;
227229
}
228230

229-
if (! $type->getItemType() instanceof MixedType) {
231+
if (! $type->getItemType() instanceof MixedType && ! $type->getItemType() instanceof NeverType) {
230232
return false;
231233
}
232234

233-
return $type->getKeyType() instanceof MixedType;
235+
return $type->getKeyType() instanceof MixedType || $type->getKeyType() instanceof NeverType;
234236
}
235237
}

0 commit comments

Comments
 (0)