Skip to content

Commit

Permalink
added more type validity checks to reduce possible false positives
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Jun 13, 2022
1 parent c7e39e7 commit 507e792
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions tests/Internal/Codebase/InternalCallMapHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public function callMapEntryProvider(): iterable
if (strpos($function, '::') !== false) {
continue;
}
// Skip alternate signatures
if (preg_match("/\'\d$/", $function)) {
// Skip functions with alternate signatures
if (isset($callMap["$function\'1"]) || preg_match("/\'\d$/", $function)) {
continue;
}
if ($this->skipUndefinedFunctions && !function_exists($function)) {
Expand Down Expand Up @@ -181,18 +181,34 @@ private function assertTypeValidity(ReflectionNamedType $reflected, string $spec
{
// Trim leading namespace separator
$specified = ltrim($specified, "\\");
if ($reflected->getName() === 'array' && preg_match('/^array<.*>$/', $specified)) {
if ($reflected->getName() === 'array' && preg_match('/^(array|list)<.*>$/', $specified)) {
return;
}
if ($reflected->getName() === 'float' && $specified === 'int|float') {
return;
}
if ($reflected->getName() === 'bool' && in_array($specified, ['true', 'false'])) {
return;
}
if ($reflected->getName() === 'callable' && preg_match('/^callable\(/', $specified)) {
return;
}

if ($reflected->getName() === 'string' && $specified === '?string' && $reflected->allowsNull()) {
return;
}
if ($reflected->getName() === 'string' && in_array($specified , ['class-string', 'numeric-string', 'string'])) {
return;
}
if ($reflected->getName() === 'int' && in_array($specified , ['positive-int', 'int'])) {
return;
}

if ($reflected->allowsNull()) {
$this->assertMatchesRegularExpression("/^\?{$reflected->getName()}|{$reflected->getName()}\|null|null\|{$reflected->getName()}/", $specified, $message);
return;
}

$this->assertSame($reflected->getName(), $specified, $message);
$this->assertEqualsIgnoringCase($reflected->getName(), $specified, $message);
}
}

0 comments on commit 507e792

Please sign in to comment.