Skip to content

Commit 10a2b24

Browse files
committed
Fix
1 parent 9878bb1 commit 10a2b24

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

conf/config.neon

+1
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ services:
758758
checkMissingIterableValueType: %checkMissingIterableValueType%
759759
checkGenericClassInNonGenericObjectType: %checkGenericClassInNonGenericObjectType%
760760
checkMissingCallableSignature: %checkMissingCallableSignature%
761+
skipCheckGenericClasses: %featureToggles.skipCheckGenericClasses%
761762

762763
-
763764
class: PHPStan\Rules\NullsafeCheck

src/Rules/MissingTypehintCheck.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,25 @@ class MissingTypehintCheck
3535

3636
private bool $checkMissingCallableSignature;
3737

38+
/** @var string[] */
39+
private array $skipCheckGenericClasses;
40+
41+
/**
42+
* @param string[] $skipCheckGenericClasses
43+
*/
3844
public function __construct(
3945
ReflectionProvider $reflectionProvider,
4046
bool $checkMissingIterableValueType,
4147
bool $checkGenericClassInNonGenericObjectType,
42-
bool $checkMissingCallableSignature
48+
bool $checkMissingCallableSignature,
49+
array $skipCheckGenericClasses = []
4350
)
4451
{
4552
$this->reflectionProvider = $reflectionProvider;
4653
$this->checkMissingIterableValueType = $checkMissingIterableValueType;
4754
$this->checkGenericClassInNonGenericObjectType = $checkGenericClassInNonGenericObjectType;
4855
$this->checkMissingCallableSignature = $checkMissingCallableSignature;
56+
$this->skipCheckGenericClasses = $skipCheckGenericClasses;
4957
}
5058

5159
/**
@@ -97,7 +105,7 @@ public function getNonGenericObjectTypesWithGenericClass(Type $type): array
97105
}
98106

99107
$objectTypes = [];
100-
TypeTraverser::map($type, static function (Type $type, callable $traverse) use (&$objectTypes): Type {
108+
TypeTraverser::map($type, function (Type $type, callable $traverse) use (&$objectTypes): Type {
101109
if ($type instanceof GenericObjectType) {
102110
$traverse($type);
103111
return $type;
@@ -114,6 +122,9 @@ public function getNonGenericObjectTypesWithGenericClass(Type $type): array
114122
// checked by getIterableTypesWithMissingValueTypehint() already
115123
return $type;
116124
}
125+
if (in_array($classReflection->getName(), $this->skipCheckGenericClasses, true)) {
126+
return $type;
127+
}
117128
if ($classReflection->isTrait()) {
118129
return $type;
119130
}

0 commit comments

Comments
 (0)