11
11
use PHPStan \Analyser \TypeSpecifierContext ;
12
12
use PHPStan \Reflection \MethodReflection ;
13
13
use PHPStan \TrinaryLogic ;
14
+ use PHPStan \Type \Constant \ConstantArrayType ;
14
15
use PHPStan \Type \Php \RegexArrayShapeMatcher ;
15
16
use PHPStan \Type \StaticMethodTypeSpecifyingExtension ;
17
+ use PHPStan \Type \TypeCombinator ;
18
+ use PHPStan \Type \Type ;
16
19
17
20
final class PregMatchTypeSpecifyingExtension implements StaticMethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
18
21
{
@@ -43,7 +46,7 @@ public function getClass(): string
43
46
44
47
public function isStaticMethodSupported (MethodReflection $ methodReflection , StaticCall $ node , TypeSpecifierContext $ context ): bool
45
48
{
46
- return in_array ($ methodReflection ->getName (), ['match ' , 'isMatch ' ], true ) && !$ context ->null ();
49
+ return in_array ($ methodReflection ->getName (), ['match ' , 'isMatch ' , ' matchStrictGroups ' , ' isMatchStrictGroups ' ], true ) && !$ context ->null ();
47
50
}
48
51
49
52
public function specifyTypes (MethodReflection $ methodReflection , StaticCall $ node , Scope $ scope , TypeSpecifierContext $ context ): SpecifiedTypes
@@ -70,6 +73,22 @@ public function specifyTypes(MethodReflection $methodReflection, StaticCall $nod
70
73
return new SpecifiedTypes ();
71
74
}
72
75
76
+ if (
77
+ in_array ($ methodReflection ->getName (), ['matchStrictGroups ' , 'isMatchStrictGroups ' ], true )
78
+ && count ($ matchedType ->getConstantArrays ()) > 0
79
+ ) {
80
+ $ matchedType = $ matchedType ->getConstantArrays ()[0 ];
81
+ $ matchedType = new ConstantArrayType (
82
+ $ matchedType ->getKeyTypes (),
83
+ array_map (static function (Type $ valueType ): Type {
84
+ return TypeCombinator::removeNull ($ valueType );
85
+ }, $ matchedType ->getValueTypes ()),
86
+ [0 ],
87
+ [],
88
+ $ matchedType ->isList ()
89
+ );
90
+ }
91
+
73
92
$ overwrite = false ;
74
93
if ($ context ->false ()) {
75
94
$ overwrite = true ;
0 commit comments