1515use TypePHP \Internal \Docblock \DocblockParser ;
1616use TypePHP \Internal \Generics \TemplateManager ;
1717use TypePHP \Internal \Util \Config ;
18+ use TypePHP \Internal \Util \IgnoreManager ;
1819use TypePHP \Internal \Validator \TypeValidatorRegistry ;
1920use TypePHP \Internal \Wrapper \CallableWrapper ;
2021use TypePHP \Internal \Wrapper \IterableWrapper ;
@@ -26,6 +27,20 @@ final class RuntimeTypeChecker
2627{
2728 private static ?TypeValidatorRegistry $ registry = null ;
2829
30+ /**
31+ * @var array<string, bool>
32+ */
33+ private static array $ hasMethodTemplatesCache = [];
34+
35+ /**
36+ * Resets runtime caches.
37+ */
38+ public static function reset (): void
39+ {
40+ self ::$ hasMethodTemplatesCache = [];
41+ IgnoreManager ::reset ();
42+ }
43+
2944 /**
3045 * Returns whether TypePHP is globally enabled in configuration.
3146 */
@@ -43,7 +58,13 @@ public static function bindInstanceFromNode(object $instance, GenericTypeNode $t
4358 return null ;
4459 }
4560
46- return TemplateManager ::bindInstanceFromNode ($ instance , $ typeNode , $ context , $ forceBind );
61+ $ err = TemplateManager ::bindInstanceFromNode ($ instance , $ typeNode , $ context , $ forceBind );
62+
63+ if ($ err !== null && IgnoreManager ::isCallerIgnored ()) {
64+ return null ;
65+ }
66+
67+ return $ err ;
4768 }
4869
4970 /**
@@ -61,7 +82,7 @@ public static function checkVariable(
6182 return $ value ;
6283 }
6384
64- return InlineChecker ::checkVariable (
85+ $ res = InlineChecker ::checkVariable (
6586 $ value ,
6687 $ typeString ,
6788 $ varName ,
@@ -70,6 +91,12 @@ public static function checkVariable(
7091 $ caller ,
7192 $ thisOrClass
7293 );
94+
95+ if ($ res instanceof ErrorMessage && IgnoreManager ::isCallerIgnored ()) {
96+ return $ value ;
97+ }
98+
99+ return $ res ;
73100 }
74101
75102 /**
@@ -86,13 +113,14 @@ public static function checkProperty(mixed $value, mixed $objectOrClass, string
86113 return $ value ;
87114 }
88115
89- return InlineChecker ::checkProperty ($ value , $ objectOrClass , $ propName , $ file , self ::getRegistry ());
90- }
116+ $ res = InlineChecker ::checkProperty ($ value , $ objectOrClass , $ propName , $ file , self ::getRegistry ());
91117
92- /**
93- * @var array<string, bool>
94- */
95- private static array $ hasMethodTemplatesCache = [];
118+ if ($ res instanceof ErrorMessage && IgnoreManager ::isCallerIgnored ()) {
119+ return $ value ;
120+ }
121+
122+ return $ res ;
123+ }
96124
97125 /**
98126 * Initialises generic call frames and returns a ScopeCleaner that pops the call frame on destruction.
@@ -123,6 +151,10 @@ public static function setupScope(string $function, array $vars, object|string|n
123151 $ err = ParamChecker ::checkParams ($ function , $ vars , $ thisOrClass , self ::getRegistry (), $ effectiveFunction );
124152
125153 if ($ err !== null ) {
154+ if (IgnoreManager ::isCallerIgnored ()) {
155+ return null ;
156+ }
157+
126158 TemplateManager ::popCallFrame ($ effectiveFunction );
127159
128160 return $ err ;
@@ -151,7 +183,13 @@ public static function checkParams(string $function, array $vars, object|string|
151183 return null ;
152184 }
153185
154- return ParamChecker ::checkParams ($ function , $ vars , $ thisOrClass , self ::getRegistry ());
186+ $ err = ParamChecker ::checkParams ($ function , $ vars , $ thisOrClass , self ::getRegistry ());
187+
188+ if ($ err !== null && IgnoreManager ::isCallerIgnored ()) {
189+ return null ;
190+ }
191+
192+ return $ err ;
155193 }
156194
157195 /**
@@ -172,14 +210,19 @@ public static function checkReturn(string $function, mixed $value, object|string
172210 $ thisObj = \is_object ($ thisOrClass ) ? $ thisOrClass : null ;
173211 $ effectiveFunction = ParamChecker ::resolveEffectiveFunction ($ function , $ thisOrClass , $ thisObj );
174212
175- // Fast-path: if return type is unconstrained, skip validation.
176213 if (ReturnChecker ::isReturnUnconstrained ($ effectiveFunction )) {
177214 return $ value ;
178215 }
179216
180217 $ vars ??= [];
181218
182- return ReturnChecker ::checkReturn ($ function , $ value , $ thisOrClass , $ vars , self ::getRegistry (), [self ::class, 'wrapIterable ' ]);
219+ $ res = ReturnChecker ::checkReturn ($ function , $ value , $ thisOrClass , $ vars , self ::getRegistry (), [self ::class, 'wrapIterable ' ]);
220+
221+ if ($ res instanceof ErrorMessage && IgnoreManager ::isCallerIgnored ()) {
222+ return $ value ;
223+ }
224+
225+ return $ res ;
183226 }
184227
185228 /**
@@ -191,7 +234,13 @@ public static function checkSend(string $function, mixed $sendValue, object|stri
191234 return $ sendValue ;
192235 }
193236
194- return GeneratorChecker ::checkSend ($ function , $ sendValue , self ::getRegistry (), $ thisOrClass );
237+ $ res = GeneratorChecker ::checkSend ($ function , $ sendValue , self ::getRegistry (), $ thisOrClass );
238+
239+ if ($ res instanceof ErrorMessage && IgnoreManager ::isCallerIgnored ()) {
240+ return $ sendValue ;
241+ }
242+
243+ return $ res ;
195244 }
196245
197246 /**
@@ -203,7 +252,13 @@ public static function checkYield(string $function, mixed $key, mixed $value, ob
203252 return $ value ;
204253 }
205254
206- return GeneratorChecker ::checkYield ($ function , $ key , $ value , self ::getRegistry (), $ thisOrClass );
255+ $ res = GeneratorChecker ::checkYield ($ function , $ key , $ value , self ::getRegistry (), $ thisOrClass );
256+
257+ if ($ res instanceof ErrorMessage && IgnoreManager ::isCallerIgnored ()) {
258+ return $ value ;
259+ }
260+
261+ return $ res ;
207262 }
208263
209264 /**
0 commit comments