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 Nov 4, 2024
1 parent 5affef4 commit 3151afe
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
2 changes: 2 additions & 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 All @@ -33,6 +34,7 @@ jobs:
- uses: "ramsey/composer-install@v2"
with:
dependency-versions: ${{ matrix.dependencies }}
composer-options: "--ignore-platform-reqs" # Remove when Psalm supports PHP 8.4 / @see https://github.com/vimeo/psalm/pull/10928

- name: Running unit tests
run: php vendor/bin/phpunit --testsuite=unit
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.2 use `ReflectionFunction::isAnonymous()`
$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.2 use `ReflectionFunction::isAnonymous()`
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,11 @@ public function test_function_data_can_be_retrieved(): void
$function = $this->repository->for($callback);
$parameters = $function->parameters;

self::assertSame(__NAMESPACE__ . '\{closure}', $function->name);
if (PHP_VERSION_ID < 8_04_00) {
self::assertSame(__NAMESPACE__ . '\{closure}', $function->name);
} else {
self::assertSame('{closure:' . self::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 3151afe

Please sign in to comment.