Skip to content

Commit

Permalink
feat: add support for PHP 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
romm committed Oct 12, 2024
1 parent 6e68d6f commit d853458
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
- "8.1"
- "8.2"
- "8.3"
- "8.4"

env:
php-extensions: ds,yaml
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.1.0 || ~8.2.0 || ~8.3.0",
"php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0",
"composer-runtime-api": "^2.0",
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0"
},
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use function array_map;
use function str_ends_with;
use function str_starts_with;

/** @internal */
final class ReflectionFunctionDefinitionRepository implements FunctionDefinitionRepository
Expand Down Expand Up @@ -57,7 +58,8 @@ public function for(callable $function): FunctionDefinition
$class = $reflection->getClosureScopeClass();
$returnType = $returnTypeResolver->resolveReturnTypeFor($reflection);
$nativeReturnType = $returnTypeResolver->resolveNativeReturnTypeFor($reflection);
$isClosure = $name === '{closure}' || str_ends_with($name, '\\{closure}');
// PHP8.4 Only `str_starts_with($name, '{closure:')` is needed
$isClosure = $name === '{closure}' || str_ends_with($name, '\\{closure}') || str_starts_with($name, '{closure:');

if ($returnType instanceof UnresolvableType) {
$returnType = $returnType->forFunctionReturnType($signature);
Expand All @@ -83,7 +85,8 @@ public function for(callable $function): FunctionDefinition
*/
private function signature(ReflectionFunction $reflection): string
{
if (str_contains($reflection->name, '{closure}')) {
// PHP8.4 Only `str_starts_with($name, '{closure:')` is needed
if ($reflection->name === '{closure}' || str_ends_with($reflection->name, '\\{closure}') || str_starts_with($reflection->name, '{closure:')) {
$startLine = $reflection->getStartLine();
$endLine = $reflection->getEndLine();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function test_function_data_can_be_retrieved(): void
$function = $this->repository->for($callback);
$parameters = $function->parameters;

self::assertSame(__NAMESPACE__ . '\{closure}', $function->name);
self::assertSame('{closure:' . __CLASS__ . '::' . __FUNCTION__ . '():37}', $function->name);
self::assertInstanceOf(NativeStringType::class, $function->returnType);

self::assertTrue($parameters->has('foo'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static function native_type_is_resolved_properly_data_provider(): iterabl
}

// PHP8.2 move to data provider
#[RequiresPhp('8.2')]
#[RequiresPhp('>=8.2')]
public function test_disjunctive_normal_form_type_is_resolved_properly(): void
{
$reflectionType = (new ReflectionProperty(ObjectWithPropertyWithNativeDisjunctiveNormalFormType::class, 'someProperty'))->getType();
Expand All @@ -109,7 +109,7 @@ public function test_disjunctive_normal_form_type_is_resolved_properly(): void
}

// PHP8.2 move to data provider
#[RequiresPhp('8.2')]
#[RequiresPhp('>=8.2')]
public function test_native_null_type_is_resolved_properly(): void
{
$reflectionType = (new ReflectionProperty(ObjectWithPropertyWithNativePhp82StandaloneTypes::class, 'nativeNull'))->getType();
Expand All @@ -120,7 +120,7 @@ public function test_native_null_type_is_resolved_properly(): void
}

// PHP8.2 move to data provider
#[RequiresPhp('8.2')]
#[RequiresPhp('>=8.2')]
public function test_native_true_type_is_resolved_properly(): void
{
$reflectionType = (new ReflectionProperty(ObjectWithPropertyWithNativePhp82StandaloneTypes::class, 'nativeTrue'))->getType();
Expand All @@ -131,7 +131,7 @@ public function test_native_true_type_is_resolved_properly(): void
}

// PHP8.2 move to data provider
#[RequiresPhp('8.2')]
#[RequiresPhp('>=8.2')]
public function test_native_false_type_is_resolved_properly(): void
{
$reflectionType = (new ReflectionProperty(ObjectWithPropertyWithNativePhp82StandaloneTypes::class, 'nativeFalse'))->getType();
Expand Down

0 comments on commit d853458

Please sign in to comment.