Skip to content

Commit 10fe533

Browse files
committed
fix 8.2 ci failing test
1 parent 8e060b8 commit 10fe533

2 files changed

Lines changed: 46 additions & 25 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 & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)