Skip to content

Commit b231885

Browse files
committed
debugged and fix ingnore tag bug where it eagerly skip a file that has a string for typephp ignore tags whch is not in the docblocks
1 parent 768197f commit b231885

2 files changed

Lines changed: 46 additions & 45 deletions

File tree

‎src/Internal/Docblock/DocblockParser.php‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use TypePHP\Internal\Resolver\SpecialTypeResolver;
2929
use TypePHP\Internal\Util\Config;
3030
use TypePHP\Internal\Util\FileFilter;
31+
use TypePHP\Internal\Util\IgnoreManager;
3132
use TypePHP\Internal\Util\StubManager;
3233
use TypePHP\Internal\Validator\TypeValidatorRegistry;
3334

@@ -764,7 +765,7 @@ private static function extractRawParamName(object $paramNode): string
764765

765766
private static function shouldIgnoreDoc(string $doc): bool
766767
{
767-
return Config::isRespectIgnoreTagsEnabled() && (str_contains($doc, '@typephp-ignore') || str_contains($doc, '@typephp-disable'));
768+
return Config::isRespectIgnoreTagsEnabled() && IgnoreManager::hasIgnoreDocTag($doc);
768769
}
769770

770771
/**
@@ -1626,7 +1627,7 @@ public static function substituteAliases(TypeNode $node, array $aliases): TypeNo
16261627

16271628
if ($node instanceof CallableTypeNode) {
16281629
$parameters = array_map(
1629-
fn (CallableTypeParameterNode $param) => new CallableTypeParameterNode(
1630+
fn(CallableTypeParameterNode $param) => new CallableTypeParameterNode(
16301631
self::substituteAliases($param->type, $aliases),
16311632
$param->isReference,
16321633
$param->isVariadic,
@@ -1660,7 +1661,7 @@ public static function substituteAliases(TypeNode $node, array $aliases): TypeNo
16601661
if ($node instanceof GenericTypeNode) {
16611662
$genericType = self::substituteAliases($node->type, $aliases);
16621663
$genericTypes = array_map(
1663-
fn ($t) => self::substituteAliases($t, $aliases),
1664+
fn($t) => self::substituteAliases($t, $aliases),
16641665
$node->genericTypes
16651666
);
16661667

@@ -1677,7 +1678,7 @@ public static function substituteAliases(TypeNode $node, array $aliases): TypeNo
16771678

16781679
if ($node instanceof UnionTypeNode) {
16791680
$types = array_map(
1680-
fn ($t) => self::substituteAliases($t, $aliases),
1681+
fn($t) => self::substituteAliases($t, $aliases),
16811682
$node->types
16821683
);
16831684

@@ -1692,7 +1693,7 @@ public static function substituteAliases(TypeNode $node, array $aliases): TypeNo
16921693

16931694
if ($node instanceof IntersectionTypeNode) {
16941695
$types = array_map(
1695-
fn ($t) => self::substituteAliases($t, $aliases),
1696+
fn($t) => self::substituteAliases($t, $aliases),
16961697
$node->types
16971698
);
16981699

‎src/Internal/Util/IgnoreManager.php‎

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public static function isFileIgnored(string $filePath): bool
7070
public static function isCallerIgnored(?string $callerClass = null, ?string $callerFunction = null): bool
7171
{
7272
if (! Config::isRespectIgnoreTagsEnabled()) {
73-
fwrite(STDERR, "[DEBUG IgnoreManager] respect_ignore_tags is disabled.\n");
7473
return false;
7574
}
7675

@@ -94,89 +93,102 @@ public static function isCallerIgnored(?string $callerClass = null, ?string $cal
9493
$depth = Config::getIgnoreTraceDepth();
9594
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $depth);
9695

97-
fwrite(STDERR, "\n=======================================================\n");
98-
fwrite(STDERR, " [DEBUG IgnoreManager] Scanning trace (depth limit: {$depth}, actual frames: " . \count($trace) . ")\n");
99-
fwrite(STDERR, "=======================================================\n");
100-
10196
for ($i = 1; $i < \count($trace); $i++) {
10297
$frame = $trace[$i];
10398
$class = $frame['class'] ?? '';
10499
$function = $frame['function'];
105100
$file = $frame['file'] ?? '';
106-
$line = $frame['line'] ?? '?';
107101

108-
fwrite(STDERR, " #{$i} {$class}::{$function}() called at [{$file}:{$line}]\n");
102+
if (
103+
$class !== '' && (
104+
str_starts_with($class, 'TypePHP\\Internal\\')
105+
|| $class === 'TypePHP\\TypePHP'
106+
|| str_starts_with($class, 'PHPUnit\\')
107+
|| str_starts_with($class, 'Pest\\')
108+
|| str_starts_with($class, 'P\\')
109+
)
110+
) {
111+
continue;
112+
}
109113

110-
if ($class !== '' && (str_starts_with($class, 'TypePHP\\Internal\\') || $class === 'TypePHP\\TypePHP')) {
111-
fwrite(STDERR, " -> skipped (internal engine frame)\n");
114+
if (str_starts_with($function, '__pest_')) {
112115
continue;
113116
}
114117

115118
if ($class === '' && \in_array($function, ['call_user_func', 'call_user_func_array'], true)) {
116-
fwrite(STDERR, " -> skipped (call_user_func trampoline)\n");
117119
continue;
118120
}
119121

120-
if ($file !== '') {
121-
$fileIsIgnored = self::isFileIgnored($file);
122-
if ($fileIsIgnored) {
123-
fwrite(STDERR, " => [SUPPRESSED] File is registered in fileCache: {$file}\n");
124-
return true;
125-
}
122+
if ($file !== '' && self::isFileIgnored($file)) {
123+
return true;
126124
}
127125

128126
if ($class !== '') {
129127
$key = $class . '::' . $function;
130128
if (isset(self::$callerCache[$key])) {
131129
if (self::$callerCache[$key]) {
132-
fwrite(STDERR, " => [SUPPRESSED] Found cached ignored method: {$key}\n");
133130
return true;
134131
}
135132

136133
continue;
137134
}
138135

139136
if (self::checkMethodIgnored($class, $function)) {
140-
fwrite(STDERR, " => [SUPPRESSED] checkMethodIgnored returned TRUE for: {$key}\n");
141137
return self::$callerCache[$key] = true;
142138
}
143139

144140
self::$callerCache[$key] = false;
145141
} elseif (! str_contains($function, '{closure}')) {
146142
if (isset(self::$callerCache[$function])) {
147143
if (self::$callerCache[$function]) {
148-
fwrite(STDERR, " => [SUPPRESSED] Found cached ignored function: {$function}\n");
149144
return true;
150145
}
151146

152147
continue;
153148
}
154149

155150
if (self::checkFunctionIgnored($function)) {
156-
fwrite(STDERR, " => [SUPPRESSED] checkFunctionIgnored returned TRUE for: {$function}\n");
157151
return self::$callerCache[$function] = true;
158152
}
159153

160154
self::$callerCache[$function] = false;
161155
}
162156
}
163157

164-
fwrite(STDERR, " => [NOT SUPPRESSED] No ignore tags found in scanned frames.\n\n");
165158
return false;
166159
}
167160

161+
/**
162+
* Checks if a docblock contains a standalone @typephp-ignore or @typephp-disable tag.
163+
*/
164+
public static function hasIgnoreDocTag(string|false|null $doc): bool
165+
{
166+
if ($doc === null || $doc === false || $doc === '') {
167+
return false;
168+
}
169+
170+
if (! str_contains($doc, '@typephp-ignore') && ! str_contains($doc, '@typephp-disable')) {
171+
return false;
172+
}
173+
174+
return (bool) preg_match(
175+
'/(?:^\s*\*\s*|\/\*\*\s*|(?:\/\/|#)\s*)@(typephp-ignore|typephp-disable)(?:\s|\*\/|$)/m',
176+
$doc
177+
);
178+
}
179+
168180
private static function checkMethodIgnored(string $class, string $method): bool
169181
{
170182
if (StubManager::hasMethodStub($class, $method)) {
171183
$stubDoc = StubManager::getMethodDoc($class, $method);
172-
if ($stubDoc !== null && (str_contains($stubDoc, '@typephp-ignore') || str_contains($stubDoc, '@typephp-disable'))) {
184+
if (self::hasIgnoreDocTag($stubDoc)) {
173185
return true;
174186
}
175187
}
176188

177189
if (StubManager::hasClassStub($class)) {
178190
$classStubDoc = StubManager::getClassDoc($class);
179-
if ($classStubDoc !== null && (str_contains($classStubDoc, '@typephp-ignore') || str_contains($classStubDoc, '@typephp-disable'))) {
191+
if (self::hasIgnoreDocTag($classStubDoc)) {
180192
return true;
181193
}
182194
}
@@ -191,20 +203,12 @@ private static function checkMethodIgnored(string $class, string $method): bool
191203

192204
if ($refClass->hasMethod($method)) {
193205
$refMethod = $refClass->getMethod($method);
194-
$doc = $refMethod->getDocComment();
195-
if ($doc !== false && $doc !== null && (
196-
str_contains($doc, '@typephp-ignore')
197-
|| str_contains($doc, '@typephp-disable')
198-
)) {
206+
if (self::hasIgnoreDocTag($refMethod->getDocComment())) {
199207
return true;
200208
}
201209
}
202210

203-
$classDoc = $refClass->getDocComment();
204-
if ($classDoc !== false && $classDoc !== null && (
205-
str_contains($classDoc, '@typephp-ignore')
206-
|| str_contains($classDoc, '@typephp-disable')
207-
)) {
211+
if (self::hasIgnoreDocTag($refClass->getDocComment())) {
208212
return true;
209213
}
210214
} catch (Throwable $e) {
@@ -218,7 +222,7 @@ private static function checkFunctionIgnored(string $function): bool
218222
{
219223
if (StubManager::hasFunctionStub($function)) {
220224
$stubDoc = StubManager::getFunctionDoc($function);
221-
if ($stubDoc !== null && (str_contains($stubDoc, '@typephp-ignore') || str_contains($stubDoc, '@typephp-disable'))) {
225+
if (self::hasIgnoreDocTag($stubDoc)) {
222226
return true;
223227
}
224228
}
@@ -229,11 +233,7 @@ private static function checkFunctionIgnored(string $function): bool
229233

230234
try {
231235
$refFunc = new ReflectionFunction($function);
232-
$doc = $refFunc->getDocComment();
233-
if ($doc !== false && $doc !== null && (
234-
str_contains($doc, '@typephp-ignore')
235-
|| str_contains($doc, '@typephp-disable')
236-
)) {
236+
if (self::hasIgnoreDocTag($refFunc->getDocComment())) {
237237
return true;
238238
}
239239
} catch (Throwable $e) {
@@ -242,4 +242,4 @@ private static function checkFunctionIgnored(string $function): bool
242242

243243
return false;
244244
}
245-
}
245+
}

0 commit comments

Comments
 (0)