Skip to content

Commit

Permalink
support for PHP 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jun 18, 2024
1 parent 99976d6 commit 88d26a3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
php: ['8.0', '8.1', '8.2', '8.3']
php: ['8.0', '8.1', '8.2', '8.3', '8.4']

fail-fast: false

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
],
"require": {
"php": "8.0 - 8.3"
"php": "8.0 - 8.4"
},
"require-dev": {
"nette/tester": "^2.5",
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static function toReflection($callable): \ReflectionMethod|\ReflectionFun
}

if (is_string($callable) && str_contains($callable, '::')) {
return new ReflectionMethod($callable);
return new ReflectionMethod(...explode('::', $callable, 2));
} elseif (is_array($callable)) {
return new ReflectionMethod($callable[0], $callable[1]);
} elseif (is_object($callable) && !$callable instanceof \Closure) {
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static function getMethodDeclaringMethod(\ReflectionMethod $method): \Ref

$hash = [$method->getFileName(), $method->getStartLine(), $method->getEndLine()];
if (($alias = $decl->getTraitAliases()[$method->name] ?? null)
&& ($m = new \ReflectionMethod($alias))
&& ($m = new \ReflectionMethod(...explode('::', $alias, 2)))
&& $hash === [$m->getFileName(), $m->getStartLine(), $m->getEndLine()]
) {
return self::getMethodDeclaringMethod($m);
Expand All @@ -125,7 +125,7 @@ public static function getMethodDeclaringMethod(\ReflectionMethod $method): \Ref
public static function areCommentsAvailable(): bool
{
static $res;
return $res ?? $res = (bool) (new \ReflectionMethod(__METHOD__))->getDocComment();
return $res ?? $res = (bool) (new \ReflectionMethod(self::class, __FUNCTION__))->getDocComment();
}


Expand Down
8 changes: 4 additions & 4 deletions tests/Utils/Callback.closure.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class TestChild extends Test
function getName($ref)
{
if ($ref instanceof ReflectionFunction) {
return $ref->getName();
return $ref->getShortName();
} elseif ($ref instanceof ReflectionMethod) {
return $ref->getDeclaringClass()->getName() . '::' . $ref->getName();
}
Expand Down Expand Up @@ -121,9 +121,9 @@ test('closure', function () {
Assert::same($closure, Closure::fromCallable($closure));
Assert::same($closure, Callback::unwrap($closure));
Assert::same('{closure}', Callback::toString($closure));
Assert::same('{closure}', getName(Callback::toReflection($closure)));
Assert::same('{closure}', Closure::fromCallable($closure)(...[&$res]));
Assert::same('{closure}', $res);
Assert::match('{closure%a?%}', getName(Callback::toReflection($closure)));
Assert::match('{closure%a?%}', Closure::fromCallable($closure)(...[&$res]));
Assert::match('{closure%a?%}', $res);
});


Expand Down

0 comments on commit 88d26a3

Please sign in to comment.