Skip to content

Commit 3db92ed

Browse files
committed
remove accessor array list type
1 parent 55758e3 commit 3db92ed

4 files changed

Lines changed: 93 additions & 4 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector\FixtureIntersection;
6+
7+
final class CoverIntersection
8+
{
9+
public function run(array $values): void
10+
{
11+
$items = [];
12+
13+
foreach ($values as $value) {
14+
$items[] = 10;
15+
}
16+
17+
$this->nextItems($items);
18+
}
19+
20+
private function nextItems($items): void
21+
{
22+
}
23+
}
24+
25+
?>

rules-tests/TypeDeclaration/Rector/ClassMethod/AddMethodCallBasedStrictParamTypeRector/Fixture/cover_intersection.php.inc renamed to rules-tests/TypeDeclaration/Rector/ClassMethod/AddMethodCallBasedStrictParamTypeRector/FixtureIntersection/cover_intersection.php.inc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
declare(strict_types=1);
44

5-
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector\Fixture;
5+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector\FixtureIntersection;
66

77
final class CoverIntersection
88
{
99
public function run(array $values): void
1010
{
11-
/** @var int[] $items */
1211
$items = [];
1312

1413
foreach ($values as $value) {
@@ -29,13 +28,12 @@ final class CoverIntersection
2928

3029
declare(strict_types=1);
3130

32-
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector\Fixture;
31+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector\FixtureIntersection;
3332

3433
final class CoverIntersection
3534
{
3635
public function run(array $values): void
3736
{
38-
/** @var int[] $items */
3937
$items = [];
4038

4139
foreach ($values as $value) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector\FixtureIntersection;
6+
7+
final class CoverIntersectionWithDocblock
8+
{
9+
public function run(array $values): void
10+
{
11+
/** @var int[] $items */
12+
$items = [];
13+
14+
foreach ($values as $value) {
15+
$items[] = 10;
16+
}
17+
18+
$this->nextItems($items);
19+
}
20+
21+
private function nextItems($items): void
22+
{
23+
}
24+
}
25+
26+
?>
27+
-----
28+
<?php
29+
30+
declare(strict_types=1);
31+
32+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector\FixtureIntersection;
33+
34+
final class CoverIntersectionWithDocblock
35+
{
36+
public function run(array $values): void
37+
{
38+
/** @var int[] $items */
39+
$items = [];
40+
41+
foreach ($values as $value) {
42+
$items[] = 10;
43+
}
44+
45+
$this->nextItems($items);
46+
}
47+
48+
private function nextItems(array $items): void
49+
{
50+
}
51+
}
52+
53+
?>

rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@
1212
use PhpParser\Node\Identifier;
1313
use PhpParser\Node\VariadicPlaceholder;
1414
use PHPStan\Reflection\ReflectionProvider;
15+
use PHPStan\Type\Accessory\AccessoryArrayListType;
1516
use PHPStan\Type\ArrayType;
1617
use PHPStan\Type\Constant\ConstantArrayType;
18+
use PHPStan\Type\IntersectionType;
1719
use PHPStan\Type\MixedType;
1820
use PHPStan\Type\NeverType;
1921
use PHPStan\Type\ObjectType;
2022
use PHPStan\Type\ThisType;
2123
use PHPStan\Type\Type;
24+
use PHPStan\Type\TypeCombinator;
25+
use PHPStan\Type\TypeUtils;
2226
use PHPStan\Type\UnionType;
2327
use Rector\NodeTypeResolver\NodeTypeResolver;
2428
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
@@ -90,6 +94,15 @@ private function resolveStrictArgValueType(Arg $arg): Type
9094
{
9195
$argValueType = $this->nodeTypeResolver->getNativeType($arg->value);
9296

97+
if ($argValueType instanceof IntersectionType) {
98+
dump($argValueType);
99+
100+
$argValueType = TypeCombinator::remove($argValueType, new AccessoryArrayListType());
101+
102+
dump($argValueType);
103+
die;
104+
}
105+
93106
return $this->normalizeType($argValueType);
94107
}
95108

0 commit comments

Comments
 (0)