Skip to content

Commit 9c1e7bf

Browse files
committed
Fix generic-object false positive
1 parent f2b6ac2 commit 9c1e7bf

5 files changed

Lines changed: 58 additions & 1 deletion

File tree

src/Rules/NarrowPrivateClassMethodParamTypeRule.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use PHPStan\Type\MixedType;
2323
use PHPStan\Type\ObjectType;
2424
use PHPStan\Type\UnionType;
25+
use PHPStan\Type\Generic\GenericObjectType;
2526
use PHPStan\Type\VerbosityLevel;
2627
use Rector\TypePerfect\Configuration;
2728
use Rector\TypePerfect\NodeFinder\ClassMethodNodeFinder;
@@ -149,7 +150,7 @@ private function validateParam(Param $param, int $position, Expr $expr, Scope $s
149150
return null;
150151
}
151152

152-
if ($argType instanceof IntersectionType) {
153+
if ($argType instanceof IntersectionType || $argType instanceof GenericObjectType) {
153154
return null;
154155
}
155156

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Rector\TypePerfect\Tests\Rules\NarrowPrivateClassMethodParamTypeRule\Fixture;
4+
5+
6+
use Rector\TypePerfect\Tests\Rules\NarrowPrivateClassMethodParamTypeRule\Source\MyIterator;
7+
use Rector\TypePerfect\Tests\Rules\NarrowPrivateClassMethodParamTypeRule\Source\MyPreise;
8+
9+
final class SkipSameGeneric
10+
{
11+
protected function getPriceAndCalculateTableVM(): void
12+
{
13+
14+
$prices = $this->getPricesForArticle();
15+
$this->getAmounts($prices);
16+
}
17+
18+
/**
19+
* @param MyIterator<MyPreise> $prices
20+
*/
21+
private function getAmounts(MyIterator $prices): void
22+
{
23+
}
24+
25+
/**
26+
* @return MyIterator<MyPreise>
27+
*/
28+
private function getPricesForArticle(): MyIterator
29+
{
30+
/** @var MyIterator<MyPreise> */
31+
return new MyIterator();
32+
}
33+
34+
}

tests/Rules/NarrowPrivateClassMethodParamTypeRule/NarrowPrivateClassMethodParamTypeRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public static function provideData(): Iterator
5151
yield [__DIR__ . '/Fixture/SkipGenericType.php', []];
5252
yield [__DIR__ . '/Fixture/SkipAbstractBase.php', []];
5353
yield [__DIR__ . '/Fixture/SkipVariadics.php', []];
54+
yield [__DIR__ . '/Fixture/SkipSameGeneric.php', []];
5455
}
5556

5657
/**
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\TypePerfect\Tests\Rules\NarrowPrivateClassMethodParamTypeRule\Source;
6+
7+
/**
8+
* @template T
9+
*/
10+
final class MyIterator
11+
{
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\TypePerfect\Tests\Rules\NarrowPrivateClassMethodParamTypeRule\Source;
6+
7+
class MyPreise
8+
{
9+
}

0 commit comments

Comments
 (0)