Skip to content

Commit

Permalink
Test match on class const fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
klimick committed May 4, 2023
1 parent ac8d489 commit a18eb44
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public static function analyze(
$stmt->cond->getAttributes(),
);
}
} elseif ($stmt->cond instanceof PhpParser\Node\Expr\ClassConstFetch
&& $stmt->cond->name instanceof PhpParser\Node\Identifier
&& $stmt->cond->name->toString() === 'class'
) {
// do nothing
} elseif ($stmt->cond instanceof PhpParser\Node\Expr\ConstFetch
&& $stmt->cond->name->toString() === 'true'
) {
Expand Down
20 changes: 20 additions & 0 deletions tests/MatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,26 @@ function bar(mixed $foo): int {
'ignored_issues' => [],
'php_version' => '8.0',
],
'matchOnConstClassFetch' => [
'code' => '<?php
final class Obj1 {
public string $propFromObj1 = "str";
}
final class Obj2 {
public int $propFromObj2 = 42;
}
function process(Obj1|Obj2 $obj): int|string
{
return match ($obj::class) {
Obj1::class => $obj->propFromObj1,
Obj2::class => $obj->propFromObj2,
};
}',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.0',
],
];
}

Expand Down

0 comments on commit a18eb44

Please sign in to comment.