diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7d4a39ca..63b08279 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,6 @@ jobs: - "highest" - "locked" php-version: - - "8.0" - "8.1" - "8.2" - "8.3" diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index c3d50380..9d3ed573 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -9,12 +9,8 @@ ->notPath('Fixtures/FunctionWithSeveralImportStatementsInSameUseStatement.php') ->notPath('Fixtures/TwoClassesInDifferentNamespaces.php'); -if (PHP_VERSION_ID < 8_01_00) { - $finder = $finder->notPath('Fixture/Enum/PureEnum.php'); - $finder = $finder->notPath('Fixture/Enum/BackedStringEnum.php'); - $finder = $finder->notPath('Fixture/Enum/BackedIntegerEnum.php'); - $finder = $finder->notPath('Fixture/Object/ObjectWithPropertyWithNativeIntersectionType.php'); - $finder = $finder->notPath('Integration/Mapping/Fixture/ReadonlyValues.php'); +if (PHP_VERSION_ID < 8_02_00) { + $finder = $finder->notPath('Fixture/Object/ObjectWithPropertyWithNativeDisjunctiveNormalFormType.php'); } return (new PhpCsFixer\Config()) diff --git a/composer.json b/composer.json index e1d6b495..7ccd420c 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": "~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0", + "php": "~8.1.0 || ~8.2.0 || ~8.3.0", "composer-runtime-api": "^2.0", "psr/simple-cache": "^1.0 || ^2.0 || ^3.0" }, diff --git a/composer.lock b/composer.lock index 2c1085cb..e410c323 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fda5dc65899699cea7642eeac392c32b", + "content-hash": "5b0a5c1021fd69730e81eb8d561ed9fa", "packages": [ { "name": "psr/simple-cache", @@ -5824,9 +5824,9 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0", + "php": "~8.1.0 || ~8.2.0 || ~8.3.0", "composer-runtime-api": "^2.0" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/rector.php b/rector.php index 50777186..96e45509 100644 --- a/rector.php +++ b/rector.php @@ -4,11 +4,12 @@ use Rector\Caching\ValueObject\Storage\FileCacheStorage; use Rector\Config\RectorConfig; -use Rector\Core\Configuration\Option; use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector; use Rector\Php74\Rector\Property\RestoreDefaultNullToNullableTypePropertyRector; use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; use Rector\Php80\Rector\FunctionLike\MixedTypeRector; +use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; +use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; use Rector\Set\ValueObject\LevelSetList; return static function (RectorConfig $config): void { @@ -18,22 +19,26 @@ __DIR__ . '/tests', ]); - $config->parameters()->set(Option::CACHE_DIR, './var/cache/rector'); + $config->cacheDirectory(__DIR__ . '/var/cache/rector'); // @see https://github.com/rectorphp/rector/issues/7341 - $config->parameters()->set(Option::CACHE_CLASS, FileCacheStorage::class); + $config->cacheClass(FileCacheStorage::class); $config->sets([ - LevelSetList::UP_TO_PHP_80, + LevelSetList::UP_TO_PHP_81, ]); $config->parallel(); $config->skip([ AddLiteralSeparatorToNumberRector::class, ClassPropertyAssignToConstructorPromotionRector::class, + ReadOnlyPropertyRector::class, MixedTypeRector::class => [ __DIR__ . '/tests/Unit/Definition/Repository/Reflection/ReflectionClassDefinitionRepositoryTest', ], + NullToStrictStringFuncCallArgRector::class => [ + __DIR__ . '/tests/Traits/TestIsSingleton.php', + ], RestoreDefaultNullToNullableTypePropertyRector::class => [ __DIR__ . '/tests/Integration/Mapping/Other/FlexibleCastingMappingTest.php', __DIR__ . '/tests/Integration/Mapping/SingleNodeMappingTest', diff --git a/src/Cache/FileWatchingCache.php b/src/Cache/FileWatchingCache.php index 417762bb..2ec5fb52 100644 --- a/src/Cache/FileWatchingCache.php +++ b/src/Cache/FileWatchingCache.php @@ -125,7 +125,7 @@ private function saveTimestamps(string $key, mixed $value): void $fileNames = []; if ($value instanceof ClassDefinition) { - $reflection = Reflection::class($value->name()); + $reflection = Reflection::class($value->name); do { $fileNames[] = $reflection->getFileName(); @@ -133,7 +133,7 @@ private function saveTimestamps(string $key, mixed $value): void } if ($value instanceof FunctionDefinition) { - $fileNames[] = $value->fileName(); + $fileNames[] = $value->fileName; } foreach ($fileNames as $fileName) { diff --git a/src/Cache/Warmup/RecursiveCacheWarmupService.php b/src/Cache/Warmup/RecursiveCacheWarmupService.php index 4648fc68..568ec4ef 100644 --- a/src/Cache/Warmup/RecursiveCacheWarmupService.php +++ b/src/Cache/Warmup/RecursiveCacheWarmupService.php @@ -82,10 +82,10 @@ private function warmupInterfaceType(InterfaceType $type): void $function = $this->implementations->function($interfaceName); - $this->warmupType($function->returnType()); + $this->warmupType($function->returnType); - foreach ($function->parameters() as $parameter) { - $this->warmupType($parameter->type()); + foreach ($function->parameters as $parameter) { + $this->warmupType($parameter->type); } } diff --git a/src/Definition/AttributeDefinition.php b/src/Definition/AttributeDefinition.php index e8a1400e..1780935b 100644 --- a/src/Definition/AttributeDefinition.php +++ b/src/Definition/AttributeDefinition.php @@ -8,26 +8,13 @@ final class AttributeDefinition { public function __construct( - private ClassDefinition $class, + public readonly ClassDefinition $class, /** @var list */ - private array $arguments, + public readonly array $arguments, ) {} - public function class(): ClassDefinition - { - return $this->class; - } - - /** - * @return list - */ - public function arguments(): array - { - return $this->arguments; - } - public function instantiate(): object { - return new ($this->class->type()->className())(...$this->arguments); + return new ($this->class->type->className())(...$this->arguments); } } diff --git a/src/Definition/Attributes.php b/src/Definition/Attributes.php index 0c1ff476..7cda965f 100644 --- a/src/Definition/Attributes.php +++ b/src/Definition/Attributes.php @@ -40,7 +40,7 @@ public static function empty(): self public function has(string $className): bool { foreach ($this->attributes as $attribute) { - if (is_a($attribute->class()->type()->className(), $className, true)) { + if (is_a($attribute->class->type->className(), $className, true)) { return true; } } diff --git a/src/Definition/ClassDefinition.php b/src/Definition/ClassDefinition.php index 74b11d49..8d821cca 100644 --- a/src/Definition/ClassDefinition.php +++ b/src/Definition/ClassDefinition.php @@ -10,49 +10,13 @@ final class ClassDefinition { public function __construct( - private ClassType $type, - private Attributes $attributes, - private Properties $properties, - private Methods $methods, - private bool $isFinal, - private bool $isAbstract, + /** @var class-string */ + public readonly string $name, + public readonly ClassType $type, + public readonly Attributes $attributes, + public readonly Properties $properties, + public readonly Methods $methods, + public readonly bool $isFinal, + public readonly bool $isAbstract, ) {} - - /** - * @return class-string - */ - public function name(): string - { - return $this->type->className(); - } - - public function type(): ClassType - { - return $this->type; - } - - public function attributes(): Attributes - { - return $this->attributes; - } - - public function properties(): Properties - { - return $this->properties; - } - - public function methods(): Methods - { - return $this->methods; - } - - public function isFinal(): bool - { - return $this->isFinal; - } - - public function isAbstract(): bool - { - return $this->isAbstract; - } } diff --git a/src/Definition/FunctionDefinition.php b/src/Definition/FunctionDefinition.php index 77b6ddfb..0a93526d 100644 --- a/src/Definition/FunctionDefinition.php +++ b/src/Definition/FunctionDefinition.php @@ -10,63 +10,15 @@ final class FunctionDefinition { public function __construct( - private string $name, - private string $signature, - private Attributes $attributes, - private ?string $fileName, + public readonly string $name, + public readonly string $signature, + public readonly Attributes $attributes, + public readonly ?string $fileName, /** @var class-string|null */ - private ?string $class, - private bool $isStatic, - private bool $isClosure, - private Parameters $parameters, - private Type $returnType + public readonly ?string $class, + public readonly bool $isStatic, + public readonly bool $isClosure, + public readonly Parameters $parameters, + public readonly Type $returnType ) {} - - public function name(): string - { - return $this->name; - } - - public function signature(): string - { - return $this->signature; - } - - public function attributes(): Attributes - { - return $this->attributes; - } - - public function fileName(): ?string - { - return $this->fileName; - } - - /** - * @return class-string|null - */ - public function class(): ?string - { - return $this->class; - } - - public function isStatic(): bool - { - return $this->isStatic; - } - - public function isClosure(): bool - { - return $this->isClosure; - } - - public function parameters(): Parameters - { - return $this->parameters; - } - - public function returnType(): Type - { - return $this->returnType; - } } diff --git a/src/Definition/FunctionObject.php b/src/Definition/FunctionObject.php index 59b811cd..e3777d04 100644 --- a/src/Definition/FunctionObject.php +++ b/src/Definition/FunctionObject.php @@ -7,24 +7,14 @@ /** @internal */ final class FunctionObject { - private FunctionDefinition $definition; + public readonly FunctionDefinition $definition; /** @var callable */ - private $callback; + public readonly mixed $callback; public function __construct(FunctionDefinition $definition, callable $callback) { $this->definition = $definition; $this->callback = $callback; } - - public function definition(): FunctionDefinition - { - return $this->definition; - } - - public function callback(): callable - { - return $this->callback; - } } diff --git a/src/Definition/MethodDefinition.php b/src/Definition/MethodDefinition.php index a04e8928..ee991351 100644 --- a/src/Definition/MethodDefinition.php +++ b/src/Definition/MethodDefinition.php @@ -10,41 +10,11 @@ final class MethodDefinition { public function __construct( - private string $name, - private string $signature, - private Parameters $parameters, - private bool $isStatic, - private bool $isPublic, - private Type $returnType + public readonly string $name, + public readonly string $signature, + public readonly Parameters $parameters, + public readonly bool $isStatic, + public readonly bool $isPublic, + public readonly Type $returnType ) {} - - public function name(): string - { - return $this->name; - } - - public function signature(): string - { - return $this->signature; - } - - public function parameters(): Parameters - { - return $this->parameters; - } - - public function isStatic(): bool - { - return $this->isStatic; - } - - public function isPublic(): bool - { - return $this->isPublic; - } - - public function returnType(): Type - { - return $this->returnType; - } } diff --git a/src/Definition/Methods.php b/src/Definition/Methods.php index 4c348660..b572c2e5 100644 --- a/src/Definition/Methods.php +++ b/src/Definition/Methods.php @@ -21,7 +21,7 @@ final class Methods implements IteratorAggregate, Countable public function __construct(MethodDefinition ...$methods) { foreach ($methods as $method) { - $this->methods[$method->name()] = $method; + $this->methods[$method->name] = $method; } } diff --git a/src/Definition/ParameterDefinition.php b/src/Definition/ParameterDefinition.php index 6ea27a6c..77c72005 100644 --- a/src/Definition/ParameterDefinition.php +++ b/src/Definition/ParameterDefinition.php @@ -10,47 +10,12 @@ final class ParameterDefinition { public function __construct( - private string $name, - private string $signature, - private Type $type, - private bool $isOptional, - private bool $isVariadic, - private mixed $defaultValue, - private Attributes $attributes + public readonly string $name, + public readonly string $signature, + public readonly Type $type, + public readonly bool $isOptional, + public readonly bool $isVariadic, + public readonly mixed $defaultValue, + public readonly Attributes $attributes ) {} - - public function name(): string - { - return $this->name; - } - - public function signature(): string - { - return $this->signature; - } - - public function type(): Type - { - return $this->type; - } - - public function isOptional(): bool - { - return $this->isOptional; - } - - public function isVariadic(): bool - { - return $this->isVariadic; - } - - public function defaultValue(): mixed - { - return $this->defaultValue; - } - - public function attributes(): Attributes - { - return $this->attributes; - } } diff --git a/src/Definition/Parameters.php b/src/Definition/Parameters.php index 7177a0b3..c659b5be 100644 --- a/src/Definition/Parameters.php +++ b/src/Definition/Parameters.php @@ -23,7 +23,7 @@ final class Parameters implements IteratorAggregate, Countable public function __construct(ParameterDefinition ...$parameters) { foreach ($parameters as $parameter) { - $this->parameters[$parameter->name()] = $parameter; + $this->parameters[$parameter->name] = $parameter; } } diff --git a/src/Definition/Properties.php b/src/Definition/Properties.php index f15c6b3b..5472cfca 100644 --- a/src/Definition/Properties.php +++ b/src/Definition/Properties.php @@ -21,7 +21,7 @@ final class Properties implements IteratorAggregate, Countable public function __construct(PropertyDefinition ...$properties) { foreach ($properties as $property) { - $this->properties[$property->name()] = $property; + $this->properties[$property->name] = $property; } } diff --git a/src/Definition/PropertyDefinition.php b/src/Definition/PropertyDefinition.php index ac0aaaee..99ef349b 100644 --- a/src/Definition/PropertyDefinition.php +++ b/src/Definition/PropertyDefinition.php @@ -10,47 +10,12 @@ final class PropertyDefinition { public function __construct( - private string $name, - private string $signature, - private Type $type, - private bool $hasDefaultValue, - private mixed $defaultValue, - private bool $isPublic, - private Attributes $attributes + public readonly string $name, + public readonly string $signature, + public readonly Type $type, + public readonly bool $hasDefaultValue, + public readonly mixed $defaultValue, + public readonly bool $isPublic, + public readonly Attributes $attributes ) {} - - public function name(): string - { - return $this->name; - } - - public function signature(): string - { - return $this->signature; - } - - public function type(): Type - { - return $this->type; - } - - public function hasDefaultValue(): bool - { - return $this->hasDefaultValue; - } - - public function defaultValue(): mixed - { - return $this->defaultValue; - } - - public function isPublic(): bool - { - return $this->isPublic; - } - - public function attributes(): Attributes - { - return $this->attributes; - } } diff --git a/src/Definition/Repository/Cache/Compiler/AttributesCompiler.php b/src/Definition/Repository/Cache/Compiler/AttributesCompiler.php index 8f09ba7a..990c2620 100644 --- a/src/Definition/Repository/Cache/Compiler/AttributesCompiler.php +++ b/src/Definition/Repository/Cache/Compiler/AttributesCompiler.php @@ -35,8 +35,8 @@ private function compileAttributes(Attributes $attributes): string $attributesListCode = []; foreach ($attributes as $attribute) { - $class = $this->classDefinitionCompiler->compile($attribute->class()); - $arguments = $this->compileAttributeArguments($attribute->arguments()); + $class = $this->classDefinitionCompiler->compile($attribute->class); + $arguments = $this->compileAttributeArguments($attribute->arguments); $attributesListCode[] = <<typeCompiler->compile($value->type()); + $name = var_export($value->name, true); + $type = $this->typeCompiler->compile($value->type); $properties = array_map( fn (PropertyDefinition $property) => $this->propertyCompiler->compile($property), - iterator_to_array($value->properties()) + iterator_to_array($value->properties) ); $properties = implode(', ', $properties); $methods = array_map( fn (MethodDefinition $method) => $this->methodCompiler->compile($method), - iterator_to_array($value->methods()) + iterator_to_array($value->methods) ); $methods = implode(', ', $methods); - $attributes = $this->attributesCompiler->compile($value->attributes()); + $attributes = $this->attributesCompiler->compile($value->attributes); - $isFinal = var_export($value->isFinal(), true); - $isAbstract = var_export($value->isAbstract(), true); + $isFinal = var_export($value->isFinal, true); + $isAbstract = var_export($value->isAbstract, true); return << $this->parameterCompiler->compile($parameter), - iterator_to_array($value->parameters()) + iterator_to_array($value->parameters) ); - $attributes = $this->attributesCompiler->compile($value->attributes()); - $fileName = var_export($value->fileName(), true); - $class = var_export($value->class(), true); - $isStatic = var_export($value->isStatic(), true); - $isClosure = var_export($value->isClosure(), true); + $attributes = $this->attributesCompiler->compile($value->attributes); + $fileName = var_export($value->fileName, true); + $class = var_export($value->class, true); + $isStatic = var_export($value->isStatic, true); + $isClosure = var_export($value->isClosure, true); $parameters = implode(', ', $parameters); - $returnType = $this->typeCompiler->compile($value->returnType()); + $returnType = $this->typeCompiler->compile($value->returnType); return <<name()}', - '{$value->signature()}', + '{$value->name}', + '{$value->signature}', $attributes, $fileName, $class, diff --git a/src/Definition/Repository/Cache/Compiler/MethodDefinitionCompiler.php b/src/Definition/Repository/Cache/Compiler/MethodDefinitionCompiler.php index 282fa1bc..c523d31b 100644 --- a/src/Definition/Repository/Cache/Compiler/MethodDefinitionCompiler.php +++ b/src/Definition/Repository/Cache/Compiler/MethodDefinitionCompiler.php @@ -26,18 +26,18 @@ public function compile(MethodDefinition $method): string { $parameters = array_map( fn (ParameterDefinition $parameter) => $this->parameterCompiler->compile($parameter), - iterator_to_array($method->parameters()) + iterator_to_array($method->parameters) ); $parameters = implode(', ', $parameters); - $isStatic = var_export($method->isStatic(), true); - $isPublic = var_export($method->isPublic(), true); - $returnType = $this->typeCompiler->compile($method->returnType()); + $isStatic = var_export($method->isStatic, true); + $isPublic = var_export($method->isPublic, true); + $returnType = $this->typeCompiler->compile($method->returnType); return <<name()}', - '{$method->signature()}', + '{$method->name}', + '{$method->signature}', new \CuyZ\Valinor\Definition\Parameters($parameters), $isStatic, $isPublic, diff --git a/src/Definition/Repository/Cache/Compiler/ParameterDefinitionCompiler.php b/src/Definition/Repository/Cache/Compiler/ParameterDefinitionCompiler.php index be0a590f..909ab02a 100644 --- a/src/Definition/Repository/Cache/Compiler/ParameterDefinitionCompiler.php +++ b/src/Definition/Repository/Cache/Compiler/ParameterDefinitionCompiler.php @@ -16,16 +16,16 @@ public function __construct( public function compile(ParameterDefinition $parameter): string { - $isOptional = var_export($parameter->isOptional(), true); - $isVariadic = var_export($parameter->isVariadic(), true); + $isOptional = var_export($parameter->isOptional, true); + $isVariadic = var_export($parameter->isVariadic, true); $defaultValue = $this->defaultValue($parameter); - $type = $this->typeCompiler->compile($parameter->type()); - $attributes = $this->attributesCompiler->compile($parameter->attributes()); + $type = $this->typeCompiler->compile($parameter->type); + $attributes = $this->attributesCompiler->compile($parameter->attributes); return <<name()}', - '{$parameter->signature()}', + '{$parameter->name}', + '{$parameter->signature}', $type, $isOptional, $isVariadic, @@ -37,7 +37,7 @@ public function compile(ParameterDefinition $parameter): string private function defaultValue(ParameterDefinition $parameter): string { - $defaultValue = $parameter->defaultValue(); + $defaultValue = $parameter->defaultValue; return is_object($defaultValue) ? 'unserialize(' . var_export(serialize($defaultValue), true) . ')' diff --git a/src/Definition/Repository/Cache/Compiler/PropertyDefinitionCompiler.php b/src/Definition/Repository/Cache/Compiler/PropertyDefinitionCompiler.php index 3a6fb9f0..371df3be 100644 --- a/src/Definition/Repository/Cache/Compiler/PropertyDefinitionCompiler.php +++ b/src/Definition/Repository/Cache/Compiler/PropertyDefinitionCompiler.php @@ -16,16 +16,16 @@ public function __construct( public function compile(PropertyDefinition $property): string { - $type = $this->typeCompiler->compile($property->type()); - $hasDefaultValue = var_export($property->hasDefaultValue(), true); - $defaultValue = var_export($property->defaultValue(), true); - $isPublic = var_export($property->isPublic(), true); - $attributes = $this->attributesCompiler->compile($property->attributes()); + $type = $this->typeCompiler->compile($property->type); + $hasDefaultValue = var_export($property->hasDefaultValue, true); + $defaultValue = var_export($property->defaultValue, true); + $isPublic = var_export($property->isPublic, true); + $attributes = $this->attributesCompiler->compile($property->attributes); return <<name()}', - '{$property->signature()}', + '{$property->name}', + '{$property->signature}', $type, $hasDefaultValue, $defaultValue, diff --git a/src/Definition/Repository/Reflection/ReflectionClassDefinitionRepository.php b/src/Definition/Repository/Reflection/ReflectionClassDefinitionRepository.php index 39b61506..a686471c 100644 --- a/src/Definition/Repository/Reflection/ReflectionClassDefinitionRepository.php +++ b/src/Definition/Repository/Reflection/ReflectionClassDefinitionRepository.php @@ -65,6 +65,7 @@ public function for(ClassType $type): ClassDefinition $reflection = Reflection::class($type->className()); return new ClassDefinition( + $reflection->name, $type, new Attributes(...$this->attributes($reflection)), new Properties(...$this->properties($type)), diff --git a/src/Mapper/ArgumentsMapperError.php b/src/Mapper/ArgumentsMapperError.php index b7bd58b9..0cfbf969 100644 --- a/src/Mapper/ArgumentsMapperError.php +++ b/src/Mapper/ArgumentsMapperError.php @@ -25,11 +25,11 @@ public function __construct(FunctionDefinition $function, Node $node) if ($errorsCount === 1) { $body = $errors ->toArray()[0] - ->withBody("Could not map arguments of `{$function->signature()}`. An error occurred at path {node_path}: {original_message}") + ->withBody("Could not map arguments of `$function->signature`. An error occurred at path {node_path}: {original_message}") ->toString(); } else { $source = ValueDumper::dump($node->sourceValue()); - $body = "Could not map arguments of `{$function->signature()}` with value $source. A total of $errorsCount errors were encountered."; + $body = "Could not map arguments of `$function->signature` with value $source. A total of $errorsCount errors were encountered."; } parent::__construct($body, 1671115362); diff --git a/src/Mapper/Object/Argument.php b/src/Mapper/Object/Argument.php index 71fceb57..339b5631 100644 --- a/src/Mapper/Object/Argument.php +++ b/src/Mapper/Object/Argument.php @@ -30,11 +30,11 @@ public function __construct(string $name, Type $type) public static function fromParameter(ParameterDefinition $parameter): self { - $instance = new self($parameter->name(), $parameter->type()); - $instance->attributes = $parameter->attributes(); + $instance = new self($parameter->name, $parameter->type); + $instance->attributes = $parameter->attributes; - if ($parameter->isOptional()) { - $instance->defaultValue = $parameter->defaultValue(); + if ($parameter->isOptional) { + $instance->defaultValue = $parameter->defaultValue; $instance->isRequired = false; } @@ -43,11 +43,11 @@ public static function fromParameter(ParameterDefinition $parameter): self public static function fromProperty(PropertyDefinition $property): self { - $instance = new self($property->name(), $property->type()); - $instance->attributes = $property->attributes(); + $instance = new self($property->name, $property->type); + $instance->attributes = $property->attributes; - if ($property->hasDefaultValue()) { - $instance->defaultValue = $property->defaultValue(); + if ($property->hasDefaultValue) { + $instance->defaultValue = $property->defaultValue; $instance->isRequired = false; } diff --git a/src/Mapper/Object/Arguments.php b/src/Mapper/Object/Arguments.php index 3ff47c6a..023e390d 100644 --- a/src/Mapper/Object/Arguments.php +++ b/src/Mapper/Object/Arguments.php @@ -14,7 +14,6 @@ use function array_map; use function array_values; -use function iterator_to_array; /** * @internal @@ -35,7 +34,7 @@ public static function fromParameters(Parameters $parameters): self { return new self(...array_map( fn (ParameterDefinition $parameter) => Argument::fromParameter($parameter), - array_values(iterator_to_array($parameters)) // PHP8.1 array unpacking + array_values([...$parameters]) )); } @@ -43,7 +42,7 @@ public static function fromProperties(Properties $properties): self { return new self(...array_map( fn (PropertyDefinition $property) => Argument::fromProperty($property), - array_values(iterator_to_array($properties)) // PHP8.1 array unpacking + array_values([...$properties]) )); } diff --git a/src/Mapper/Object/Exception/CannotInstantiateObject.php b/src/Mapper/Object/Exception/CannotInstantiateObject.php index cbecad81..b60fae7c 100644 --- a/src/Mapper/Object/Exception/CannotInstantiateObject.php +++ b/src/Mapper/Object/Exception/CannotInstantiateObject.php @@ -13,7 +13,7 @@ final class CannotInstantiateObject extends RuntimeException public function __construct(ClassDefinition $class) { parent::__construct( - "No available constructor found for class `{$class->name()}`.", + "No available constructor found for class `{$class->name}`.", 1646916477 ); } diff --git a/src/Mapper/Object/Exception/InvalidConstructorClassTypeParameter.php b/src/Mapper/Object/Exception/InvalidConstructorClassTypeParameter.php index f47208ef..5f7fc45b 100644 --- a/src/Mapper/Object/Exception/InvalidConstructorClassTypeParameter.php +++ b/src/Mapper/Object/Exception/InvalidConstructorClassTypeParameter.php @@ -14,7 +14,7 @@ final class InvalidConstructorClassTypeParameter extends LogicException public function __construct(FunctionDefinition $function, Type $type) { parent::__construct( - "Invalid type `{$type->toString()}` for the first parameter of the constructor `{$function->signature()}`, it should be of type `class-string`.", + "Invalid type `{$type->toString()}` for the first parameter of the constructor `{$function->signature}`, it should be of type `class-string`.", 1661517000 ); } diff --git a/src/Mapper/Object/Exception/InvalidConstructorReturnType.php b/src/Mapper/Object/Exception/InvalidConstructorReturnType.php index 136b66e2..5fff4656 100644 --- a/src/Mapper/Object/Exception/InvalidConstructorReturnType.php +++ b/src/Mapper/Object/Exception/InvalidConstructorReturnType.php @@ -13,12 +13,10 @@ final class InvalidConstructorReturnType extends LogicException { public function __construct(FunctionDefinition $function) { - $returnType = $function->returnType(); - - if ($returnType instanceof UnresolvableType) { - $message = $returnType->message(); + if ($function->returnType instanceof UnresolvableType) { + $message = $function->returnType->message(); } else { - $message = "Invalid return type `{$returnType->toString()}` for constructor `{$function->signature()}`, it must be a valid class name."; + $message = "Invalid return type `{$function->returnType->toString()}` for constructor `{$function->signature}`, it must be a valid class name."; } parent::__construct($message, 1659446121); diff --git a/src/Mapper/Object/Exception/MissingConstructorClassTypeParameter.php b/src/Mapper/Object/Exception/MissingConstructorClassTypeParameter.php index 1c5c8d4e..57110e9c 100644 --- a/src/Mapper/Object/Exception/MissingConstructorClassTypeParameter.php +++ b/src/Mapper/Object/Exception/MissingConstructorClassTypeParameter.php @@ -13,7 +13,7 @@ final class MissingConstructorClassTypeParameter extends LogicException public function __construct(FunctionDefinition $function) { parent::__construct( - "Missing first parameter of type `class-string` for the constructor `{$function->signature()}`.", + "Missing first parameter of type `class-string` for the constructor `{$function->signature}`.", 1661516853 ); } diff --git a/src/Mapper/Object/Exception/ObjectBuildersCollision.php b/src/Mapper/Object/Exception/ObjectBuildersCollision.php index dce0aeee..697fed7c 100644 --- a/src/Mapper/Object/Exception/ObjectBuildersCollision.php +++ b/src/Mapper/Object/Exception/ObjectBuildersCollision.php @@ -20,7 +20,7 @@ public function __construct(ClassDefinition $class, ObjectBuilder ...$builders) $constructors = implode('`, `', $constructors); parent::__construct( - "A collision was detected between the following constructors of the class `{$class->type()->toString()}`: `$constructors`.", + "A collision was detected between the following constructors of the class `{$class->type->toString()}`: `$constructors`.", 1654955787 ); } diff --git a/src/Mapper/Object/Factory/CacheObjectBuilderFactory.php b/src/Mapper/Object/Factory/CacheObjectBuilderFactory.php index 82f14007..c1e460df 100644 --- a/src/Mapper/Object/Factory/CacheObjectBuilderFactory.php +++ b/src/Mapper/Object/Factory/CacheObjectBuilderFactory.php @@ -19,7 +19,7 @@ public function __construct( public function for(ClassDefinition $class): array { - $signature = $class->type()->toString(); + $signature = $class->type->toString(); $entry = $this->cache->get($signature); diff --git a/src/Mapper/Object/Factory/ConstructorObjectBuilderFactory.php b/src/Mapper/Object/Factory/ConstructorObjectBuilderFactory.php index feff612f..fd45c49f 100644 --- a/src/Mapper/Object/Factory/ConstructorObjectBuilderFactory.php +++ b/src/Mapper/Object/Factory/ConstructorObjectBuilderFactory.php @@ -45,7 +45,7 @@ public function for(ClassDefinition $class): array $builders = $this->builders($class); if (count($builders) === 0) { - if ($class->methods()->hasConstructor()) { + if ($class->methods->hasConstructor()) { throw new CannotInstantiateObject($class); } @@ -60,9 +60,9 @@ public function for(ClassDefinition $class): array */ private function builders(ClassDefinition $class): array { - $className = $class->name(); - $classType = $class->type(); - $methods = $class->methods(); + $className = $class->name; + $classType = $class->type; + $methods = $class->methods; $builders = []; @@ -71,13 +71,13 @@ private function builders(ClassDefinition $class): array continue; } - $definition = $constructor->definition(); - $functionClass = $definition->class(); + $definition = $constructor->definition; + $functionClass = $definition->class; - if ($functionClass && $definition->isStatic() && ! $definition->isClosure()) { + if ($functionClass && $definition->isStatic && ! $definition->isClosure) { $scopedClass = is_a($className, $functionClass, true) ? $className : $functionClass; - $builders[] = new MethodObjectBuilder($scopedClass, $definition->name(), $definition->parameters()); + $builders[] = new MethodObjectBuilder($scopedClass, $definition->name, $definition->parameters); } else { $builders[] = new FunctionObjectBuilder($constructor, $classType); } @@ -89,7 +89,7 @@ private function builders(ClassDefinition $class): array if ($classType instanceof EnumType) { $builders[] = new NativeEnumObjectBuilder($classType); - } elseif ($methods->hasConstructor() && $methods->constructor()->isPublic()) { + } elseif ($methods->hasConstructor() && $methods->constructor()->isPublic) { $builders[] = new NativeConstructorObjectBuilder($class); } @@ -98,23 +98,21 @@ private function builders(ClassDefinition $class): array private function constructorMatches(FunctionObject $function, ClassType $classType): bool { - $definition = $function->definition(); - $parameters = $definition->parameters(); - $returnType = $definition->returnType(); + $definition = $function->definition; - if (! $classType->matches($returnType)) { + if (! $classType->matches($definition->returnType)) { return false; } - if (! $definition->attributes()->has(DynamicConstructor::class)) { + if (! $definition->attributes->has(DynamicConstructor::class)) { return true; } - if (count($parameters) === 0) { + if (count($definition->parameters) === 0) { throw new MissingConstructorClassTypeParameter($definition); } - $parameterType = $parameters->at(0)->type(); + $parameterType = $definition->parameters->at(0)->type; if ($parameterType instanceof NativeStringType) { $parameterType = ClassStringType::get(); @@ -142,13 +140,13 @@ private function filteredConstructors(): array $this->filteredConstructors = []; foreach ($this->constructors as $constructor) { - $function = $constructor->definition(); + $function = $constructor->definition; - if (enum_exists($function->class() ?? '') && in_array($function->name(), ['from', 'tryFrom'], true)) { + if (enum_exists($function->class ?? '') && in_array($function->name, ['from', 'tryFrom'], true)) { continue; } - if (! $function->returnType() instanceof ObjectType) { + if (! $function->returnType instanceof ObjectType) { throw new InvalidConstructorReturnType($function); } diff --git a/src/Mapper/Object/Factory/DateTimeObjectBuilderFactory.php b/src/Mapper/Object/Factory/DateTimeObjectBuilderFactory.php index f1c80bc2..a3a54fe5 100644 --- a/src/Mapper/Object/Factory/DateTimeObjectBuilderFactory.php +++ b/src/Mapper/Object/Factory/DateTimeObjectBuilderFactory.php @@ -31,7 +31,7 @@ public function __construct( public function for(ClassDefinition $class): array { - $className = $class->name(); + $className = $class->name; $builders = $this->delegate->for($class); @@ -45,7 +45,7 @@ public function for(ClassDefinition $class): array $buildersWithOneArgument = array_filter($builders, fn (ObjectBuilder $builder) => count($builder->describeArguments()) === 1); if (count($buildersWithOneArgument) === 0 || $this->supportedDateFormats !== Settings::DEFAULT_SUPPORTED_DATETIME_FORMATS) { - $builders[] = $this->internalDateTimeBuilder($class->type()); + $builders[] = $this->internalDateTimeBuilder($class->type); } return $builders; diff --git a/src/Mapper/Object/Factory/DateTimeZoneObjectBuilderFactory.php b/src/Mapper/Object/Factory/DateTimeZoneObjectBuilderFactory.php index 48871ca9..7f76a431 100644 --- a/src/Mapper/Object/Factory/DateTimeZoneObjectBuilderFactory.php +++ b/src/Mapper/Object/Factory/DateTimeZoneObjectBuilderFactory.php @@ -35,7 +35,7 @@ public function for(ClassDefinition $class): array { $builders = $this->delegate->for($class); - if ($class->name() !== DateTimeZone::class) { + if ($class->name !== DateTimeZone::class) { return $builders; } @@ -54,7 +54,7 @@ public function for(ClassDefinition $class): array if ($useDefaultBuilder) { // @infection-ignore-all / Ignore memoization - $builders[] = $this->defaultBuilder($class->type()); + $builders[] = $this->defaultBuilder($class->type); } return $builders; diff --git a/src/Mapper/Object/Factory/ReflectionObjectBuilderFactory.php b/src/Mapper/Object/Factory/ReflectionObjectBuilderFactory.php index abdb91dc..d7f1391d 100644 --- a/src/Mapper/Object/Factory/ReflectionObjectBuilderFactory.php +++ b/src/Mapper/Object/Factory/ReflectionObjectBuilderFactory.php @@ -14,7 +14,7 @@ final class ReflectionObjectBuilderFactory implements ObjectBuilderFactory { public function for(ClassDefinition $class): array { - if (enum_exists($class->name())) { + if (enum_exists($class->name)) { return []; } diff --git a/src/Mapper/Object/FunctionObjectBuilder.php b/src/Mapper/Object/FunctionObjectBuilder.php index 57f2e08f..281f3e7e 100644 --- a/src/Mapper/Object/FunctionObjectBuilder.php +++ b/src/Mapper/Object/FunctionObjectBuilder.php @@ -26,14 +26,14 @@ final class FunctionObjectBuilder implements ObjectBuilder public function __construct(FunctionObject $function, ClassType $type) { - $definition = $function->definition(); + $definition = $function->definition; $arguments = array_map( fn (ParameterDefinition $parameter) => Argument::fromParameter($parameter), - array_values(iterator_to_array($definition->parameters())) // PHP8.1 array unpacking + array_values([...$definition->parameters]) ); - $this->isDynamicConstructor = $definition->attributes()->has(DynamicConstructor::class); + $this->isDynamicConstructor = $definition->attributes->has(DynamicConstructor::class); if ($this->isDynamicConstructor) { array_shift($arguments); @@ -51,16 +51,16 @@ public function describeArguments(): Arguments public function build(array $arguments): object { - $parameters = $this->function->definition()->parameters(); + $parameters = $this->function->definition->parameters; if ($this->isDynamicConstructor) { - $arguments[$parameters->at(0)->name()] = $this->className; + $arguments[$parameters->at(0)->name] = $this->className; } $arguments = new MethodArguments($parameters, $arguments); try { - return ($this->function->callback())(...$arguments); + return ($this->function->callback)(...$arguments); } catch (Exception $exception) { throw UserlandError::from($exception); } @@ -68,6 +68,6 @@ public function build(array $arguments): object public function signature(): string { - return $this->function->definition()->signature(); + return $this->function->definition->signature; } } diff --git a/src/Mapper/Object/MethodArguments.php b/src/Mapper/Object/MethodArguments.php index 7a10723f..ded388c6 100644 --- a/src/Mapper/Object/MethodArguments.php +++ b/src/Mapper/Object/MethodArguments.php @@ -26,9 +26,9 @@ final class MethodArguments implements IteratorAggregate public function __construct(Parameters $parameters, array $arguments) { foreach ($parameters as $parameter) { - $name = $parameter->name(); + $name = $parameter->name; - if ($parameter->isVariadic()) { + if ($parameter->isVariadic) { $this->arguments = [...$this->arguments, ...array_values($arguments[$name])]; // @phpstan-ignore-line we know that the argument is iterable } else { $this->arguments[] = $arguments[$name]; diff --git a/src/Mapper/Object/NativeConstructorObjectBuilder.php b/src/Mapper/Object/NativeConstructorObjectBuilder.php index ec7bedd3..808a16f9 100644 --- a/src/Mapper/Object/NativeConstructorObjectBuilder.php +++ b/src/Mapper/Object/NativeConstructorObjectBuilder.php @@ -17,13 +17,13 @@ public function __construct(private ClassDefinition $class) {} public function describeArguments(): Arguments { - return $this->arguments ??= Arguments::fromParameters($this->class->methods()->constructor()->parameters()); + return $this->arguments ??= Arguments::fromParameters($this->class->methods->constructor()->parameters); } public function build(array $arguments): object { - $className = $this->class->name(); - $arguments = new MethodArguments($this->class->methods()->constructor()->parameters(), $arguments); + $className = $this->class->name; + $arguments = new MethodArguments($this->class->methods->constructor()->parameters, $arguments); try { return new $className(...$arguments); @@ -34,6 +34,6 @@ public function build(array $arguments): object public function signature(): string { - return $this->class->methods()->constructor()->signature(); + return $this->class->methods->constructor()->signature; } } diff --git a/src/Mapper/Object/ReflectionObjectBuilder.php b/src/Mapper/Object/ReflectionObjectBuilder.php index 54447c75..54eccbf4 100644 --- a/src/Mapper/Object/ReflectionObjectBuilder.php +++ b/src/Mapper/Object/ReflectionObjectBuilder.php @@ -17,12 +17,12 @@ public function __construct(private ClassDefinition $class) {} public function describeArguments(): Arguments { - return $this->arguments ??= Arguments::fromProperties($this->class->properties()); + return $this->arguments ??= Arguments::fromProperties($this->class->properties); } public function build(array $arguments): object { - $object = new ($this->class->name())(); + $object = new ($this->class->name)(); if (count($arguments) > 0) { (function () use ($arguments): void { @@ -37,6 +37,6 @@ public function build(array $arguments): object public function signature(): string { - return $this->class->name() . ' (properties)'; + return $this->class->name . ' (properties)'; } } diff --git a/src/Mapper/Tree/Builder/InterfaceNodeBuilder.php b/src/Mapper/Tree/Builder/InterfaceNodeBuilder.php index eb6a03c4..93f3e893 100644 --- a/src/Mapper/Tree/Builder/InterfaceNodeBuilder.php +++ b/src/Mapper/Tree/Builder/InterfaceNodeBuilder.php @@ -44,7 +44,7 @@ public function build(Shell $shell, RootNodeBuilder $rootBuilder): TreeNode $className = $type->className(); if (! $this->implementations->has($className)) { - if ($type instanceof InterfaceType || $this->classDefinitionRepository->for($type)->isAbstract()) { + if ($type instanceof InterfaceType || $this->classDefinitionRepository->for($type)->isAbstract) { throw new CannotResolveObjectType($className); } @@ -52,9 +52,9 @@ public function build(Shell $shell, RootNodeBuilder $rootBuilder): TreeNode } $function = $this->implementations->function($className); - $arguments = Arguments::fromParameters($function->parameters()); + $arguments = Arguments::fromParameters($function->parameters); - if ($type instanceof NativeClassType && $this->classDefinitionRepository->for($type)->isFinal()) { + if ($type instanceof NativeClassType && $this->classDefinitionRepository->for($type)->isFinal) { throw new CannotInferFinalClass($type, $function); } diff --git a/src/Mapper/Tree/Builder/ObjectImplementations.php b/src/Mapper/Tree/Builder/ObjectImplementations.php index 8b9ba566..a1e9982c 100644 --- a/src/Mapper/Tree/Builder/ObjectImplementations.php +++ b/src/Mapper/Tree/Builder/ObjectImplementations.php @@ -44,7 +44,7 @@ public function has(string $name): bool public function function(string $name): FunctionDefinition { - return $this->functions->get($name)->definition(); + return $this->functions->get($name)->definition; } /** @@ -64,7 +64,7 @@ public function implementation(string $name, array $arguments): ClassType private function call(string $name, array $arguments): string { try { - $signature = ($this->functions->get($name)->callback())(...$arguments); + $signature = ($this->functions->get($name)->callback)(...$arguments); } catch (Exception $exception) { throw new ObjectImplementationCallbackError($name, $exception); } @@ -81,7 +81,7 @@ private function call(string $name, array $arguments): string */ private function implementations(string $name): array { - $function = $this->functions->get($name)->definition(); + $function = $this->functions->get($name)->definition; try { $type = $this->typeParser->parse($name); @@ -113,10 +113,10 @@ private function implementations(string $name): array */ private function implementationsByReturnSignature(string $name, FunctionDefinition $function): array { - $returnType = $function->returnType(); + $returnType = $function->returnType; if (! $returnType instanceof ClassStringType && ! $returnType instanceof UnionType) { - if (count($function->parameters()) > 0) { + if (count($function->parameters) > 0) { return []; } diff --git a/src/Mapper/Tree/Builder/TreeNode.php b/src/Mapper/Tree/Builder/TreeNode.php index 8a17f437..959e7755 100644 --- a/src/Mapper/Tree/Builder/TreeNode.php +++ b/src/Mapper/Tree/Builder/TreeNode.php @@ -77,11 +77,7 @@ public static function flattenedBranch(Shell $shell, mixed $value, self $child): return $instance; } - /** - * PHP8.1 intersection - * @param Throwable&Message $message - */ - public static function error(Shell $shell, Throwable $message): self + public static function error(Shell $shell, Throwable&Message $message): self { return (new self($shell, null))->withMessage($message); } diff --git a/src/Mapper/Tree/Builder/ValueAlteringNodeBuilder.php b/src/Mapper/Tree/Builder/ValueAlteringNodeBuilder.php index 66a6630d..ed518d94 100644 --- a/src/Mapper/Tree/Builder/ValueAlteringNodeBuilder.php +++ b/src/Mapper/Tree/Builder/ValueAlteringNodeBuilder.php @@ -26,19 +26,19 @@ public function build(Shell $shell, RootNodeBuilder $rootBuilder): TreeNode $value = $node->value(); foreach ($this->functions as $function) { - $parameters = $function->definition()->parameters(); + $parameters = $function->definition->parameters; if (count($parameters) === 0) { continue; } - $firstParameterType = $parameters->at(0)->type(); + $firstParameterType = $parameters->at(0)->type; if (! $firstParameterType->accepts($value)) { continue; } - $value = ($function->callback())($value); + $value = ($function->callback)($value); $node = $node->withValue($value); } diff --git a/src/Mapper/Tree/Exception/CannotInferFinalClass.php b/src/Mapper/Tree/Exception/CannotInferFinalClass.php index d2bd244e..b8e84f7b 100644 --- a/src/Mapper/Tree/Exception/CannotInferFinalClass.php +++ b/src/Mapper/Tree/Exception/CannotInferFinalClass.php @@ -14,7 +14,7 @@ final class CannotInferFinalClass extends RuntimeException public function __construct(ClassType $class, FunctionDefinition $function) { parent::__construct( - "Cannot infer final class `{$class->className()}` with function `{$function->signature()}`.", + "Cannot infer final class `{$class->className()}` with function `$function->signature`.", 1671468163 ); } diff --git a/src/Mapper/Tree/Exception/CannotResolveTypeFromUnion.php b/src/Mapper/Tree/Exception/CannotResolveTypeFromUnion.php index ee470cac..a8dacb2f 100644 --- a/src/Mapper/Tree/Exception/CannotResolveTypeFromUnion.php +++ b/src/Mapper/Tree/Exception/CannotResolveTypeFromUnion.php @@ -27,8 +27,7 @@ public function __construct(mixed $source, UnionType $unionType) $this->parameters = [ 'allowed_types' => implode( ', ', - // PHP8.1 First-class callable syntax - array_map([TypeHelper::class, 'dump'], $unionType->types()) + array_map(TypeHelper::dump(...), $unionType->types()) ), ]; diff --git a/src/Mapper/Tree/Exception/MissingObjectImplementationRegistration.php b/src/Mapper/Tree/Exception/MissingObjectImplementationRegistration.php index 9d5b4712..850c3097 100644 --- a/src/Mapper/Tree/Exception/MissingObjectImplementationRegistration.php +++ b/src/Mapper/Tree/Exception/MissingObjectImplementationRegistration.php @@ -13,7 +13,7 @@ final class MissingObjectImplementationRegistration extends RuntimeException public function __construct(string $name, FunctionDefinition $functionDefinition) { parent::__construct( - "No implementation of `$name` found with return type `{$functionDefinition->returnType()->toString()}` of `{$functionDefinition->signature()}`.", + "No implementation of `$name` found with return type `{$functionDefinition->returnType->toString()}` of `$functionDefinition->signature`.", 1653990549 ); } diff --git a/src/Mapper/Tree/Message/MessageBuilder.php b/src/Mapper/Tree/Message/MessageBuilder.php index aa7e55cf..943e1ed2 100644 --- a/src/Mapper/Tree/Message/MessageBuilder.php +++ b/src/Mapper/Tree/Message/MessageBuilder.php @@ -121,10 +121,9 @@ public function parameters(): array /** * @psalm-pure * - * PHP8.1 intersection * @return MessageType&HasCode&HasParameters */ - public function build(): Message + public function build(): Message&HasCode&HasParameters { /** @var MessageType&HasCode&HasParameters */ return $this->isError @@ -132,7 +131,7 @@ public function build(): Message : $this->buildMessage(); } - private function buildMessage(): Message + private function buildMessage(): Message&HasCode&HasParameters { return new class ($this->body, $this->code, $this->parameters) implements Message, HasCode, HasParameters { /** @@ -161,7 +160,7 @@ public function parameters(): array }; } - private function buildErrorMessage(): ErrorMessage + private function buildErrorMessage(): ErrorMessage&HasCode&HasParameters { return new class ($this->body, $this->code, $this->parameters) extends RuntimeException implements ErrorMessage, HasCode, HasParameters { /** diff --git a/src/Mapper/Tree/Message/UserlandError.php b/src/Mapper/Tree/Message/UserlandError.php index 2313239a..fd4fc4f4 100644 --- a/src/Mapper/Tree/Message/UserlandError.php +++ b/src/Mapper/Tree/Message/UserlandError.php @@ -10,11 +10,7 @@ /** @internal */ final class UserlandError extends RuntimeException implements ErrorMessage { - /** - * PHP8.1 intersection - * @return Message&Throwable - */ - public static function from(Throwable $message): Message + public static function from(Throwable $message): Message&Throwable { // @infection-ignore-all return $message instanceof Message diff --git a/src/Mapper/TypeArgumentsMapper.php b/src/Mapper/TypeArgumentsMapper.php index 5d128cdc..dfa4a21e 100644 --- a/src/Mapper/TypeArgumentsMapper.php +++ b/src/Mapper/TypeArgumentsMapper.php @@ -32,11 +32,11 @@ public function mapArguments(callable $callable, mixed $source): array $elements = array_map( fn (ParameterDefinition $parameter) => new ShapedArrayElement( - new StringValueType($parameter->name()), - $parameter->type(), - $parameter->isOptional() + new StringValueType($parameter->name), + $parameter->type, + $parameter->isOptional ), - iterator_to_array($function->parameters()) + iterator_to_array($function->parameters) ); $type = new ShapedArrayType(...$elements); diff --git a/src/Normalizer/ArrayNormalizer.php b/src/Normalizer/ArrayNormalizer.php index c711e5e6..c76a000f 100644 --- a/src/Normalizer/ArrayNormalizer.php +++ b/src/Normalizer/ArrayNormalizer.php @@ -26,13 +26,10 @@ public function normalize(mixed $value): mixed { $value = $this->transformer->transform($value); + /** @var array|scalar|null */ return $this->normalizeIterator($value); } - /** - * @param iterable|scalar|null $value - * @return array|scalar|null - */ private function normalizeIterator(mixed $value): mixed { if (is_iterable($value)) { @@ -40,8 +37,7 @@ private function normalizeIterator(mixed $value): mixed $value = iterator_to_array($value); } - // PHP8.1 First-class callable syntax - $value = array_map([$this, 'normalizeIterator'], $value); + $value = array_map($this->normalizeIterator(...), $value); } return $value; diff --git a/src/Normalizer/Exception/KeyTransformerHasTooManyParameters.php b/src/Normalizer/Exception/KeyTransformerHasTooManyParameters.php index 6e902e04..3a751f3d 100644 --- a/src/Normalizer/Exception/KeyTransformerHasTooManyParameters.php +++ b/src/Normalizer/Exception/KeyTransformerHasTooManyParameters.php @@ -13,7 +13,7 @@ final class KeyTransformerHasTooManyParameters extends LogicException public function __construct(MethodDefinition $method) { parent::__construct( - "Key transformer must have at most 1 parameter, {$method->parameters()->count()} given for `{$method->signature()}`.", + "Key transformer must have at most 1 parameter, {$method->parameters->count()} given for `$method->signature`.", 1701701102, ); } diff --git a/src/Normalizer/Exception/KeyTransformerParameterInvalidType.php b/src/Normalizer/Exception/KeyTransformerParameterInvalidType.php index 269c7f7b..a1cef842 100644 --- a/src/Normalizer/Exception/KeyTransformerParameterInvalidType.php +++ b/src/Normalizer/Exception/KeyTransformerParameterInvalidType.php @@ -13,7 +13,7 @@ final class KeyTransformerParameterInvalidType extends LogicException public function __construct(MethodDefinition $method) { parent::__construct( - "Key transformer parameter must be a string, {$method->parameters()->at(0)->type()->toString()} given for `{$method->signature()}`.", + "Key transformer parameter must be a string, {$method->parameters->at(0)->type->toString()} given for `$method->signature`.", 1701706316, ); } diff --git a/src/Normalizer/Exception/TransformerHasInvalidCallableParameter.php b/src/Normalizer/Exception/TransformerHasInvalidCallableParameter.php index e3223b87..b0360044 100644 --- a/src/Normalizer/Exception/TransformerHasInvalidCallableParameter.php +++ b/src/Normalizer/Exception/TransformerHasInvalidCallableParameter.php @@ -15,7 +15,7 @@ final class TransformerHasInvalidCallableParameter extends LogicException public function __construct(MethodDefinition|FunctionDefinition $method, Type $parameterType) { parent::__construct( - "Transformer's second parameter must be a callable, `{$parameterType->toString()}` given for `{$method->signature()}`.", + "Transformer's second parameter must be a callable, `{$parameterType->toString()}` given for `$method->signature`.", 1695065710, ); } diff --git a/src/Normalizer/Exception/TransformerHasNoParameter.php b/src/Normalizer/Exception/TransformerHasNoParameter.php index 27127aad..d04173db 100644 --- a/src/Normalizer/Exception/TransformerHasNoParameter.php +++ b/src/Normalizer/Exception/TransformerHasNoParameter.php @@ -14,7 +14,7 @@ final class TransformerHasNoParameter extends LogicException public function __construct(MethodDefinition|FunctionDefinition $method) { parent::__construct( - "Transformer must have at least one parameter, none given for `{$method->signature()}`.", + "Transformer must have at least one parameter, none given for `$method->signature`.", 1695064946, ); } diff --git a/src/Normalizer/Exception/TransformerHasTooManyParameters.php b/src/Normalizer/Exception/TransformerHasTooManyParameters.php index 6da2055b..46dc929b 100644 --- a/src/Normalizer/Exception/TransformerHasTooManyParameters.php +++ b/src/Normalizer/Exception/TransformerHasTooManyParameters.php @@ -14,7 +14,7 @@ final class TransformerHasTooManyParameters extends LogicException public function __construct(MethodDefinition|FunctionDefinition $method) { parent::__construct( - "Transformer must have at most 2 parameters, {$method->parameters()->count()} given for `{$method->signature()}`.", + "Transformer must have at most 2 parameters, {$method->parameters->count()} given for `$method->signature`.", 1695065433, ); } diff --git a/src/Normalizer/Formatter/JsonFormatter.php b/src/Normalizer/Formatter/JsonFormatter.php index e2259abc..a3369f5b 100644 --- a/src/Normalizer/Formatter/JsonFormatter.php +++ b/src/Normalizer/Formatter/JsonFormatter.php @@ -8,7 +8,7 @@ use Generator; use function addcslashes; -use function array_values; +use function array_is_list; use function fwrite; use function is_array; use function is_bool; @@ -49,7 +49,7 @@ public function format(mixed $value): void // should have been an object. This is a trade-off we accept, // considering most generators starting at 0 are actually lists. $isList = ($value instanceof Generator && $value->key() === 0) - || (is_array($value) && $this->arrayIsList($value)); + || (is_array($value) && array_is_list($value)); $isFirst = true; @@ -84,33 +84,4 @@ private function write(string $content): void { fwrite($this->resource, $content); } - - /** - * PHP8.1: replace with native function. - * - * `array_is_list` function polyfill. - * - * Code taken from `symfony/polyfill-php81` - * - * @param array $array - * - * @codeCoverageIgnore - * @infection-ignore-all - */ - private function arrayIsList(array $array): bool - { - if ([] === $array || $array === array_values($array)) { - return true; - } - - $nextKey = -1; - - foreach ($array as $k => $v) { - if ($k !== ++$nextKey) { - return false; - } - } - - return true; - } } diff --git a/src/Normalizer/Transformer/KeyTransformersHandler.php b/src/Normalizer/Transformer/KeyTransformersHandler.php index 67b907b5..8f86c89f 100644 --- a/src/Normalizer/Transformer/KeyTransformersHandler.php +++ b/src/Normalizer/Transformer/KeyTransformersHandler.php @@ -22,15 +22,15 @@ final class KeyTransformersHandler public function transformKey(string|int $key, array $attributes): string|int { foreach ($attributes as $attribute) { - if (! $attribute->class()->methods()->has('normalizeKey')) { + if (! $attribute->class->methods->has('normalizeKey')) { continue; } - $method = $attribute->class()->methods()->get('normalizeKey'); + $method = $attribute->class->methods->get('normalizeKey'); $this->checkKeyTransformer($method); - if ($method->parameters()->count() === 0 || $method->parameters()->at(0)->type()->accepts($key)) { + if ($method->parameters->count() === 0 || $method->parameters->at(0)->type->accepts($key)) { $key = $attribute->instantiate()->normalizeKey($key); // @phpstan-ignore-line / We know the method exists } } @@ -40,21 +40,21 @@ public function transformKey(string|int $key, array $attributes): string|int private function checkKeyTransformer(MethodDefinition $method): void { - if (isset($this->keyTransformerCheck[$method->signature()])) { + if (isset($this->keyTransformerCheck[$method->signature])) { return; } // @infection-ignore-all - $this->keyTransformerCheck[$method->signature()] = true; + $this->keyTransformerCheck[$method->signature] = true; - $parameters = $method->parameters(); + $parameters = $method->parameters; if ($parameters->count() > 1) { throw new KeyTransformerHasTooManyParameters($method); } if ($parameters->count() > 0) { - $type = $parameters->at(0)->type(); + $type = $parameters->at(0)->type; if (! $type instanceof StringType) { throw new KeyTransformerParameterInvalidType($method); diff --git a/src/Normalizer/Transformer/RecursiveTransformer.php b/src/Normalizer/Transformer/RecursiveTransformer.php index 2099bebc..29ae24f9 100644 --- a/src/Normalizer/Transformer/RecursiveTransformer.php +++ b/src/Normalizer/Transformer/RecursiveTransformer.php @@ -15,13 +15,11 @@ use DateTimeInterface; use DateTimeZone; use Generator; -use ReflectionClass; use stdClass; use UnitEnum; use WeakMap; use function array_map; -use function array_reverse; use function get_object_vars; use function is_a; use function is_array; @@ -71,7 +69,7 @@ private function doTransform(mixed $value, WeakMap $references, array $attribute } if ($this->transformerAttributes !== [] && is_object($value)) { - $classAttributes = $this->classDefinitionRepository->for(NativeClassType::for($value::class))->attributes(); + $classAttributes = $this->classDefinitionRepository->for(NativeClassType::for($value::class))->attributes; $classAttributes = $this->filterAttributes($classAttributes); $attributes = [...$attributes, ...$classAttributes]; @@ -121,37 +119,12 @@ private function defaultTransformer(mixed $value, WeakMap $references): mixed $values = (fn () => get_object_vars($this))->call($value); - // @infection-ignore-all - if (PHP_VERSION_ID < 8_01_00) { - // In PHP 8.1, behavior changed for `get_object_vars` function: - // the sorting order was taking children properties first, now - // it takes parents properties first. This code is a temporary - // workaround to keep the same behavior in PHP 8.0 and later - // versions. - $sorted = []; - - $parents = array_reverse(class_parents($value)); - $parents[] = $value::class; - - foreach ($parents as $parent) { - foreach ((new ReflectionClass($parent))->getProperties() as $property) { - if (! isset($values[$property->name])) { - continue; - } - - $sorted[$property->name] = $values[$property->name]; - } - } - - $values = $sorted; - } - $transformed = []; $class = $this->classDefinitionRepository->for(NativeClassType::for($value::class)); foreach ($values as $key => $subValue) { - $attributes = $this->filterAttributes($class->properties()->get($key)->attributes())->toArray(); + $attributes = $this->filterAttributes($class->properties->get($key)->attributes)->toArray(); $key = $this->keyTransformers->transformKey($key, $attributes); @@ -183,7 +156,7 @@ private function filterAttributes(Attributes $attributes): Attributes { return $attributes->filter(function (AttributeDefinition $attribute) { foreach ($this->transformerAttributes as $transformerAttribute) { - if (is_a($attribute->class()->type()->className(), $transformerAttribute, true)) { + if (is_a($attribute->class->type->className(), $transformerAttribute, true)) { return true; } } diff --git a/src/Normalizer/Transformer/ValueTransformersHandler.php b/src/Normalizer/Transformer/ValueTransformersHandler.php index 31731336..d5cdf90a 100644 --- a/src/Normalizer/Transformer/ValueTransformersHandler.php +++ b/src/Normalizer/Transformer/ValueTransformersHandler.php @@ -62,7 +62,7 @@ private function next(array $transformers, mixed $value, array $attributes, call $this->checkTransformer($function); - if (! $function->parameters()->at(0)->type()->accepts($value)) { + if (! $function->parameters->at(0)->type->accepts($value)) { return $this->next($transformers, $value, [], $defaultTransformer); } @@ -80,15 +80,15 @@ private function nextAttribute(mixed $value, array $attributes, callable $next): return $next; } - if (! $attribute->class()->methods()->has('normalize')) { + if (! $attribute->class->methods->has('normalize')) { return $this->nextAttribute($value, $attributes, $next); } - $method = $attribute->class()->methods()->get('normalize'); + $method = $attribute->class->methods->get('normalize'); $this->checkTransformer($method); - if (! $method->parameters()->at(0)->type()->accepts($value)) { + if (! $method->parameters->at(0)->type->accepts($value)) { return $this->nextAttribute($value, $attributes, $next); } @@ -101,14 +101,14 @@ private function nextAttribute(mixed $value, array $attributes, callable $next): private function checkTransformer(MethodDefinition|FunctionDefinition $method): void { - if (isset($this->transformerCheck[$method->signature()])) { + if (isset($this->transformerCheck[$method->signature])) { return; } // @infection-ignore-all - $this->transformerCheck[$method->signature()] = true; + $this->transformerCheck[$method->signature] = true; - $parameters = $method->parameters(); + $parameters = $method->parameters; if ($parameters->count() === 0) { throw new TransformerHasNoParameter($method); @@ -118,8 +118,8 @@ private function checkTransformer(MethodDefinition|FunctionDefinition $method): throw new TransformerHasTooManyParameters($method); } - if ($parameters->count() > 1 && ! $parameters->at(1)->type() instanceof CallableType) { - throw new TransformerHasInvalidCallableParameter($method, $parameters->at(1)->type()); + if ($parameters->count() > 1 && ! $parameters->at(1)->type instanceof CallableType) { + throw new TransformerHasInvalidCallableParameter($method, $parameters->at(1)->type); } } } diff --git a/src/Type/Parser/Lexer/NativeLexer.php b/src/Type/Parser/Lexer/NativeLexer.php index 68b1ad04..c1ce8e58 100644 --- a/src/Type/Parser/Lexer/NativeLexer.php +++ b/src/Type/Parser/Lexer/NativeLexer.php @@ -83,8 +83,7 @@ public function tokenize(string $symbol): Token return new FloatValueToken((float)$symbol); } - /** @infection-ignore-all */ - if (PHP_VERSION_ID >= 8_01_00 && enum_exists($symbol)) { + if (enum_exists($symbol)) { /** @var class-string $symbol */ return new EnumNameToken($symbol); } diff --git a/src/Type/Types/ListType.php b/src/Type/Types/ListType.php index f669dd08..84d6460e 100644 --- a/src/Type/Types/ListType.php +++ b/src/Type/Types/ListType.php @@ -42,7 +42,6 @@ public function accepts(mixed $value): bool return false; } - // PHP8.1 use `array_is_list` $i = 0; foreach ($value as $key => $item) { diff --git a/src/Utility/Reflection/TokenParser.php b/src/Utility/Reflection/TokenParser.php index 2e58f740..e97bd34c 100644 --- a/src/Utility/Reflection/TokenParser.php +++ b/src/Utility/Reflection/TokenParser.php @@ -38,7 +38,7 @@ public function parseUseStatements(string $namespaceName): array while ($token = $this->next()) { if ($currentNamespace === $namespaceName && $token->is(T_USE)) { - $statements = array_merge($statements, $this->parseUseStatement()); + $statements = [...$statements, ...$this->parseUseStatement()]; continue; } diff --git a/tests/Fake/Definition/FakeClassDefinition.php b/tests/Fake/Definition/FakeClassDefinition.php index a7b57803..851feeb4 100644 --- a/tests/Fake/Definition/FakeClassDefinition.php +++ b/tests/Fake/Definition/FakeClassDefinition.php @@ -26,6 +26,7 @@ private function __construct() {} public static function new(string $name = stdClass::class): ClassDefinition { return new ClassDefinition( + $name, new NativeClassType($name), new Attributes(), new Properties(), @@ -51,6 +52,7 @@ public static function fromReflection(ReflectionClass $reflection): ClassDefinit ); return new ClassDefinition( + $reflection->name, new NativeClassType($reflection->name), new Attributes(), new Properties(...$properties), diff --git a/tests/Fixture/Object/ObjectWithConstants.php b/tests/Fixture/Object/ObjectWithConstants.php index 8ccca9f9..c837ee95 100644 --- a/tests/Fixture/Object/ObjectWithConstants.php +++ b/tests/Fixture/Object/ObjectWithConstants.php @@ -4,37 +4,43 @@ namespace CuyZ\Valinor\Tests\Fixture\Object; +use CuyZ\Valinor\Tests\Fixture\Enum\BackedIntegerEnum; + class ObjectWithConstants { - public const CONST_WITH_STRING_VALUE_A = 'some string value'; + final public const CONST_WITH_STRING_VALUE_A = 'some string value'; - public const CONST_WITH_STRING_VALUE_B = 'another string value'; + final public const CONST_WITH_STRING_VALUE_B = 'another string value'; private const CONST_WITH_STRING_PRIVATE_VALUE = 'some private string value'; // @phpstan-ignore-line - public const CONST_WITH_PREFIX_WITH_STRING_VALUE = 'some prefixed string value'; + final public const CONST_WITH_PREFIX_WITH_STRING_VALUE = 'some prefixed string value'; + + final public const CONST_WITH_INTEGER_VALUE_A = 1653398288; - public const CONST_WITH_INTEGER_VALUE_A = 1653398288; + final public const CONST_WITH_INTEGER_VALUE_B = 1653398289; - public const CONST_WITH_INTEGER_VALUE_B = 1653398289; + final public const CONST_WITH_FLOAT_VALUE_A = 1337.42; - public const CONST_WITH_FLOAT_VALUE_A = 1337.42; + final public const CONST_WITH_FLOAT_VALUE_B = 404.512; - public const CONST_WITH_FLOAT_VALUE_B = 404.512; + final public const CONST_WITH_ENUM_VALUE_A = BackedIntegerEnum::FOO; - public const CONST_WITH_ARRAY_VALUE_A = [ + final public const CONST_WITH_ENUM_VALUE_B = BackedIntegerEnum::BAR; + + final public const CONST_WITH_ARRAY_VALUE_A = [ 'string' => 'some string value', 'integer' => 1653398288, 'float' => 1337.42, ]; - public const CONST_WITH_ARRAY_VALUE_B = [ + final public const CONST_WITH_ARRAY_VALUE_B = [ 'string' => 'another string value', 'integer' => 1653398289, 'float' => 404.512, ]; - public const CONST_WITH_NESTED_ARRAY_VALUE_A = [ + final public const CONST_WITH_NESTED_ARRAY_VALUE_A = [ 'nested_array' => [ 'string' => 'some string value', 'integer' => 1653398288, @@ -42,22 +48,11 @@ class ObjectWithConstants ], ]; - public const CONST_WITH_NESTED_ARRAY_VALUE_B = [ + final public const CONST_WITH_NESTED_ARRAY_VALUE_B = [ 'another_nested_array' => [ 'string' => 'another string value', 'integer' => 1653398289, 'float' => 404.512, ], ]; - - /** - * PHP8.1 replace all calls with `ObjectWithConstants::class` - * @return class-string - */ - public static function className(): string - { - return PHP_VERSION_ID >= 8_01_00 - ? ObjectWithConstantsIncludingEnums::class - : ObjectWithConstants::class; - } } diff --git a/tests/Fixture/Object/ObjectWithConstantsIncludingEnums.php b/tests/Fixture/Object/ObjectWithConstantsIncludingEnums.php deleted file mode 100644 index 3ba298c3..00000000 --- a/tests/Fixture/Object/ObjectWithConstantsIncludingEnums.php +++ /dev/null @@ -1,14 +0,0 @@ - */ - public Countable&Iterator $someProperty; -} diff --git a/tests/Functional/Definition/Repository/Cache/Compiler/AttributesCompilerTest.php b/tests/Functional/Definition/Repository/Cache/Compiler/AttributesCompilerTest.php index b7a4db67..737c312d 100644 --- a/tests/Functional/Definition/Repository/Cache/Compiler/AttributesCompilerTest.php +++ b/tests/Functional/Definition/Repository/Cache/Compiler/AttributesCompilerTest.php @@ -47,11 +47,11 @@ public function test_compiles_attributes_for_class_with_attributes(): void self::assertTrue($attributes->has(BasicAttribute::class)); self::assertTrue($attributes->has(AttributeWithArguments::class)); - /** @var AttributeWithArguments $attribute */ $attribute = $attributes->filter( - fn (AttributeDefinition $attribute) => $attribute->class()->type()->className() === AttributeWithArguments::class + fn (AttributeDefinition $attribute) => $attribute->class->type->className() === AttributeWithArguments::class )->toArray()[0]->instantiate(); + /** @var AttributeWithArguments $attribute */ self::assertSame('foo', $attribute->foo); self::assertSame('bar', $attribute->bar); } @@ -66,9 +66,6 @@ public function test_compiles_attributes_for_class_without_attributes(): void self::assertSame(Attributes::empty(), $attributes); } - /** - * @requires PHP >= 8.1 - */ public function test_compiles_attributes_for_class_with_nested_attributes(): void { $reflection = new ReflectionClass(ObjectWithNestedAttributes::class); @@ -81,19 +78,19 @@ public function test_compiles_attributes_for_class_with_nested_attributes(): voi self::assertTrue($attributes->has(AttributeWithArguments::class)); self::assertTrue($attributes->has(NestedAttribute::class)); - /** @var AttributeWithArguments $attribute */ $attribute = $attributes->filter( - fn (AttributeDefinition $attribute) => $attribute->class()->type()->className() === AttributeWithArguments::class + fn (AttributeDefinition $attribute) => $attribute->class->type->className() === AttributeWithArguments::class )->toArray()[0]->instantiate(); + /** @var AttributeWithArguments $attribute */ self::assertSame('foo', $attribute->foo); self::assertSame('bar', $attribute->bar); - /** @var NestedAttribute $attribute */ $attribute = $attributes->filter( - fn (AttributeDefinition $attribute) => $attribute->class()->type()->className() === NestedAttribute::class + fn (AttributeDefinition $attribute) => $attribute->class->type->className() === NestedAttribute::class )->toArray()[0]->instantiate(); + /** @var NestedAttribute $attribute */ self::assertCount(2, $attribute->nestedAttributes); self::assertInstanceOf(BasicAttribute::class, $attribute->nestedAttributes[0]); self::assertInstanceOf(AttributeWithArguments::class, $attribute->nestedAttributes[1]); @@ -105,9 +102,6 @@ public function test_compiles_attributes_for_class_with_nested_attributes(): voi self::assertSame('bar', $nestedAttribute->bar); } - /** - * @requires PHP >= 8.1 - */ public function test_compiles_attributes_for_property_with_nested_attributes(): void { $reflection = new ReflectionProperty(ObjectWithNestedAttributes::class, 'property'); @@ -121,9 +115,6 @@ public function test_compiles_attributes_for_property_with_nested_attributes(): self::assertTrue($attributes->has(NestedAttribute::class)); } - /** - * @requires PHP >= 8.1 - */ public function test_compiles_attributes_for_method_with_nested_attributes(): void { $reflection = new ReflectionMethod(ObjectWithNestedAttributes::class, 'method'); diff --git a/tests/Functional/Definition/Repository/Cache/Compiler/ClassDefinitionCompilerTest.php b/tests/Functional/Definition/Repository/Cache/Compiler/ClassDefinitionCompilerTest.php index 14370f9c..69435158 100644 --- a/tests/Functional/Definition/Repository/Cache/Compiler/ClassDefinitionCompilerTest.php +++ b/tests/Functional/Definition/Repository/Cache/Compiler/ClassDefinitionCompilerTest.php @@ -7,7 +7,7 @@ use CuyZ\Valinor\Definition\ClassDefinition; use CuyZ\Valinor\Definition\Repository\Cache\Compiler\ClassDefinitionCompiler; use CuyZ\Valinor\Tests\Fake\Definition\FakeClassDefinition; -use CuyZ\Valinor\Tests\Fixture\Object\ObjectWithParameterDefaultObjectValue; +use CuyZ\Valinor\Tests\Fixture\Object\StringableObject; use CuyZ\Valinor\Type\Types\NativeStringType; use Error; use PHPUnit\Framework\TestCase; @@ -36,6 +36,11 @@ public static function method(string $parameter = 'Some parameter default value' { return $parameter . implode(' / ', $variadic); } + + public static function methodWithDefaultObjectValue(StringableObject $object = new StringableObject('bar')): StringableObject + { + return $object; + } }; $class = FakeClassDefinition::fromReflection(new ReflectionClass($object)); @@ -45,59 +50,49 @@ public static function method(string $parameter = 'Some parameter default value' self::assertInstanceOf(ClassDefinition::class, $class); - self::assertSame($className, $class->name()); - self::assertSame($className, $class->type()->className()); - self::assertFalse($class->isFinal()); - self::assertFalse($class->isAbstract()); + self::assertSame($className, $class->name); + self::assertSame($className, $class->type->className()); + self::assertFalse($class->isFinal); + self::assertFalse($class->isAbstract); - $properties = $class->properties(); + $properties = $class->properties; self::assertTrue($properties->has('property')); $property = $properties->get('property'); - self::assertSame('property', $property->name()); - self::assertSame('Signature::property', $property->signature()); - self::assertSame(NativeStringType::get(), $property->type()); - self::assertTrue($property->hasDefaultValue()); - self::assertSame('Some property default value', $property->defaultValue()); - self::assertTrue($property->isPublic()); - - $method = $class->methods()->get('method'); + self::assertSame('property', $property->name); + self::assertSame('Signature::property', $property->signature); + self::assertSame(NativeStringType::get(), $property->type); + self::assertTrue($property->hasDefaultValue); + self::assertSame('Some property default value', $property->defaultValue); + self::assertTrue($property->isPublic); - self::assertSame('method', $method->name()); - self::assertSame('Signature::method', $method->signature()); - self::assertTrue($method->isStatic()); - self::assertTrue($method->isPublic()); - self::assertSame(NativeStringType::get(), $method->returnType()); + $method = $class->methods->get('method'); - $parameter = $method->parameters()->get('parameter'); + self::assertSame('method', $method->name); + self::assertSame('Signature::method', $method->signature); + self::assertTrue($method->isStatic); + self::assertTrue($method->isPublic); + self::assertSame(NativeStringType::get(), $method->returnType); - self::assertSame('parameter', $parameter->name()); - self::assertSame('Signature::parameter', $parameter->signature()); - self::assertSame(NativeStringType::get(), $parameter->type()); - self::assertTrue($parameter->isOptional()); - self::assertFalse($parameter->isVariadic()); - self::assertSame('Some parameter default value', $parameter->defaultValue()); + $parameter = $method->parameters->get('parameter'); - $variadic = $method->parameters()->get('variadic'); + self::assertSame('parameter', $parameter->name); + self::assertSame('Signature::parameter', $parameter->signature); + self::assertSame(NativeStringType::get(), $parameter->type); + self::assertTrue($parameter->isOptional); + self::assertFalse($parameter->isVariadic); + self::assertSame('Some parameter default value', $parameter->defaultValue); - self::assertTrue($variadic->isVariadic()); - } + $variadic = $method->parameters->get('variadic'); - /** - * PHP8.1 move to test above - * - * @requires PHP >= 8.1 - */ - public function test_parameter_with_object_default_value_is_compiled_correctly(): void - { - $class = FakeClassDefinition::fromReflection(new ReflectionClass(ObjectWithParameterDefaultObjectValue::class)); + self::assertTrue($variadic->isVariadic); - $class = $this->eval($this->compiler->compile($class)); + $methodWithDefaultObjectValue = $class->methods->get('methodWithDefaultObjectValue'); + $parameterWithDefaultObjectValue = $methodWithDefaultObjectValue->parameters->get('object'); - self::assertInstanceOf(ClassDefinition::class, $class); - self::assertSame(ObjectWithParameterDefaultObjectValue::class, $class->name()); + self::assertInstanceOf(StringableObject::class, $parameterWithDefaultObjectValue->defaultValue); } public function test_final_class_is_compiled_correctly(): void @@ -107,7 +102,7 @@ public function test_final_class_is_compiled_correctly(): void $class = $this->eval($this->compiler->compile($class)); self::assertInstanceOf(ClassDefinition::class, $class); - self::assertTrue($class->isFinal()); + self::assertTrue($class->isFinal); } public function test_abstract_class_is_compiled_correctly(): void @@ -117,7 +112,7 @@ public function test_abstract_class_is_compiled_correctly(): void $class = $this->eval($this->compiler->compile($class)); self::assertInstanceOf(ClassDefinition::class, $class); - self::assertTrue($class->isAbstract()); + self::assertTrue($class->isAbstract); } private function eval(string $code): mixed diff --git a/tests/Functional/Definition/Repository/Cache/Compiler/FunctionDefinitionCompilerTest.php b/tests/Functional/Definition/Repository/Cache/Compiler/FunctionDefinitionCompilerTest.php index e3f727a1..fc5d3d29 100644 --- a/tests/Functional/Definition/Repository/Cache/Compiler/FunctionDefinitionCompilerTest.php +++ b/tests/Functional/Definition/Repository/Cache/Compiler/FunctionDefinitionCompilerTest.php @@ -53,14 +53,14 @@ public function test_function_is_compiled_correctly(): void $compiledFunction = $this->eval($code); self::assertInstanceOf(FunctionDefinition::class, $compiledFunction); - self::assertSame('foo', $compiledFunction->name()); - self::assertSame('foo:42-1337', $compiledFunction->signature()); - self::assertSame('foo/bar', $compiledFunction->fileName()); - self::assertSame(true, $compiledFunction->isStatic()); - self::assertSame(true, $compiledFunction->isClosure()); - self::assertSame(stdClass::class, $compiledFunction->class()); - self::assertTrue($compiledFunction->parameters()->has('bar')); - self::assertInstanceOf(NativeStringType::class, $compiledFunction->returnType()); + self::assertSame('foo', $compiledFunction->name); + self::assertSame('foo:42-1337', $compiledFunction->signature); + self::assertSame('foo/bar', $compiledFunction->fileName); + self::assertSame(true, $compiledFunction->isStatic); + self::assertSame(true, $compiledFunction->isClosure); + self::assertSame(stdClass::class, $compiledFunction->class); + self::assertTrue($compiledFunction->parameters->has('bar')); + self::assertInstanceOf(NativeStringType::class, $compiledFunction->returnType); } private function eval(string $code): \CuyZ\Valinor\Definition\FunctionDefinition|bool diff --git a/tests/Functional/Definition/Repository/Cache/Compiler/TypeCompilerTest.php b/tests/Functional/Definition/Repository/Cache/Compiler/TypeCompilerTest.php index 82a811d4..137b6841 100644 --- a/tests/Functional/Definition/Repository/Cache/Compiler/TypeCompilerTest.php +++ b/tests/Functional/Definition/Repository/Cache/Compiler/TypeCompilerTest.php @@ -102,12 +102,8 @@ public function type_is_compiled_correctly_data_provider(): iterable yield [new InterfaceType(DateTimeInterface::class, ['Template' => NativeStringType::get()])]; yield [new NativeClassType(stdClass::class, ['Template' => NativeStringType::get()])]; yield [new IntersectionType(new InterfaceType(DateTimeInterface::class), new NativeClassType(DateTime::class))]; - - if (PHP_VERSION_ID >= 8_01_00) { - yield [EnumType::native(PureEnum::class)]; - yield [EnumType::fromPattern(PureEnum::class, 'BA*')]; - } - + yield [EnumType::native(PureEnum::class)]; + yield [EnumType::fromPattern(PureEnum::class, 'BA*')]; yield [new UnionType(NativeStringType::get(), NativeIntegerType::get(), NativeFloatType::get())]; yield [ArrayType::native()]; yield [new ArrayType(ArrayKeyType::default(), NativeFloatType::get())]; diff --git a/tests/Functional/Type/Parser/Lexer/NativeLexerTest.php b/tests/Functional/Type/Parser/Lexer/NativeLexerTest.php index 20dcb4b9..51ec505c 100644 --- a/tests/Functional/Type/Parser/Lexer/NativeLexerTest.php +++ b/tests/Functional/Type/Parser/Lexer/NativeLexerTest.php @@ -876,13 +876,11 @@ public function parse_valid_types_returns_valid_result_data_provider(): iterable 'type' => UnionType::class, ]; - if (PHP_VERSION_ID >= 8_01_00) { - yield 'Union type with enum' => [ - 'raw' => PureEnum::class . '|' . BackedStringEnum::class, - 'transformed' => PureEnum::class . '|' . BackedStringEnum::class, - 'type' => UnionType::class, - ]; - } + yield 'Union type with enum' => [ + 'raw' => PureEnum::class . '|' . BackedStringEnum::class, + 'transformed' => PureEnum::class . '|' . BackedStringEnum::class, + 'type' => UnionType::class, + ]; yield 'Union type with class-string' => [ 'raw' => 'class-string|int', @@ -921,98 +919,94 @@ public function parse_valid_types_returns_valid_result_data_provider(): iterable ]; yield 'Class constant with string value' => [ - 'raw' => ObjectWithConstants::className() . '::CONST_WITH_STRING_VALUE_A', + 'raw' => ObjectWithConstants::class . '::CONST_WITH_STRING_VALUE_A', 'transformed' => "'some string value'", 'type' => StringValueType::class, ]; yield 'Class constant with integer value' => [ - 'raw' => ObjectWithConstants::className() . '::CONST_WITH_INTEGER_VALUE_A', + 'raw' => ObjectWithConstants::class . '::CONST_WITH_INTEGER_VALUE_A', 'transformed' => '1653398288', 'type' => IntegerValueType::class, ]; yield 'Class constant with float value' => [ - 'raw' => ObjectWithConstants::className() . '::CONST_WITH_FLOAT_VALUE_A', + 'raw' => ObjectWithConstants::class . '::CONST_WITH_FLOAT_VALUE_A', 'transformed' => '1337.42', 'type' => FloatValueType::class, ]; - if (PHP_VERSION_ID >= 8_01_00) { - yield 'Class constant with enum value' => [ - 'raw' => ObjectWithConstants::className() . '::CONST_WITH_ENUM_VALUE_A', - 'transformed' => BackedIntegerEnum::class . '::FOO', - 'type' => EnumType::class, - ]; - } + yield 'Class constant with enum value' => [ + 'raw' => ObjectWithConstants::class . '::CONST_WITH_ENUM_VALUE_A', + 'transformed' => BackedIntegerEnum::class . '::FOO', + 'type' => EnumType::class, + ]; yield 'Class constant with array value' => [ - 'raw' => ObjectWithConstants::className() . '::CONST_WITH_ARRAY_VALUE_A', + 'raw' => ObjectWithConstants::class . '::CONST_WITH_ARRAY_VALUE_A', 'transformed' => "array{string: 'some string value', integer: 1653398288, float: 1337.42}", 'type' => ShapedArrayType::class, ]; yield 'Class constant with nested array value' => [ - 'raw' => ObjectWithConstants::className() . '::CONST_WITH_NESTED_ARRAY_VALUE_A', + 'raw' => ObjectWithConstants::class . '::CONST_WITH_NESTED_ARRAY_VALUE_A', 'transformed' => "array{nested_array: array{string: 'some string value', integer: 1653398288, float: 1337.42}}", 'type' => ShapedArrayType::class, ]; - if (PHP_VERSION_ID >= 8_01_00) { - yield 'Pure enum' => [ - 'raw' => PureEnum::class, - 'transformed' => PureEnum::class, - 'type' => EnumType::class, - ]; - - yield 'Backed integer enum' => [ - 'raw' => BackedIntegerEnum::class, - 'transformed' => BackedIntegerEnum::class, - 'type' => EnumType::class, - ]; - - yield 'Backed string enum' => [ - 'raw' => BackedStringEnum::class, - 'transformed' => BackedStringEnum::class, - 'type' => EnumType::class, - ]; - - yield 'Pure enum value' => [ - 'raw' => PureEnum::class . '::FOO', - 'transformed' => PureEnum::class . '::FOO', - 'type' => EnumType::class, - ]; - - yield 'Backed integer enum value' => [ - 'raw' => BackedIntegerEnum::class . '::FOO', - 'transformed' => BackedIntegerEnum::class . '::FOO', - 'type' => EnumType::class, - ]; - - yield 'Backed string enum value' => [ - 'raw' => BackedStringEnum::class . '::FOO', - 'transformed' => BackedStringEnum::class . '::FOO', - 'type' => EnumType::class, - ]; - - yield 'Pure enum value with pattern with wildcard at the beginning' => [ - 'raw' => PureEnum::class . '::*OO', - 'transformed' => PureEnum::class . '::*OO', - 'type' => EnumType::class, - ]; - - yield 'Pure enum value with pattern with wildcard at the end' => [ - 'raw' => PureEnum::class . '::FO*', - 'transformed' => PureEnum::class . '::FO*', - 'type' => EnumType::class, - ]; - - yield 'Pure enum value with pattern with wildcard at the beginning and end' => [ - 'raw' => PureEnum::class . '::*A*', - 'transformed' => PureEnum::class . '::*A*', - 'type' => EnumType::class, - ]; - } + yield 'Pure enum' => [ + 'raw' => PureEnum::class, + 'transformed' => PureEnum::class, + 'type' => EnumType::class, + ]; + + yield 'Backed integer enum' => [ + 'raw' => BackedIntegerEnum::class, + 'transformed' => BackedIntegerEnum::class, + 'type' => EnumType::class, + ]; + + yield 'Backed string enum' => [ + 'raw' => BackedStringEnum::class, + 'transformed' => BackedStringEnum::class, + 'type' => EnumType::class, + ]; + + yield 'Pure enum value' => [ + 'raw' => PureEnum::class . '::FOO', + 'transformed' => PureEnum::class . '::FOO', + 'type' => EnumType::class, + ]; + + yield 'Backed integer enum value' => [ + 'raw' => BackedIntegerEnum::class . '::FOO', + 'transformed' => BackedIntegerEnum::class . '::FOO', + 'type' => EnumType::class, + ]; + + yield 'Backed string enum value' => [ + 'raw' => BackedStringEnum::class . '::FOO', + 'transformed' => BackedStringEnum::class . '::FOO', + 'type' => EnumType::class, + ]; + + yield 'Pure enum value with pattern with wildcard at the beginning' => [ + 'raw' => PureEnum::class . '::*OO', + 'transformed' => PureEnum::class . '::*OO', + 'type' => EnumType::class, + ]; + + yield 'Pure enum value with pattern with wildcard at the end' => [ + 'raw' => PureEnum::class . '::FO*', + 'transformed' => PureEnum::class . '::FO*', + 'type' => EnumType::class, + ]; + + yield 'Pure enum value with pattern with wildcard at the beginning and end' => [ + 'raw' => PureEnum::class . '::*A*', + 'transformed' => PureEnum::class . '::*A*', + 'type' => EnumType::class, + ]; } public function test_multiple_union_types_are_parsed(): void @@ -1365,9 +1359,6 @@ public function test_missing_closing_double_quote_throws_exception(): void $this->parser->parse('"foo'); } - /** - * @requires PHP >= 8.1 - */ public function test_missing_enum_case_throws_exception(): void { $this->expectException(MissingEnumCase::class); @@ -1377,9 +1368,6 @@ public function test_missing_enum_case_throws_exception(): void $this->parser->parse(PureEnum::class . '::'); } - /** - * @requires PHP >= 8.1 - */ public function test_no_enum_case_found_throws_exception(): void { $this->expectException(EnumCaseNotFound::class); @@ -1389,9 +1377,6 @@ public function test_no_enum_case_found_throws_exception(): void $this->parser->parse(PureEnum::class . '::ABC'); } - /** - * @requires PHP >= 8.1 - */ public function test_no_enum_case_found_with_wildcard_throws_exception(): void { $this->expectException(EnumCaseNotFound::class); @@ -1401,9 +1386,6 @@ public function test_no_enum_case_found_with_wildcard_throws_exception(): void $this->parser->parse(PureEnum::class . '::ABC*'); } - /** - * @requires PHP >= 8.1 - */ public function test_no_enum_case_found_with_several_wildcards_in_a_row_throws_exception(): void { $this->expectException(EnumCaseNotFound::class); @@ -1413,9 +1395,6 @@ public function test_no_enum_case_found_with_several_wildcards_in_a_row_throws_e $this->parser->parse(PureEnum::class . '::F**O'); } - /** - * @requires PHP >= 8.1 - */ public function test_missing_specific_enum_case_throws_exception(): void { $this->expectException(MissingSpecificEnumCase::class); @@ -1429,44 +1408,44 @@ public function test_missing_class_constant_case_throws_exception(): void { $this->expectException(MissingClassConstantCase::class); $this->expectExceptionCode(1664905018); - $this->expectExceptionMessage('Missing case name for class constant `' . ObjectWithConstants::className() . '::?`.'); + $this->expectExceptionMessage('Missing case name for class constant `' . ObjectWithConstants::class . '::?`.'); - $this->parser->parse(ObjectWithConstants::className() . '::'); + $this->parser->parse(ObjectWithConstants::class . '::'); } public function test_no_class_constant_case_found_throws_exception(): void { $this->expectException(ClassConstantCaseNotFound::class); $this->expectExceptionCode(1652189140); - $this->expectExceptionMessage('Unknown class constant case `' . ObjectWithConstants::className() . '::ABC`.'); + $this->expectExceptionMessage('Unknown class constant case `' . ObjectWithConstants::class . '::ABC`.'); - $this->parser->parse(ObjectWithConstants::className() . '::ABC'); + $this->parser->parse(ObjectWithConstants::class . '::ABC'); } public function test_no_class_constant_case_found_with_wildcard_throws_exception(): void { $this->expectException(ClassConstantCaseNotFound::class); $this->expectExceptionCode(1652189140); - $this->expectExceptionMessage('Cannot find class constant case with pattern `' . ObjectWithConstants::className() . '::ABC*`.'); + $this->expectExceptionMessage('Cannot find class constant case with pattern `' . ObjectWithConstants::class . '::ABC*`.'); - $this->parser->parse(ObjectWithConstants::className() . '::ABC*'); + $this->parser->parse(ObjectWithConstants::class . '::ABC*'); } public function test_no_class_constant_case_found_with_several_wildcards_in_a_row_throws_exception(): void { $this->expectException(ClassConstantCaseNotFound::class); $this->expectExceptionCode(1652189140); - $this->expectExceptionMessage('Cannot find class constant case with pattern `' . ObjectWithConstants::className() . '::F**O`.'); + $this->expectExceptionMessage('Cannot find class constant case with pattern `' . ObjectWithConstants::class . '::F**O`.'); - $this->parser->parse(ObjectWithConstants::className() . '::F**O'); + $this->parser->parse(ObjectWithConstants::class . '::F**O'); } public function test_missing_specific_class_constant_case_throws_exception(): void { $this->expectException(MissingSpecificClassConstantCase::class); $this->expectExceptionCode(1664904636); - $this->expectExceptionMessage('Missing specific case for class constant `' . ObjectWithConstants::className() . '::?` (cannot be `*`).'); + $this->expectExceptionMessage('Missing specific case for class constant `' . ObjectWithConstants::class . '::?` (cannot be `*`).'); - $this->parser->parse(ObjectWithConstants::className() . '::*'); + $this->parser->parse(ObjectWithConstants::class . '::*'); } } diff --git a/tests/Integration/Cache/CacheWarmupTest.php b/tests/Integration/Cache/CacheWarmupTest.php index 05307030..d5ac4ce3 100644 --- a/tests/Integration/Cache/CacheWarmupTest.php +++ b/tests/Integration/Cache/CacheWarmupTest.php @@ -56,10 +56,9 @@ public function test_will_warmup_type_parser_cache_for_object_with_properties(): public function test_will_warmup_type_parser_cache_for_object_with_constructor(): void { - // PHP8.1 first-class callable syntax $mapper = $this->mapper->registerConstructor( - [ObjectToWarmupWithConstructors::class, 'constructorA'], - [ObjectToWarmupWithConstructors::class, 'constructorB'], + ObjectToWarmupWithConstructors::constructorA(...), + ObjectToWarmupWithConstructors::constructorB(...), ); $mapper->warmup(ObjectToWarmupWithConstructors::class); diff --git a/tests/Integration/IntegrationTest.php b/tests/Integration/IntegrationTest.php index 90953b37..59b42d05 100644 --- a/tests/Integration/IntegrationTest.php +++ b/tests/Integration/IntegrationTest.php @@ -13,11 +13,7 @@ abstract class IntegrationTest extends TestCase { - /** - * PHP8.1 never - * @return never-return - */ - protected function mappingFail(MappingError $error) + protected function mappingFail(MappingError $error): never { $errorFinder = static function (Node $node, callable $errorFinder) { if ($node->isValid()) { diff --git a/tests/Integration/Mapping/Closure/ArgumentsMappingTest.php b/tests/Integration/Mapping/Closure/ArgumentsMappingTest.php index 78c9c99b..9d8373a4 100644 --- a/tests/Integration/Mapping/Closure/ArgumentsMappingTest.php +++ b/tests/Integration/Mapping/Closure/ArgumentsMappingTest.php @@ -31,8 +31,7 @@ public function test_can_map_to_class_method(): void $object = new SomeClassWithMethods(); try { - // PHP8.1 First-class callable syntax - $arguments = (new MapperBuilder())->argumentsMapper()->mapArguments([$object, 'somePublicMethod'], [ + $arguments = (new MapperBuilder())->argumentsMapper()->mapArguments($object->somePublicMethod(...), [ 'foo' => 'foo', 'bar' => 42, ]); @@ -46,8 +45,7 @@ public function test_can_map_to_class_method(): void public function test_can_map_to_class_static_method(): void { try { - // PHP8.1 First-class callable syntax - $arguments = (new MapperBuilder())->argumentsMapper()->mapArguments([SomeClassWithMethods::class, 'somePublicStaticMethod'], [ + $arguments = (new MapperBuilder())->argumentsMapper()->mapArguments(SomeClassWithMethods::somePublicStaticMethod(...), [ 'foo' => 'foo', 'bar' => 42, ]); diff --git a/tests/Integration/Mapping/ConstructorRegistrationMappingTest.php b/tests/Integration/Mapping/ConstructorRegistrationMappingTest.php index 20f2175c..878251a6 100644 --- a/tests/Integration/Mapping/ConstructorRegistrationMappingTest.php +++ b/tests/Integration/Mapping/ConstructorRegistrationMappingTest.php @@ -92,8 +92,7 @@ public function test_registered_named_constructor_is_used(): void { try { $result = (new MapperBuilder()) - // PHP8.1 first-class callable syntax - ->registerConstructor([SomeClassWithNamedConstructors::class, 'namedConstructor']) + ->registerConstructor(SomeClassWithNamedConstructors::namedConstructor(...)) ->mapper() ->map(SomeClassWithNamedConstructors::class, 'foo'); } catch (MappingError $error) { @@ -141,8 +140,7 @@ public function build(): stdClass try { $result = (new MapperBuilder()) - // PHP8.1 first-class callable syntax - ->registerConstructor([$constructor, 'build']) + ->registerConstructor($constructor->build(...)) ->mapper() ->map(stdClass::class, []); } catch (MappingError $error) { @@ -156,8 +154,7 @@ public function test_class_static_constructor_for_other_class_is_used(): void { try { $result = (new MapperBuilder()) - // PHP8.1 first-class callable syntax - ->registerConstructor([SomeClassWithStaticConstructorForOtherClass::class, 'from']) + ->registerConstructor(SomeClassWithStaticConstructorForOtherClass::from(...)) ->mapper() ->map(SimpleObject::class, 'foo'); } catch (MappingError $error) { @@ -262,8 +259,7 @@ public function test_native_constructor_is_not_called_if_not_registered_but_othe { try { $result = (new MapperBuilder()) - // PHP8.1 first-class callable syntax - ->registerConstructor([SomeClassWithSimilarNativeConstructorAndNamedConstructor::class, 'namedConstructor']) + ->registerConstructor(SomeClassWithSimilarNativeConstructorAndNamedConstructor::namedConstructor(...)) ->mapper() ->map(SomeClassWithSimilarNativeConstructorAndNamedConstructor::class, 'foo'); } catch (MappingError $error) { @@ -277,9 +273,8 @@ public function test_registered_native_constructor_is_called_if_registered_and_o { try { $result = (new MapperBuilder()) - // PHP8.1 first-class callable syntax ->registerConstructor(SomeClassWithDifferentNativeConstructorAndNamedConstructor::class) - ->registerConstructor([SomeClassWithDifferentNativeConstructorAndNamedConstructor::class, 'namedConstructor']) + ->registerConstructor(SomeClassWithDifferentNativeConstructorAndNamedConstructor::namedConstructor(...)) ->mapper() ->map(SomeClassWithDifferentNativeConstructorAndNamedConstructor::class, [ 'foo' => 'foo', @@ -464,8 +459,7 @@ public function test_inherited_static_constructor_is_used_to_map_child_class(): try { $result = (new MapperBuilder()) - // PHP8.1 First-class callable syntax - ->registerConstructor([SomeAbstractClassWithStaticConstructor::class, 'from']) + ->registerConstructor(SomeAbstractClassWithStaticConstructor::from(...)) ->mapper() ->map($class, [ 'someChild' => ['foo' => 'foo', 'bar' => 42], @@ -520,9 +514,9 @@ public function test_identical_registered_constructors_with_several_argument_thr (new MapperBuilder()) ->registerConstructor( - __NAMESPACE__ . '\constructorA', // PHP8.1 First-class callable syntax + constructorA(...), fn (int $other, float $arguments): stdClass => new stdClass(), - __NAMESPACE__ . '\constructorB', // PHP8.1 First-class callable syntax + constructorB(...), ) ->mapper() ->map(stdClass::class, []); diff --git a/tests/Integration/Mapping/EnumConstructorRegistrationMappingTest.php b/tests/Integration/Mapping/EnumConstructorRegistrationMappingTest.php index 1946a14b..67706143 100644 --- a/tests/Integration/Mapping/EnumConstructorRegistrationMappingTest.php +++ b/tests/Integration/Mapping/EnumConstructorRegistrationMappingTest.php @@ -7,9 +7,6 @@ use CuyZ\Valinor\Tests\Fixture\Enum\BackedStringEnum; use CuyZ\Valinor\Tests\Integration\IntegrationTest; -/** - * @requires PHP >= 8.1 - */ class EnumConstructorRegistrationMappingTest extends IntegrationTest { public function test_constructor_with_no_argument_is_called_when_no_value_is_given(): void @@ -122,8 +119,7 @@ public function test_register_internal_from_constructor_is_overridden_by_library { try { (new MapperBuilder()) - // PHP8.1 first-class callable syntax - ->registerConstructor([BackedStringEnum::class, 'from']) + ->registerConstructor(BackedStringEnum::from(...)) ->mapper() ->map(BackedStringEnum::class, 'fiz'); } catch (MappingError $exception) { @@ -138,8 +134,7 @@ public function test_register_internal_try_from_constructor_is_overridden_by_lib { try { (new MapperBuilder()) - // PHP8.1 first-class callable syntax - ->registerConstructor([BackedStringEnum::class, 'tryFrom']) + ->registerConstructor(BackedStringEnum::tryFrom(...)) ->mapper() ->map(BackedStringEnum::class, 'fiz'); } catch (MappingError $exception) { diff --git a/tests/Integration/Mapping/Fixture/ReadonlyValues.php b/tests/Integration/Mapping/Fixture/ReadonlyValues.php deleted file mode 100644 index 7abb5bc2..00000000 --- a/tests/Integration/Mapping/Fixture/ReadonlyValues.php +++ /dev/null @@ -1,11 +0,0 @@ -infer( SomeInterface::class, /** @return class-string|class-string */ - function (string $value): string { - // PHP8.0 match - if ($value === 'fooA') { - return SomeClassThatInheritsInterfaceA::class; - } - - return SomeClassThatInheritsInterfaceB::class; + fn (string $value) => match ($value) { + 'fooA' => SomeClassThatInheritsInterfaceA::class, + default => SomeClassThatInheritsInterfaceB::class, } )->mapper(); @@ -183,13 +179,11 @@ public function test_infer_with_two_functions_with_same_name_works_properly(): v $result = (new MapperBuilder()) ->infer( InterfaceA::class, - // PHP8.1 first-class callable syntax - [InterfaceAInferer::class, 'infer'] + InterfaceAInferer::infer(...) ) ->infer( InterfaceB::class, - // PHP8.1 first-class callable syntax - [InterfaceBInferer::class, 'infer'] + InterfaceBInferer::infer(...) ) ->mapper() ->map(ClassWithBothInterfaces::class, [ diff --git a/tests/Integration/Mapping/Namespace/RegisteredStaticConstructorWithReturnTypeInDocBlockTest.php b/tests/Integration/Mapping/Namespace/RegisteredStaticConstructorWithReturnTypeInDocBlockTest.php index 4701e77a..b7aba095 100644 --- a/tests/Integration/Mapping/Namespace/RegisteredStaticConstructorWithReturnTypeInDocBlockTest.php +++ b/tests/Integration/Mapping/Namespace/RegisteredStaticConstructorWithReturnTypeInDocBlockTest.php @@ -14,8 +14,7 @@ public function test_registered_static_constructor_with_return_type_in_doc_block { $result = (new MapperBuilder()) ->registerConstructor( - // PHP8.1 first-class callable syntax - [SomeClassWithStaticConstructor::class, 'staticConstructorWithReturnTypeInDocBlock'], + SomeClassWithStaticConstructor::staticConstructorWithReturnTypeInDocBlock(...), ) ->mapper() ->map(SomeClassWithStaticConstructor::class, 'foo'); diff --git a/tests/Integration/Mapping/Object/ConstantValuesMappingTest.php b/tests/Integration/Mapping/Object/ConstantValuesMappingTest.php index dff9342b..e868fbae 100644 --- a/tests/Integration/Mapping/Object/ConstantValuesMappingTest.php +++ b/tests/Integration/Mapping/Object/ConstantValuesMappingTest.php @@ -8,7 +8,6 @@ use CuyZ\Valinor\MapperBuilder; use CuyZ\Valinor\Tests\Fixture\Enum\BackedIntegerEnum; use CuyZ\Valinor\Tests\Fixture\Object\ObjectWithConstants; -use CuyZ\Valinor\Tests\Fixture\Object\ObjectWithConstantsIncludingEnums; use CuyZ\Valinor\Tests\Integration\IntegrationTest; final class ConstantValuesMappingTest extends IntegrationTest @@ -19,6 +18,7 @@ public function test_values_are_mapped_properly(): void 'constantStringValue' => 'another string value', 'constantIntegerValue' => 1653398289, 'constantFloatValue' => 404.512, + 'constantEnumValue' => BackedIntegerEnum::FOO, 'constantArrayValue' => [ 'string' => 'another string value', 'integer' => 1653398289, @@ -33,17 +33,7 @@ public function test_values_are_mapped_properly(): void ], ]; - // PHP8.1 remove condition - if (PHP_VERSION_ID >= 8_01_00) { - $source['constantEnumValue'] = BackedIntegerEnum::FOO; - } - - // PHP8.1 merge classes - $classes = PHP_VERSION_ID >= 8_01_00 - ? [ClassWithConstantValuesIncludingEnum::class, ClassWithConstantValuesIncludingEnumWithConstructor::class] - : [ClassWithConstantValues::class, ClassWithConstantValuesWithConstructor::class]; - - foreach ($classes as $class) { + foreach ([ClassWithConstantValues::class, ClassWithConstantValuesWithConstructor::class] as $class) { try { $result = (new MapperBuilder())->mapper()->map($class, $source); } catch (MappingError $error) { @@ -53,12 +43,7 @@ public function test_values_are_mapped_properly(): void self::assertSame('another string value', $result->constantStringValue); self::assertSame(1653398289, $result->constantIntegerValue); self::assertSame(404.512, $result->constantFloatValue); - - // PHP8.1 remove condition - if (PHP_VERSION_ID >= 8_01_00) { - /** @var ClassWithConstantValuesIncludingEnum $result */ - self::assertSame(BackedIntegerEnum::FOO, $result->constantEnumValue); - } + self::assertSame(BackedIntegerEnum::FOO, $result->constantEnumValue); self::assertSame([ 'string' => 'another string value', @@ -80,7 +65,7 @@ public function test_private_constant_cannot_be_mapped(): void try { (new MapperBuilder()) ->mapper() - ->map(ObjectWithConstants::className() . '::CONST_WITH_STRING_*', 'some private string value'); + ->map(ObjectWithConstants::class . '::CONST_WITH_STRING_*', 'some private string value'); } catch (MappingError $exception) { $error = $exception->node()->messages()[0]; @@ -94,7 +79,7 @@ public function test_constant_not_matching_pattern_cannot_be_mapped(): void try { (new MapperBuilder()) ->mapper() - ->map(ObjectWithConstants::className() . '::CONST_WITH_STRING_*', 'some prefixed string value'); + ->map(ObjectWithConstants::class . '::CONST_WITH_STRING_*', 'some prefixed string value'); } catch (MappingError $exception) { $error = $exception->node()->messages()[0]; @@ -115,6 +100,9 @@ class ClassWithConstantValues /** @var ObjectWithConstants::CONST_WITH_FLOAT_* */ public float $constantFloatValue; + /** @var ObjectWithConstants::CONST_WITH_ENUM_VALUE_* */ + public BackedIntegerEnum $constantEnumValue; + /** @var ObjectWithConstants::CONST_WITH_ARRAY_VALUE_* */ public array $constantArrayValue; @@ -122,43 +110,13 @@ class ClassWithConstantValues public array $constantNestedArrayValue; } -class ClassWithConstantValuesIncludingEnum extends ClassWithConstantValues -{ - /** @var ObjectWithConstantsIncludingEnums::CONST_WITH_ENUM_VALUE_* */ - public BackedIntegerEnum $constantEnumValue; -} - final class ClassWithConstantValuesWithConstructor extends ClassWithConstantValues { /** * @param ObjectWithConstants::CONST_WITH_STRING_* $constantStringValue * @param ObjectWithConstants::CONST_WITH_INTEGER_* $constantIntegerValue * @param ObjectWithConstants::CONST_WITH_FLOAT_* $constantFloatValue - * @param ObjectWithConstants::CONST_WITH_ARRAY_VALUE_* $constantArrayValue - * @param ObjectWithConstants::CONST_WITH_NESTED_ARRAY_VALUE_* $constantNestedArrayValue - */ - public function __construct( - string $constantStringValue, - int $constantIntegerValue, - float $constantFloatValue, - array $constantArrayValue, - array $constantNestedArrayValue - ) { - $this->constantStringValue = $constantStringValue; - $this->constantIntegerValue = $constantIntegerValue; - $this->constantFloatValue = $constantFloatValue; - $this->constantArrayValue = $constantArrayValue; - $this->constantNestedArrayValue = $constantNestedArrayValue; - } -} - -final class ClassWithConstantValuesIncludingEnumWithConstructor extends ClassWithConstantValuesIncludingEnum -{ - /** - * @param ObjectWithConstants::CONST_WITH_STRING_* $constantStringValue - * @param ObjectWithConstants::CONST_WITH_INTEGER_* $constantIntegerValue - * @param ObjectWithConstants::CONST_WITH_FLOAT_* $constantFloatValue - * @param ObjectWithConstantsIncludingEnums::CONST_WITH_ENUM_VALUE_* $constantEnumValue + * @param ObjectWithConstants::CONST_WITH_ENUM_VALUE_* $constantEnumValue * @param ObjectWithConstants::CONST_WITH_ARRAY_VALUE_* $constantArrayValue * @param ObjectWithConstants::CONST_WITH_NESTED_ARRAY_VALUE_* $constantNestedArrayValue */ diff --git a/tests/Integration/Mapping/Object/EnumValuesMappingTest.php b/tests/Integration/Mapping/Object/EnumValuesMappingTest.php index c106f404..be6eb644 100644 --- a/tests/Integration/Mapping/Object/EnumValuesMappingTest.php +++ b/tests/Integration/Mapping/Object/EnumValuesMappingTest.php @@ -12,9 +12,6 @@ use CuyZ\Valinor\Tests\Fixture\Object\StringableObject; use CuyZ\Valinor\Tests\Integration\IntegrationTest; -/** - * @requires PHP >= 8.1 - */ final class EnumValuesMappingTest extends IntegrationTest { public function test_values_are_mapped_properly(): void diff --git a/tests/Integration/Mapping/Object/UnionOfObjectsMappingTest.php b/tests/Integration/Mapping/Object/UnionOfObjectsMappingTest.php index 0b53b718..24815dbf 100644 --- a/tests/Integration/Mapping/Object/UnionOfObjectsMappingTest.php +++ b/tests/Integration/Mapping/Object/UnionOfObjectsMappingTest.php @@ -14,9 +14,8 @@ public function test_objects_sharing_one_property_are_resolved_correctly(): void { try { $result = (new MapperBuilder()) - // PHP8.1 first-class callable syntax - ->registerConstructor([SomeFooAndBarObject::class, 'constructorA']) - ->registerConstructor([SomeFooAndBarObject::class, 'constructorB']) + ->registerConstructor(SomeFooAndBarObject::constructorA(...)) + ->registerConstructor(SomeFooAndBarObject::constructorB(...)) ->mapper() ->map(UnionOfFooAndBarAndFoo::class, [ 'foo', @@ -84,46 +83,39 @@ public function mapping_error_when_cannot_resolve_union_data_provider(): iterabl } } -// PHP8.1 Readonly properties final class UnionOfFooAndBar { /** @var array */ public array $objects; } -// PHP8.1 Readonly properties final class UnionOfFooAndAnotherFoo { /** @var array */ public array $objects; } -// PHP8.1 Readonly properties final class UnionOfFooAndBarAndFoo { /** @var array */ public array $objects; } -// PHP8.1 Readonly properties final class SomeFooObject { public string $foo; } -// PHP8.1 Readonly properties final class SomeOtherFooObject { public string $foo; } -// PHP8.1 Readonly properties final class SomeBarObject { public string $bar; } -// PHP8.1 Readonly properties final class SomeFooAndBarObject { public string $foo; diff --git a/tests/Integration/Mapping/Other/FlexibleCastingMappingTest.php b/tests/Integration/Mapping/Other/FlexibleCastingMappingTest.php index fb09d16a..b8304256 100644 --- a/tests/Integration/Mapping/Other/FlexibleCastingMappingTest.php +++ b/tests/Integration/Mapping/Other/FlexibleCastingMappingTest.php @@ -119,9 +119,6 @@ public function test_shaped_array_is_mapped_correctly(): void self::assertSame(['foo', 'foo' => 42], $result); } - /** - * @requires PHP >= 8.1 - */ public function test_string_enum_is_cast_correctly(): void { try { @@ -133,9 +130,6 @@ public function test_string_enum_is_cast_correctly(): void self::assertSame(BackedStringEnum::FOO, $result); } - /** - * @requires PHP >= 8.1 - */ public function test_integer_enum_is_cast_correctly(): void { try { diff --git a/tests/Integration/Mapping/Other/StrictMappingTest.php b/tests/Integration/Mapping/Other/StrictMappingTest.php index d379b446..2c54a268 100644 --- a/tests/Integration/Mapping/Other/StrictMappingTest.php +++ b/tests/Integration/Mapping/Other/StrictMappingTest.php @@ -138,9 +138,6 @@ public function test_invalid_integer_range_throws_exception(): void } } - /** - * @requires PHP >= 8.1 - */ public function test_invalid_enum_value_throws_exception(): void { try { @@ -152,9 +149,6 @@ public function test_invalid_enum_value_throws_exception(): void } } - /** - * @requires PHP >= 8.1 - */ public function test_invalid_string_enum_value_throws_exception(): void { try { @@ -166,9 +160,6 @@ public function test_invalid_string_enum_value_throws_exception(): void } } - /** - * @requires PHP >= 8.1 - */ public function test_invalid_integer_enum_value_throws_exception(): void { try { diff --git a/tests/Integration/Mapping/Other/SuperfluousKeysMappingTest.php b/tests/Integration/Mapping/Other/SuperfluousKeysMappingTest.php index 7d7592c6..e3824de9 100644 --- a/tests/Integration/Mapping/Other/SuperfluousKeysMappingTest.php +++ b/tests/Integration/Mapping/Other/SuperfluousKeysMappingTest.php @@ -70,20 +70,17 @@ public function test_single_property_node_can_be_mapped_with_superfluous_key(): } } -// PHP8.1 Readonly properties final class UnionOfBarAndFizAndFoo { /** @var array */ public array $objects; } -// PHP8.1 Readonly properties final class SomeFooObject { public string $foo; } -// PHP8.1 Readonly properties final class SomeBarAndFizObject { public string $bar; diff --git a/tests/Integration/Mapping/ReadonlyMappingTest.php b/tests/Integration/Mapping/ReadonlyMappingTest.php index 01d82baf..14124976 100644 --- a/tests/Integration/Mapping/ReadonlyMappingTest.php +++ b/tests/Integration/Mapping/ReadonlyMappingTest.php @@ -7,17 +7,17 @@ use CuyZ\Valinor\Mapper\MappingError; use CuyZ\Valinor\MapperBuilder; use CuyZ\Valinor\Tests\Integration\IntegrationTest; -use CuyZ\Valinor\Tests\Integration\Mapping\Fixture\ReadonlyValues; -/** - * @requires PHP >= 8.1 - */ final class ReadonlyMappingTest extends IntegrationTest { public function test_single_property_and_constructor_parameter_are_mapped_properly(): void { + $class = new class () { + public readonly string $value; // @phpstan-ignore-line + }; + try { - $object = (new MapperBuilder())->mapper()->map(ReadonlyValues::class, 'foo'); + $object = (new MapperBuilder())->mapper()->map($class::class, 'foo'); } catch (MappingError $error) { $this->mappingFail($error); } diff --git a/tests/Integration/Mapping/VariadicParameterMappingTest.php b/tests/Integration/Mapping/VariadicParameterMappingTest.php index 031b0706..05e3b57c 100644 --- a/tests/Integration/Mapping/VariadicParameterMappingTest.php +++ b/tests/Integration/Mapping/VariadicParameterMappingTest.php @@ -68,8 +68,7 @@ public function test_named_constructor_with_non_variadic_and_variadic_parameters { try { $object = (new MapperBuilder()) - // PHP8.1 first-class callable syntax - ->registerConstructor([SomeClassWithNamedConstructorWithNonVariadicAndVariadicParameters::class, 'new']) + ->registerConstructor(SomeClassWithNamedConstructorWithNonVariadicAndVariadicParameters::new(...)) ->mapper() ->map(SomeClassWithNamedConstructorWithNonVariadicAndVariadicParameters::class, [ 'int' => 42, diff --git a/tests/Integration/Normalizer/CommonExamples/ObjectKeysToSnakeCaseFromAttributeTest.php b/tests/Integration/Normalizer/CommonExamples/ObjectKeysToSnakeCaseFromAttributeTest.php index a101b427..a9ec34a2 100644 --- a/tests/Integration/Normalizer/CommonExamples/ObjectKeysToSnakeCaseFromAttributeTest.php +++ b/tests/Integration/Normalizer/CommonExamples/ObjectKeysToSnakeCaseFromAttributeTest.php @@ -41,7 +41,7 @@ public function normalize(object $object, callable $next): array $result = []; foreach ($next() as $key => $value) { - $newKey = strtolower(preg_replace('/[A-Z]/', '_$0', lcfirst($key)) ?? ''); + $newKey = strtolower(preg_replace('/[A-Z]/', '_$0', lcfirst((string)$key)) ?? ''); $result[$newKey] = $value; } diff --git a/tests/Integration/Normalizer/CommonExamples/ObjectKeysToSnakeCaseTest.php b/tests/Integration/Normalizer/CommonExamples/ObjectKeysToSnakeCaseTest.php index 3256f284..336053a8 100644 --- a/tests/Integration/Normalizer/CommonExamples/ObjectKeysToSnakeCaseTest.php +++ b/tests/Integration/Normalizer/CommonExamples/ObjectKeysToSnakeCaseTest.php @@ -18,7 +18,7 @@ function (object $object, callable $next) { $result = []; foreach ($next() as $key => $value) { - $newKey = strtolower(preg_replace('/[A-Z]/', '_$0', lcfirst($key)) ?? ''); + $newKey = strtolower(preg_replace('/[A-Z]/', '_$0', lcfirst((string)$key)) ?? ''); $result[$newKey] = $value; } diff --git a/tests/Integration/Normalizer/CommonExamples/UppercaseFromAttributeTest.php b/tests/Integration/Normalizer/CommonExamples/UppercaseFromAttributeTest.php index a066882d..43adf949 100644 --- a/tests/Integration/Normalizer/CommonExamples/UppercaseFromAttributeTest.php +++ b/tests/Integration/Normalizer/CommonExamples/UppercaseFromAttributeTest.php @@ -34,6 +34,6 @@ final class Uppercase { public function normalize(string $value, callable $next): string { - return strtoupper($next()); + return strtoupper((string)$next()); } } diff --git a/tests/Integration/Normalizer/NormalizerTest.php b/tests/Integration/Normalizer/NormalizerTest.php index 6d0dee31..d59bcc4c 100644 --- a/tests/Integration/Normalizer/NormalizerTest.php +++ b/tests/Integration/Normalizer/NormalizerTest.php @@ -185,25 +185,23 @@ public function normalize_basic_values_yields_expected_output_data_provider(): i 'expected json' => '{"foo":{"value":"foo"},"bar":{"value":"bar"}}', ]; - if (PHP_VERSION_ID >= 8_01_00) { - yield 'unit enum' => [ - 'input' => PureEnum::FOO, - 'expected array' => 'FOO', - 'expected json' => '"FOO"', - ]; - - yield 'backed string enum' => [ - 'input' => BackedStringEnum::FOO, - 'expected array' => 'foo', - 'expected json' => '"foo"', - ]; - - yield 'backed integer enum' => [ - 'input' => BackedIntegerEnum::FOO, - 'expected array' => 42, - 'expected json' => '42', - ]; - } + yield 'unit enum' => [ + 'input' => PureEnum::FOO, + 'expected array' => 'FOO', + 'expected json' => '"FOO"', + ]; + + yield 'backed string enum' => [ + 'input' => BackedStringEnum::FOO, + 'expected array' => 'foo', + 'expected json' => '"foo"', + ]; + + yield 'backed integer enum' => [ + 'input' => BackedIntegerEnum::FOO, + 'expected array' => 42, + 'expected json' => '42', + ]; yield 'class with public properties' => [ 'input' => new class () { diff --git a/tests/StaticAnalysis/inferring-types-with-plugin.php b/tests/StaticAnalysis/inferring-types-with-plugin.php index c081e2a7..ef9dd07e 100644 --- a/tests/StaticAnalysis/inferring-types-with-plugin.php +++ b/tests/StaticAnalysis/inferring-types-with-plugin.php @@ -53,8 +53,7 @@ function mapping_function_arguments_will_infer_object_of_same_type(ArgumentsMapp function mapping_static_method_arguments_will_infer_object_of_same_type(ArgumentsMapper $mapper): void { - // PHP8.1 First-class callable syntax - $result = $mapper->mapArguments(Closure::fromCallable([SomeClass::class, 'someStaticMethod']), []); + $result = $mapper->mapArguments(Closure::fromCallable(SomeClass::someStaticMethod(...)), []); /** @psalm-check-type $result = array{foo: string, bar?: int|null} */ assertType('array{foo: string, bar?: int|null}', $result); @@ -62,8 +61,7 @@ function mapping_static_method_arguments_will_infer_object_of_same_type(Argument function mapping_method_arguments_will_infer_object_of_same_type(ArgumentsMapper $mapper): void { - // PHP8.1 First-class callable syntax - $result = $mapper->mapArguments(Closure::fromCallable([new SomeClass(), 'someMethod']), []); + $result = $mapper->mapArguments(Closure::fromCallable((new SomeClass())->someMethod(...)), []); /** @psalm-check-type $result = array{foo: string, bar?: int|null} */ assertType('array{foo: string, bar?: int|null}', $result); diff --git a/tests/Unit/Cache/Compiled/FileWatchingCacheTest.php b/tests/Unit/Cache/Compiled/FileWatchingCacheTest.php index 55084adc..4bfe12f7 100644 --- a/tests/Unit/Cache/Compiled/FileWatchingCacheTest.php +++ b/tests/Unit/Cache/Compiled/FileWatchingCacheTest.php @@ -16,8 +16,6 @@ use ReflectionClass; use stdClass; -use function iterator_to_array; - final class FileWatchingCacheTest extends TestCase { private vfsStreamDirectory $files; @@ -115,8 +113,7 @@ public function test_multiple_values_set_can_be_fetched_and_deleted(): void self::assertTrue($this->cache->has('foo')); self::assertTrue($this->cache->has('bar')); - // PHP8.1 array unpacking - self::assertEquals($values, iterator_to_array($this->cache->getMultiple(['foo', 'bar']))); // @phpstan-ignore-line + self::assertEquals($values, [...$this->cache->getMultiple(['foo', 'bar'])]); self::assertTrue($this->cache->deleteMultiple(['foo', 'bar'])); diff --git a/tests/Unit/Cache/FileSystemCacheTest.php b/tests/Unit/Cache/FileSystemCacheTest.php index 1363f152..11824d55 100644 --- a/tests/Unit/Cache/FileSystemCacheTest.php +++ b/tests/Unit/Cache/FileSystemCacheTest.php @@ -74,8 +74,8 @@ public function test_cache_entries_are_handled_properly(): void /** @var FunctionDefinition $cachedFunctionDefinition */ $cachedFunctionDefinition = $this->cache->get('function-definition'); - self::assertSame($classDefinition->name(), $cachedClassDefinition->name()); - self::assertSame($functionDefinition->signature(), $cachedFunctionDefinition->signature()); + self::assertSame($classDefinition->name, $cachedClassDefinition->name); + self::assertSame($functionDefinition->signature, $cachedFunctionDefinition->signature); self::assertTrue($this->cache->delete('class-definition')); self::assertTrue($this->cache->delete('function-definition')); @@ -118,8 +118,8 @@ public function test_multiple_cache_entries_are_handled_properly(): void /** @var FunctionDefinition $cachedFunctionDefinition */ $cachedFunctionDefinition = $cached['function-definition']; - self::assertSame($classDefinition->name(), $cachedClassDefinition->name()); - self::assertSame($functionDefinition->signature(), $cachedFunctionDefinition->signature()); + self::assertSame($classDefinition->name, $cachedClassDefinition->name); + self::assertSame($functionDefinition->signature, $cachedFunctionDefinition->signature); self::assertTrue($this->cache->deleteMultiple(['class-definition', 'function-definition'])); diff --git a/tests/Unit/Definition/AttributesTest.php b/tests/Unit/Definition/AttributesTest.php index 31b052a3..c72272b8 100644 --- a/tests/Unit/Definition/AttributesTest.php +++ b/tests/Unit/Definition/AttributesTest.php @@ -64,7 +64,7 @@ public function test_attributes_of_type_filters_on_given_class_name(): void $attributeB = FakeAttributeDefinition::new(DateTimeImmutable::class); $attributes = new Attributes($attributeA, $attributeB); - $filteredAttributes = $attributes->filter(fn (AttributeDefinition $attribute) => $attribute->class()->type()->className() === DateTimeImmutable::class); + $filteredAttributes = $attributes->filter(fn (AttributeDefinition $attribute) => $attribute->class->type->className() === DateTimeImmutable::class); self::assertContainsEquals($attributeB, $filteredAttributes); self::assertNotContains($attributeA, $filteredAttributes); diff --git a/tests/Unit/Definition/ClassDefinitionTest.php b/tests/Unit/Definition/ClassDefinitionTest.php index 6a9909a9..139f3a6a 100644 --- a/tests/Unit/Definition/ClassDefinitionTest.php +++ b/tests/Unit/Definition/ClassDefinitionTest.php @@ -24,14 +24,14 @@ public function test_class_data_can_be_retrieved(): void $properties = new Properties(FakePropertyDefinition::new()); $methods = new Methods(FakeMethodDefinition::new()); - $class = new ClassDefinition($type, $attributes, $properties, $methods, true, false); + $class = new ClassDefinition(stdClass::class, $type, $attributes, $properties, $methods, true, false); - self::assertSame(stdClass::class, $class->name()); - self::assertSame($type, $class->type()); - self::assertSame($attributes, $class->attributes()); - self::assertSame($properties, $class->properties()); - self::assertSame($methods, $class->methods()); - self::assertSame(true, $class->isFinal()); - self::assertSame(false, $class->isAbstract()); + self::assertSame(stdClass::class, $class->name); + self::assertSame($type, $class->type); + self::assertSame($attributes, $class->attributes); + self::assertSame($properties, $class->properties); + self::assertSame($methods, $class->methods); + self::assertSame(true, $class->isFinal); + self::assertSame(false, $class->isAbstract); } } diff --git a/tests/Unit/Definition/MethodDefinitionTest.php b/tests/Unit/Definition/MethodDefinitionTest.php index 8c12da4a..76656f16 100644 --- a/tests/Unit/Definition/MethodDefinitionTest.php +++ b/tests/Unit/Definition/MethodDefinitionTest.php @@ -30,11 +30,11 @@ public function test_method_data_can_be_retrieved(): void $returnType ); - self::assertSame($name, $method->name()); - self::assertSame($signature, $method->signature()); - self::assertSame($parameters, $method->parameters()); - self::assertSame($isStatic, $method->isStatic()); - self::assertSame($isPublic, $method->isPublic()); - self::assertSame($returnType, $method->returnType()); + self::assertSame($name, $method->name); + self::assertSame($signature, $method->signature); + self::assertSame($parameters, $method->parameters); + self::assertSame($isStatic, $method->isStatic); + self::assertSame($isPublic, $method->isPublic); + self::assertSame($returnType, $method->returnType); } } diff --git a/tests/Unit/Definition/MethodsTest.php b/tests/Unit/Definition/MethodsTest.php index af6bb726..2364881f 100644 --- a/tests/Unit/Definition/MethodsTest.php +++ b/tests/Unit/Definition/MethodsTest.php @@ -23,8 +23,8 @@ public function test_method_can_be_found(): void self::assertFalse($methods->has('unknownMethod')); self::assertFalse($methods->hasConstructor()); - self::assertTrue($methods->has($method->name())); - self::assertSame($method, $methods->get($method->name())); + self::assertTrue($methods->has($method->name)); + self::assertSame($method, $methods->get($method->name)); } public function test_constructor_is_found(): void diff --git a/tests/Unit/Definition/ParameterDefinitionTest.php b/tests/Unit/Definition/ParameterDefinitionTest.php index 2f51ff7c..70d5e443 100644 --- a/tests/Unit/Definition/ParameterDefinitionTest.php +++ b/tests/Unit/Definition/ParameterDefinitionTest.php @@ -31,12 +31,12 @@ public function test_parameter_data_can_be_retrieved(): void $attributes ); - self::assertSame($name, $parameter->name()); - self::assertSame($signature, $parameter->signature()); - self::assertSame($type, $parameter->type()); - self::assertSame($isOptional, $parameter->isOptional()); - self::assertSame($isVariadic, $parameter->isVariadic()); - self::assertSame($defaultValue, $parameter->defaultValue()); - self::assertSame($attributes, $parameter->attributes()); + self::assertSame($name, $parameter->name); + self::assertSame($signature, $parameter->signature); + self::assertSame($type, $parameter->type); + self::assertSame($isOptional, $parameter->isOptional); + self::assertSame($isVariadic, $parameter->isVariadic); + self::assertSame($defaultValue, $parameter->defaultValue); + self::assertSame($attributes, $parameter->attributes); } } diff --git a/tests/Unit/Definition/ParametersTest.php b/tests/Unit/Definition/ParametersTest.php index fb05589d..39a3b072 100644 --- a/tests/Unit/Definition/ParametersTest.php +++ b/tests/Unit/Definition/ParametersTest.php @@ -22,8 +22,8 @@ public function test_parameter_can_be_found(): void self::assertFalse($parameters->has('unknownParameter')); - self::assertTrue($parameters->has($parameter->name())); - self::assertSame($parameter, $parameters->get($parameter->name())); + self::assertTrue($parameters->has($parameter->name)); + self::assertSame($parameter, $parameters->get($parameter->name)); } public function test_get_parameter_at_index_returns_correct_parameter(): void diff --git a/tests/Unit/Definition/PropertiesTest.php b/tests/Unit/Definition/PropertiesTest.php index 9a085deb..f3cb52b7 100644 --- a/tests/Unit/Definition/PropertiesTest.php +++ b/tests/Unit/Definition/PropertiesTest.php @@ -22,8 +22,8 @@ public function test_property_can_be_found(): void self::assertFalse($properties->has('unknownProperty')); - self::assertTrue($properties->has($property->name())); - self::assertSame($property, $properties->get($property->name())); + self::assertTrue($properties->has($property->name)); + self::assertSame($property, $properties->get($property->name)); } public function test_properties_are_countable(): void diff --git a/tests/Unit/Definition/PropertyDefinitionTest.php b/tests/Unit/Definition/PropertyDefinitionTest.php index 29b40268..eae94171 100644 --- a/tests/Unit/Definition/PropertyDefinitionTest.php +++ b/tests/Unit/Definition/PropertyDefinitionTest.php @@ -31,12 +31,12 @@ public function test_property_data_can_be_retrieved(): void $attributes ); - self::assertSame($name, $property->name()); - self::assertSame($signature, $property->signature()); - self::assertSame($type, $property->type()); - self::assertSame($hasDefaultValue, $property->hasDefaultValue()); - self::assertSame($defaultValue, $property->defaultValue()); - self::assertSame($isPublic, $property->isPublic()); - self::assertSame($attributes, $property->attributes()); + self::assertSame($name, $property->name); + self::assertSame($signature, $property->signature); + self::assertSame($type, $property->type); + self::assertSame($hasDefaultValue, $property->hasDefaultValue); + self::assertSame($defaultValue, $property->defaultValue); + self::assertSame($isPublic, $property->isPublic); + self::assertSame($attributes, $property->attributes); } } diff --git a/tests/Unit/Definition/Repository/Reflection/ReflectionClassDefinitionRepositoryTest.php b/tests/Unit/Definition/Repository/Reflection/ReflectionClassDefinitionRepositoryTest.php index 6ff74256..b22efb4a 100644 --- a/tests/Unit/Definition/Repository/Reflection/ReflectionClassDefinitionRepositoryTest.php +++ b/tests/Unit/Definition/Repository/Reflection/ReflectionClassDefinitionRepositoryTest.php @@ -52,23 +52,23 @@ public function test_properties_can_be_retrieved(): void }; $type = new NativeClassType($object::class); - $properties = $this->repository->for($type)->properties(); + $properties = $this->repository->for($type)->properties; - self::assertTrue($properties->get('propertyWithDefaultValue')->hasDefaultValue()); - self::assertSame('Default value for property', $properties->get('propertyWithDefaultValue')->defaultValue()); + self::assertTrue($properties->get('propertyWithDefaultValue')->hasDefaultValue); + self::assertSame('Default value for property', $properties->get('propertyWithDefaultValue')->defaultValue); - self::assertInstanceOf(NativeBooleanType::class, $properties->get('propertyWithDocBlockType')->type()); + self::assertInstanceOf(NativeBooleanType::class, $properties->get('propertyWithDocBlockType')->type); - self::assertInstanceOf(MixedType::class, $properties->get('propertyWithNoType')->type()); + self::assertInstanceOf(MixedType::class, $properties->get('propertyWithNoType')->type); - self::assertInstanceOf(StringType::class, $properties->get('publicProperty')->type()); - self::assertTrue($properties->get('publicProperty')->isPublic()); + self::assertInstanceOf(StringType::class, $properties->get('publicProperty')->type); + self::assertTrue($properties->get('publicProperty')->isPublic); - self::assertInstanceOf(StringType::class, $properties->get('protectedProperty')->type()); - self::assertFalse($properties->get('protectedProperty')->isPublic()); + self::assertInstanceOf(StringType::class, $properties->get('protectedProperty')->type); + self::assertFalse($properties->get('protectedProperty')->isPublic); - self::assertInstanceOf(NativeBooleanType::class, $properties->get('privateProperty')->type()); - self::assertFalse($properties->get('privateProperty')->isPublic()); + self::assertInstanceOf(NativeBooleanType::class, $properties->get('privateProperty')->type); + self::assertFalse($properties->get('privateProperty')->isPublic); } public function test_methods_can_be_retrieved(): void @@ -108,15 +108,15 @@ public function publicMethodWithNativeAndDocBlockReturnTypes(): string $className = $object::class; $type = new NativeClassType($className); - $methods = $this->repository->for($type)->methods(); + $methods = $this->repository->for($type)->methods; self::assertTrue($methods->hasConstructor()); - self::assertInstanceOf(StringType::class, $methods->get('publicMethodWithReturnType')->returnType()); - self::assertInstanceOf(StringType::class, $methods->get('publicMethodWithDocBlockReturnType')->returnType()); - self::assertInstanceOf(StringType::class, $methods->get('publicMethodWithNativeAndDocBlockReturnTypes')->returnType()); + self::assertInstanceOf(StringType::class, $methods->get('publicMethodWithReturnType')->returnType); + self::assertInstanceOf(StringType::class, $methods->get('publicMethodWithDocBlockReturnType')->returnType); + self::assertInstanceOf(StringType::class, $methods->get('publicMethodWithNativeAndDocBlockReturnTypes')->returnType); - $parameters = $methods->get('publicMethod')->parameters(); + $parameters = $methods->get('publicMethod')->parameters; self::assertTrue($parameters->has('mandatoryParameter')); self::assertTrue($parameters->has('parameterWithNoType')); @@ -128,26 +128,26 @@ public function publicMethodWithNativeAndDocBlockReturnTypes(): string $parameterWithDocBlockType = $parameters->get('parameterWithDocBlockType'); $optionalParameter = $parameters->get('optionalParameter'); - self::assertSame($className . '::publicMethod($mandatoryParameter)', $mandatoryParameter->signature()); - self::assertSame($className . '::publicMethod($parameterWithNoType)', $parameterWithNoType->signature()); - self::assertSame($className . '::publicMethod($parameterWithDocBlockType)', $parameterWithDocBlockType->signature()); - self::assertSame($className . '::publicMethod($optionalParameter)', $optionalParameter->signature()); + self::assertSame($className . '::publicMethod($mandatoryParameter)', $mandatoryParameter->signature); + self::assertSame($className . '::publicMethod($parameterWithNoType)', $parameterWithNoType->signature); + self::assertSame($className . '::publicMethod($parameterWithDocBlockType)', $parameterWithDocBlockType->signature); + self::assertSame($className . '::publicMethod($optionalParameter)', $optionalParameter->signature); - self::assertInstanceOf(NativeBooleanType::class, $mandatoryParameter->type()); - self::assertFalse($mandatoryParameter->isOptional()); + self::assertInstanceOf(NativeBooleanType::class, $mandatoryParameter->type); + self::assertFalse($mandatoryParameter->isOptional); - self::assertInstanceOf(MixedType::class, $parameterWithNoType->type()); + self::assertInstanceOf(MixedType::class, $parameterWithNoType->type); - self::assertInstanceOf(StringType::class, $parameterWithDocBlockType->type()); + self::assertInstanceOf(StringType::class, $parameterWithDocBlockType->type); - self::assertTrue($parameters->get('optionalParameter')->isOptional()); - self::assertSame('Optional parameter value', $optionalParameter->defaultValue()); + self::assertTrue($parameters->get('optionalParameter')->isOptional); + self::assertSame('Optional parameter value', $optionalParameter->defaultValue); } public function test_methods_can_be_retrieved_from_abstract_object_with_interface_and_with_method_referencing_self(): void { $type = new NativeClassType(AbstractObjectWithInterface::class); - $methods = $this->repository->for($type)->methods(); + $methods = $this->repository->for($type)->methods; self::assertTrue($methods->has('of')); self::assertTrue($methods->has('jsonSerialize')); @@ -156,10 +156,10 @@ public function test_methods_can_be_retrieved_from_abstract_object_with_interfac public function test_private_parent_constructor_is_listed_in_methods(): void { $type = new NativeClassType(ClassWithInheritedPrivateConstructor::class, parent: new NativeClassType(AbstractClassWithPrivateConstructor::class)); - $methods = $this->repository->for($type)->methods(); + $methods = $this->repository->for($type)->methods; self::assertTrue($methods->hasConstructor()); - self::assertFalse($methods->constructor()->isPublic()); + self::assertFalse($methods->constructor()->isPublic); } public function test_invalid_property_type_throws_exception(): void @@ -170,7 +170,7 @@ public function test_invalid_property_type_throws_exception(): void })::class; $class = $this->repository->for(new NativeClassType($class)); - $type = $class->properties()->get('propertyWithInvalidType')->type(); + $type = $class->properties->get('propertyWithInvalidType')->type; self::assertInstanceOf(UnresolvableType::class, $type); /** @var UnresolvableType $type */ @@ -185,7 +185,7 @@ public function test_invalid_property_default_value_throws_exception(): void })::class; $class = $this->repository->for(new NativeClassType($class)); - $type = $class->properties()->get('propertyWithInvalidDefaultValue')->type(); + $type = $class->properties->get('propertyWithInvalidDefaultValue')->type; self::assertInstanceOf(UnresolvableType::class, $type); self::assertMatchesRegularExpression('/Property `.*::\$propertyWithInvalidDefaultValue` of type `string` has invalid default value false/', $type->message()); @@ -221,7 +221,7 @@ public function publicMethod($parameterWithInvalidType): void {} })::class; $class = $this->repository->for(new NativeClassType($class)); - $type = $class->methods()->get('publicMethod')->parameters()->get('parameterWithInvalidType')->type(); + $type = $class->methods->get('publicMethod')->parameters->get('parameterWithInvalidType')->type; self::assertInstanceOf(UnresolvableType::class, $type); /** @var UnresolvableType $type */ @@ -239,7 +239,7 @@ public function publicMethod($parameterWithInvalidType): void {} })::class; $class = $this->repository->for(new NativeClassType($class)); - $type = $class->methods()->get('publicMethod')->returnType(); + $type = $class->methods->get('publicMethod')->returnType; self::assertInstanceOf(UnresolvableType::class, $type); /** @var UnresolvableType $type */ @@ -257,7 +257,7 @@ public function publicMethod($parameterWithInvalidDefaultValue = false): void {} })::class; $class = $this->repository->for(new NativeClassType($class)); - $type = $class->methods()->get('publicMethod')->parameters()->get('parameterWithInvalidDefaultValue')->type(); + $type = $class->methods->get('publicMethod')->parameters->get('parameterWithInvalidDefaultValue')->type; self::assertInstanceOf(UnresolvableType::class, $type); self::assertMatchesRegularExpression('/Parameter `.*::publicMethod\(\$parameterWithInvalidDefaultValue\)` of type `string` has invalid default value false/', $type->message()); diff --git a/tests/Unit/Definition/Repository/Reflection/ReflectionFunctionDefinitionRepositoryTest.php b/tests/Unit/Definition/Repository/Reflection/ReflectionFunctionDefinitionRepositoryTest.php index 4ac2b369..1012c0ec 100644 --- a/tests/Unit/Definition/Repository/Reflection/ReflectionFunctionDefinitionRepositoryTest.php +++ b/tests/Unit/Definition/Repository/Reflection/ReflectionFunctionDefinitionRepositoryTest.php @@ -32,15 +32,15 @@ public function test_function_data_can_be_retrieved(): void $callback = fn (string $foo, $parameterWithDocBlockType): string => $foo . $parameterWithDocBlockType; $function = $this->repository->for($callback); - $parameters = $function->parameters(); + $parameters = $function->parameters; - self::assertSame(__NAMESPACE__ . '\{closure}', $function->name()); - self::assertInstanceOf(NativeStringType::class, $function->returnType()); + self::assertSame(__NAMESPACE__ . '\{closure}', $function->name); + self::assertInstanceOf(NativeStringType::class, $function->returnType); self::assertTrue($parameters->has('foo')); self::assertTrue($parameters->has('parameterWithDocBlockType')); - self::assertInstanceOf(NativeStringType::class, $parameters->get('foo')->type()); - self::assertInstanceOf(NativeStringType::class, $parameters->get('parameterWithDocBlockType')->type()); + self::assertInstanceOf(NativeStringType::class, $parameters->get('foo')->type); + self::assertInstanceOf(NativeStringType::class, $parameters->get('parameterWithDocBlockType')->type); } public function test_function_return_type_is_fetched_from_docblock(): void @@ -52,6 +52,6 @@ public function test_function_return_type_is_fetched_from_docblock(): void $function = $this->repository->for($callback); - self::assertInstanceOf(NativeStringType::class, $function->returnType()); + self::assertInstanceOf(NativeStringType::class, $function->returnType); } } diff --git a/tests/Unit/Type/Parser/Lexer/NativeLexerTest.php b/tests/Unit/Type/Parser/Lexer/NativeLexerTest.php index 46bf03bd..3d723017 100644 --- a/tests/Unit/Type/Parser/Lexer/NativeLexerTest.php +++ b/tests/Unit/Type/Parser/Lexer/NativeLexerTest.php @@ -151,11 +151,9 @@ public function tokenized_type_is_correct_data_provider(): iterable 'token' => UnknownSymbolToken::class, ]; - if (PHP_VERSION_ID >= 8_01_00) { - yield 'enum' => [ - 'symbol' => PureEnum::class, - 'token' => EnumNameToken::class, - ]; - } + yield 'enum' => [ + 'symbol' => PureEnum::class, + 'token' => EnumNameToken::class, + ]; } } diff --git a/tests/Unit/Type/Types/EnumTypeTest.php b/tests/Unit/Type/Types/EnumTypeTest.php index 5eddc724..b906a3bb 100644 --- a/tests/Unit/Type/Types/EnumTypeTest.php +++ b/tests/Unit/Type/Types/EnumTypeTest.php @@ -15,9 +15,6 @@ use PHPUnit\Framework\TestCase; use stdClass; -/** - * @requires PHP >= 8.1 - */ final class EnumTypeTest extends TestCase { private EnumType $pureEnumType; diff --git a/tests/Unit/Type/Types/Factory/ValueTypeFactoryTest.php b/tests/Unit/Type/Types/Factory/ValueTypeFactoryTest.php index 7fc7f858..7e0d18bf 100644 --- a/tests/Unit/Type/Types/Factory/ValueTypeFactoryTest.php +++ b/tests/Unit/Type/Types/Factory/ValueTypeFactoryTest.php @@ -65,12 +65,10 @@ public function type_from_value_returns_expected_type_data_provider(): iterable 'type' => "array{foo: array{foo: 'bar', baz: 'fiz'}}", ]; - if (PHP_VERSION_ID >= 8_01_00) { - yield 'enum' => [ - 'symbol' => PureEnum::FOO, - 'token' => PureEnum::class . '::FOO', - ]; - } + yield 'enum' => [ + 'symbol' => PureEnum::FOO, + 'token' => PureEnum::class . '::FOO', + ]; } public function test_invalid_value_throws_exception(): void diff --git a/tests/Unit/Utility/Reflection/DocParserTest.php b/tests/Unit/Utility/Reflection/DocParserTest.php index 4e5abda8..9d5e29a9 100644 --- a/tests/Unit/Utility/Reflection/DocParserTest.php +++ b/tests/Unit/Utility/Reflection/DocParserTest.php @@ -78,13 +78,11 @@ public function callables_with_docblock_typed_return_type(): iterable 'ObjectWithConstants::CONST_WITH_*', ]; - if (PHP_VERSION_ID >= 8_01_00) { - yield 'phpdoc enum with joker' => [ - /** @return BackedStringEnum::BA* */ - fn () => BackedStringEnum::BAR, - 'BackedStringEnum::BA*', - ]; - } + yield 'phpdoc enum with joker' => [ + /** @return BackedStringEnum::BA* */ + fn () => BackedStringEnum::BAR, + 'BackedStringEnum::BA*', + ]; yield 'psalm' => [ /** @psalm-return int */ diff --git a/tests/Unit/Utility/Reflection/ReflectionTest.php b/tests/Unit/Utility/Reflection/ReflectionTest.php index 494dd1c5..e3fed8c0 100644 --- a/tests/Unit/Utility/Reflection/ReflectionTest.php +++ b/tests/Unit/Utility/Reflection/ReflectionTest.php @@ -5,10 +5,11 @@ namespace CuyZ\Valinor\Tests\Unit\Utility\Reflection; use Closure; +use Countable; use CuyZ\Valinor\Tests\Fixture\Object\ObjectWithPropertyWithNativeDisjunctiveNormalFormType; -use CuyZ\Valinor\Tests\Fixture\Object\ObjectWithPropertyWithNativeIntersectionType; use CuyZ\Valinor\Tests\Fixture\Object\ObjectWithPropertyWithNativePhp82StandaloneTypes; use CuyZ\Valinor\Utility\Reflection\Reflection; +use Iterator; use PHPUnit\Framework\TestCase; use ReflectionClass; use ReflectionFunction; @@ -59,8 +60,8 @@ public function method(string $parameter): void {} $reflectionProperty = $reflectionClass->getProperty('property'); $reflectionMethod = $reflectionClass->getMethod('method'); $reflectionParameter = $reflectionMethod->getParameters()[0]; - $reflectionFunction = new ReflectionFunction(__NAMESPACE__ . '\some_function'); // PHP8.1 First-class callable syntax - $reflectionFunctionMethod = new ReflectionFunction(Closure::fromCallable([self::class, 'test_reflection_signatures_are_correct'])); // PHP8.1 First-class callable syntax + $reflectionFunction = new ReflectionFunction(some_function(...)); + $reflectionFunctionMethod = new ReflectionFunction(Closure::fromCallable(self::test_reflection_signatures_are_correct(...))); $reflectionFunctionOnOneLineClosure = new ReflectionFunction($functions['function_on_one_line']); $reflectionFunctionOnSeveralLinesClosure = new ReflectionFunction($functions['function_on_several_lines']); @@ -121,12 +122,12 @@ public function test_mixed_type_is_handled(): void self::assertSame('mixed', Reflection::flattenType($type)); } - /** - * @requires PHP >= 8.1 - */ public function test_intersection_type_is_handled(): void { - $class = ObjectWithPropertyWithNativeIntersectionType::class; + $class = new class () { + /** @var Countable&Iterator */ + public Countable&Iterator $someProperty; + }; /** @var ReflectionType $type */ $type = (new ReflectionProperty($class, 'someProperty'))->getType(); diff --git a/tests/Unit/Utility/ValueDumperTest.php b/tests/Unit/Utility/ValueDumperTest.php index cacec0ea..78851c11 100644 --- a/tests/Unit/Utility/ValueDumperTest.php +++ b/tests/Unit/Utility/ValueDumperTest.php @@ -38,6 +38,9 @@ public function dump_value_returns_correct_signature_data_provider(): array 'utf8 string cropped' => ['πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„', "'πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„β€¦'"], 'string cropped only after threshold' => ['Lorem12345 ipsumdolorsitamet,consecteturadipiscingelit.Curabitur', "'Lorem12345 ipsumdolorsitamet,consecteturadipiscinge…'"], 'string without space cropped' => ['Loremipsumdolorsitamet,consecteturadipiscingelit.Curabitur',"'Loremipsumdolorsitamet,consecteturadipiscingelit.Cu…'"], + 'pure enum' => [PureEnum::FOO, "'FOO'"], + 'backed string enum' => [BackedStringEnum::FOO, "'foo'"], + 'backed integer enum' => [BackedIntegerEnum::FOO, '42'], 'date' => [new DateTimeImmutable('@1648733888'), '2022/03/31 13:38:08'], 'object' => [new stdClass(), 'object(stdClass)'], 'array' => [['foo' => 'bar', 'baz'], "array{foo: 'bar', 0: 'baz'}"], @@ -45,16 +48,4 @@ public function dump_value_returns_correct_signature_data_provider(): array 'array with too much entries' => [[0, 1, 2, 3, 4, 5, 6, 7], "array{0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, …}"], ]; } - - /** - * PHP8.1 move to data provider - * - * @requires PHP >= 8.1 - */ - public function test_dump_enum_value_returns_correct_signature(): void - { - self::assertSame("'FOO'", ValueDumper::dump(PureEnum::FOO)); - self::assertSame("'foo'", ValueDumper::dump(BackedStringEnum::FOO)); - self::assertSame('42', ValueDumper::dump(BackedIntegerEnum::FOO)); - } }