Skip to content

Commit 347ef6a

Browse files
committed
Fix generic-object false positive
1 parent f2b6ac2 commit 347ef6a

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

src/Rules/NarrowPrivateClassMethodParamTypeRule.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use PHPStan\Rules\Rule;
1818
use PHPStan\Rules\RuleError;
1919
use PHPStan\Rules\RuleErrorBuilder;
20+
use PHPStan\Type\Generic\GenericObjectType;
2021
use PHPStan\Type\Generic\TemplateType;
2122
use PHPStan\Type\IntersectionType;
2223
use PHPStan\Type\MixedType;
@@ -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)