-
-
Notifications
You must be signed in to change notification settings - Fork 742
Closed
rectorphp/rector-src
#6961Labels
Description
Bug Report
| Subject | Details |
|---|---|
| Rector version | last dev-main |
| Installed as | composer dependency |
Minimal PHP Code Causing Issue
See https://getrector.com/demo/8690845d-21e2-4d05-af11-f515b4cf890f
<?php
class FilterAssert
{
public static function boolean(callable $filter): void
{
switch ($filter) {
case $filter instanceof Closure:
$reflection = new ReflectionFunction($filter);
break;
case is_object($filter):
$reflection = new ReflectionMethod($filter, '__invoke');
break;
default:
throw new InvalidArgumentException(
sprintf('Expected Closure or invokable object on callable filter, %s given', gettype($filter))
);
}
var_dump($reflection->getReturnType());
}
}
$filter = new class {
public function __invoke(int $datum): bool
{
return $datum === 1;
}
};
FilterAssert::boolean($filter);Responsible rules
ChangeSwitchToMatchRector
Expected Behavior
This should use match(true):
- return match ($filter) {
+ return match (true) {The current behaviour cause different result, see
- using switch: https://3v4l.org/j3urp (working)
- using rector generate to match: https://3v4l.org/1rD46 (fallback to default which throw exception)
- using
match(true): https://3v4l.org/aE6Wc (working)
Reactions are currently unavailable