Skip to content

Commit 6733224

Browse files
committedJun 18, 2024
support for PHP 8.4
1 parent 99976d6 commit 6733224

File tree

7 files changed

+14
-11
lines changed

7 files changed

+14
-11
lines changed
 

‎.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
matrix:
1010
os: [ubuntu-latest, windows-latest]
11-
php: ['8.0', '8.1', '8.2', '8.3']
11+
php: ['8.0', '8.1', '8.2', '8.3', '8.4']
1212

1313
fail-fast: false
1414

‎composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
],
1717
"require": {
18-
"php": "8.0 - 8.3"
18+
"php": "8.0 - 8.4"
1919
},
2020
"require-dev": {
2121
"nette/tester": "^2.5",

‎readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ The recommended way to install is via Composer:
4141
composer require nette/utils
4242
```
4343

44-
Nette Utils 4.0 is compatible with PHP 8.0 to 8.3.
44+
Nette Utils 4.0 is compatible with PHP 8.0 to 8.4.
4545

4646
 <!---->
4747

‎src/Utils/Callback.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static function toReflection($callable): \ReflectionMethod|\ReflectionFun
9494
}
9595

9696
if (is_string($callable) && str_contains($callable, '::')) {
97-
return new ReflectionMethod($callable);
97+
return new ReflectionMethod(...explode('::', $callable, 2));
9898
} elseif (is_array($callable)) {
9999
return new ReflectionMethod($callable[0], $callable[1]);
100100
} elseif (is_object($callable) && !$callable instanceof \Closure) {

‎src/Utils/Reflection.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static function getMethodDeclaringMethod(\ReflectionMethod $method): \Ref
100100

101101
$hash = [$method->getFileName(), $method->getStartLine(), $method->getEndLine()];
102102
if (($alias = $decl->getTraitAliases()[$method->name] ?? null)
103-
&& ($m = new \ReflectionMethod($alias))
103+
&& ($m = new \ReflectionMethod(...explode('::', $alias, 2)))
104104
&& $hash === [$m->getFileName(), $m->getStartLine(), $m->getEndLine()]
105105
) {
106106
return self::getMethodDeclaringMethod($m);
@@ -125,7 +125,7 @@ public static function getMethodDeclaringMethod(\ReflectionMethod $method): \Ref
125125
public static function areCommentsAvailable(): bool
126126
{
127127
static $res;
128-
return $res ?? $res = (bool) (new \ReflectionMethod(__METHOD__))->getDocComment();
128+
return $res ?? $res = (bool) (new \ReflectionMethod(self::class, __FUNCTION__))->getDocComment();
129129
}
130130

131131

@@ -136,7 +136,9 @@ public static function toString(\Reflector $ref): string
136136
} elseif ($ref instanceof \ReflectionMethod) {
137137
return $ref->getDeclaringClass()->name . '::' . $ref->name . '()';
138138
} elseif ($ref instanceof \ReflectionFunction) {
139-
return $ref->name . '()';
139+
return PHP_VERSION_ID >= 80200 && $ref->isAnonymous()
140+
? '{closure}()'
141+
: $ref->name . '()';
140142
} elseif ($ref instanceof \ReflectionProperty) {
141143
return self::getPropertyDeclaringClass($ref)->name . '::$' . $ref->name;
142144
} elseif ($ref instanceof \ReflectionParameter) {

‎tests/Utils/Callback.closure.phpt

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class TestChild extends Test
8787
function getName($ref)
8888
{
8989
if ($ref instanceof ReflectionFunction) {
90-
return $ref->getName();
90+
return $ref->getShortName();
9191
} elseif ($ref instanceof ReflectionMethod) {
9292
return $ref->getDeclaringClass()->getName() . '::' . $ref->getName();
9393
}
@@ -121,9 +121,9 @@ test('closure', function () {
121121
Assert::same($closure, Closure::fromCallable($closure));
122122
Assert::same($closure, Callback::unwrap($closure));
123123
Assert::same('{closure}', Callback::toString($closure));
124-
Assert::same('{closure}', getName(Callback::toReflection($closure)));
125-
Assert::same('{closure}', Closure::fromCallable($closure)(...[&$res]));
126-
Assert::same('{closure}', $res);
124+
Assert::match('{closure%a?%}', getName(Callback::toReflection($closure)));
125+
Assert::match('{closure%a?%}', Closure::fromCallable($closure)(...[&$res]));
126+
Assert::match('{closure%a?%}', $res);
127127
});
128128

129129

‎tests/Utils/Reflection.toString.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ Assert::same('$param in Foo::method()', Reflection::toString(new ReflectionParam
3434
Assert::same('Foo::$var', Reflection::toString(new ReflectionProperty('Foo', 'var')));
3535
Assert::same('func()', Reflection::toString(new ReflectionFunction('func')));
3636
Assert::same('$param in func()', Reflection::toString(new ReflectionParameter('func', 'param')));
37+
Assert::same('$param in {closure}()', Reflection::toString((new ReflectionFunction(function($param){}))->getParameters()[0]));

0 commit comments

Comments
 (0)
Failed to load comments.