@@ -99,7 +99,20 @@ public static function isCallerIgnored(?string $callerClass = null, ?string $cal
9999 $ function = $ frame ['function ' ];
100100 $ file = $ frame ['file ' ] ?? '' ;
101101
102- if ($ class !== '' && (str_starts_with ($ class , 'TypePHP \\Internal \\' ) || $ class === 'TypePHP \\TypePHP ' )) {
102+ // Skip internal library frames and test runner framework internals
103+ if (
104+ $ class !== '' && (
105+ str_starts_with ($ class , 'TypePHP \\Internal \\' )
106+ || $ class === 'TypePHP \\TypePHP '
107+ || str_starts_with ($ class , 'PHPUnit \\' )
108+ || str_starts_with ($ class , 'Pest \\' )
109+ || str_starts_with ($ class , 'P \\' )
110+ )
111+ ) {
112+ continue ;
113+ }
114+
115+ if (str_starts_with ($ function , '__pest_ ' )) {
103116 continue ;
104117 }
105118
@@ -146,18 +159,37 @@ public static function isCallerIgnored(?string $callerClass = null, ?string $cal
146159 return false ;
147160 }
148161
162+ /**
163+ * Checks if a docblock contains a standalone @typephp-ignore or @typephp-disable tag.
164+ */
165+ public static function hasIgnoreDocTag (string |false |null $ doc ): bool
166+ {
167+ if ($ doc === null || $ doc === false || $ doc === '' ) {
168+ return false ;
169+ }
170+
171+ if (! str_contains ($ doc , '@typephp-ignore ' ) && ! str_contains ($ doc , '@typephp-disable ' )) {
172+ return false ;
173+ }
174+
175+ return (bool ) preg_match (
176+ '/(?:^\s*\*\s*|\/\*\*\s*|(?:\/\/|#)\s*)@(typephp-ignore|typephp-disable)(?:\s|\*\/|$)/m ' ,
177+ $ doc
178+ );
179+ }
180+
149181 private static function checkMethodIgnored (string $ class , string $ method ): bool
150182 {
151183 if (StubManager::hasMethodStub ($ class , $ method )) {
152184 $ stubDoc = StubManager::getMethodDoc ($ class , $ method );
153- if ($ stubDoc !== null && ( str_contains ( $ stubDoc, ' @typephp-ignore ' ) || str_contains ( $ stubDoc , ' @typephp-disable ' ) )) {
185+ if (self :: hasIgnoreDocTag ( $ stubDoc )) {
154186 return true ;
155187 }
156188 }
157189
158190 if (StubManager::hasClassStub ($ class )) {
159191 $ classStubDoc = StubManager::getClassDoc ($ class );
160- if ($ classStubDoc !== null && ( str_contains ( $ classStubDoc, ' @typephp-ignore ' ) || str_contains ( $ classStubDoc , ' @typephp-disable ' ) )) {
192+ if (self :: hasIgnoreDocTag ( $ classStubDoc )) {
161193 return true ;
162194 }
163195 }
@@ -172,20 +204,12 @@ private static function checkMethodIgnored(string $class, string $method): bool
172204
173205 if ($ refClass ->hasMethod ($ method )) {
174206 $ refMethod = $ refClass ->getMethod ($ method );
175- $ doc = $ refMethod ->getDocComment ();
176- if ($ doc !== false && $ doc !== null && (
177- str_contains ($ doc , '@typephp-ignore ' )
178- || str_contains ($ doc , '@typephp-disable ' )
179- )) {
207+ if (self ::hasIgnoreDocTag ($ refMethod ->getDocComment ())) {
180208 return true ;
181209 }
182210 }
183211
184- $ classDoc = $ refClass ->getDocComment ();
185- if ($ classDoc !== false && $ classDoc !== null && (
186- str_contains ($ classDoc , '@typephp-ignore ' )
187- || str_contains ($ classDoc , '@typephp-disable ' )
188- )) {
212+ if (self ::hasIgnoreDocTag ($ refClass ->getDocComment ())) {
189213 return true ;
190214 }
191215 } catch (Throwable $ e ) {
@@ -199,7 +223,7 @@ private static function checkFunctionIgnored(string $function): bool
199223 {
200224 if (StubManager::hasFunctionStub ($ function )) {
201225 $ stubDoc = StubManager::getFunctionDoc ($ function );
202- if ($ stubDoc !== null && ( str_contains ( $ stubDoc, ' @typephp-ignore ' ) || str_contains ( $ stubDoc , ' @typephp-disable ' ) )) {
226+ if (self :: hasIgnoreDocTag ( $ stubDoc )) {
203227 return true ;
204228 }
205229 }
@@ -210,11 +234,7 @@ private static function checkFunctionIgnored(string $function): bool
210234
211235 try {
212236 $ refFunc = new ReflectionFunction ($ function );
213- $ doc = $ refFunc ->getDocComment ();
214- if ($ doc !== false && $ doc !== null && (
215- str_contains ($ doc , '@typephp-ignore ' )
216- || str_contains ($ doc , '@typephp-disable ' )
217- )) {
237+ if (self ::hasIgnoreDocTag ($ refFunc ->getDocComment ())) {
218238 return true ;
219239 }
220240 } catch (Throwable $ e ) {
@@ -223,4 +243,4 @@ private static function checkFunctionIgnored(string $function): bool
223243
224244 return false ;
225245 }
226- }
246+ }
0 commit comments