From a5c73d2a22a1491fc4169d2480b856bd212fb24a Mon Sep 17 00:00:00 2001 From: Enno Woortmann Date: Fri, 20 Sep 2024 11:19:57 +0200 Subject: [PATCH] modernize code --- composer.json | 3 +- rector.php | 36 +++++++ src/Model/GeneratorConfiguration.php | 101 ------------------ src/Model/MethodInterface.php | 2 - src/Model/Property/AbstractProperty.php | 17 +-- .../Property/CompositionPropertyDecorator.php | 8 +- src/Model/Property/Property.php | 46 +++----- src/Model/Property/PropertyInterface.php | 74 +------------ src/Model/Property/PropertyProxy.php | 22 +--- src/Model/Property/PropertyType.php | 17 +-- src/Model/RenderJob.php | 47 ++------ src/Model/Schema.php | 89 ++------------- src/Model/SchemaDefinition/JsonSchema.php | 19 +--- .../SchemaDefinition/JsonSchemaTrait.php | 2 - .../SchemaDefinition/SchemaDefinition.php | 33 ++---- .../SchemaDefinitionDictionary.php | 37 +------ src/Model/Validator.php | 17 +-- .../AbstractComposedPropertyValidator.php | 3 - .../Validator/AbstractPropertyValidator.php | 32 ++---- .../AdditionalPropertiesValidator.php | 19 +--- src/Model/Validator/ArrayItemValidator.php | 13 +-- src/Model/Validator/ArrayTupleValidator.php | 9 +- .../Validator/ComposedPropertyValidator.php | 27 ++--- src/Model/Validator/EnumValidator.php | 3 - .../Validator/ExtractedMethodValidator.php | 23 +--- src/Model/Validator/FilterValidator.php | 86 +++++---------- src/Model/Validator/FormatValidator.php | 16 +-- src/Model/Validator/InstanceOfValidator.php | 2 - .../Validator/MultiTypeCheckValidator.php | 20 ++-- .../NoAdditionalPropertiesValidator.php | 3 - .../PassThroughTypeCheckValidator.php | 6 +- .../Validator/PatternPropertiesValidator.php | 27 +---- .../Validator/PropertyDependencyValidator.php | 5 - .../Validator/PropertyNamesValidator.php | 14 +-- .../Validator/PropertyTemplateValidator.php | 21 +--- src/Model/Validator/PropertyValidator.php | 13 +-- .../Validator/PropertyValidatorInterface.php | 12 --- .../ReflectionTypeCheckValidator.php | 16 --- .../Validator/RequiredPropertyValidator.php | 2 - .../Validator/SchemaDependencyValidator.php | 6 -- src/Model/Validator/TypeCheckValidator.php | 7 +- src/ModelGenerator.php | 12 +-- .../AbstractComposedValueProcessor.php | 35 ++---- .../ComposedValue/IfProcessor.php | 10 +- .../ComposedValueProcessorFactory.php | 8 +- .../Property/ObjectInstantiationDecorator.php | 12 +-- .../Property/PropertyDecoratorInterface.php | 4 - .../Property/PropertyTransferDecorator.php | 10 +- .../SchemaNamespaceTransferDecorator.php | 12 +-- .../TypeHint/ArrayTypeHintDecorator.php | 19 +--- .../TypeHint/CompositionTypeHintDecorator.php | 13 +-- .../Decorator/TypeHint/TypeHintDecorator.php | 13 +-- .../TypeHint/TypeHintDecoratorInterface.php | 3 - .../TypeHint/TypeHintTransferDecorator.php | 13 +-- .../Filter/FilterProcessor.php | 20 +--- .../ProcessorFactoryInterface.php | 5 - .../Property/AbstractNumericProcessor.php | 3 - .../Property/AbstractPropertyProcessor.php | 61 ++--------- .../Property/AbstractTypedValueProcessor.php | 15 +-- .../Property/AbstractValueProcessor.php | 10 +- .../Property/AnyProcessor.php | 6 -- .../Property/ArrayProcessor.php | 27 +---- .../Property/BaseProcessor.php | 34 +----- .../Property/MultiTypeProcessor.php | 21 +--- .../Property/NullProcessor.php | 5 - .../Property/StringProcessor.php | 12 --- src/PropertyProcessor/PropertyFactory.php | 20 +--- .../PropertyMetaDataCollection.php | 19 +--- .../PropertyProcessorFactory.php | 10 -- .../PropertyProcessorInterface.php | 2 - .../Hook/SchemaHookResolver.php | 21 ++-- ...itionalPropertiesAccessorPostProcessor.php | 32 +----- .../PostProcessor/EnumPostProcessor.php | 28 ++--- .../AdditionalPropertiesPostProcessor.php | 7 -- .../CompositionValidationPostProcessor.php | 33 +----- ...MatchingPatternPropertiesPostProcessor.php | 43 +++----- .../PatternPropertiesPostProcessor.php | 18 +--- .../Internal/SerializationPostProcessor.php | 25 +---- ...PatternPropertiesAccessorPostProcessor.php | 15 +-- .../PostProcessor/PostProcessor.php | 3 - .../PostProcessor/RenderedMethod.php | 30 ++---- src/SchemaProcessor/RenderQueue.php | 3 - src/SchemaProcessor/SchemaProcessor.php | 77 ++----------- src/SchemaProvider/OpenAPIv3Provider.php | 15 ++- .../RecursiveDirectoryProvider.php | 5 +- .../SchemaProviderInterface.php | 2 - src/Utils/ClassNameGeneratorInterface.php | 2 - src/Utils/NormalizedName.php | 8 +- src/Utils/RenderHelper.php | 49 +-------- tests/AbstractPHPModelGeneratorTestCase.php | 94 +++------------- tests/Basic/AdditionalPropertiesTest.php | 24 ----- tests/Basic/BasicSchemaGenerationTest.php | 31 +++--- tests/Basic/DefaultValueTest.php | 19 ++-- tests/Basic/ErrorCollectionTest.php | 15 ++- tests/Basic/ExplicitNullTest.php | 4 - tests/Basic/FilterTest.php | 78 +++----------- tests/Basic/IdenticalNestedSchemaTest.php | 30 +++--- tests/Basic/ObjectSizeTest.php | 5 - tests/Basic/PatternPropertiesTest.php | 2 +- tests/Basic/PropertyDependencyTest.php | 16 --- tests/Basic/PropertyNamesTest.php | 11 -- tests/Basic/SchemaDependencyTest.php | 22 ---- tests/Basic/SchemaHookTest.php | 18 +--- tests/ComposedValue/ComposedAllOfTest.php | 58 +++------- tests/ComposedValue/ComposedAnyOfTest.php | 75 +++---------- tests/ComposedValue/ComposedIfTest.php | 18 ---- tests/ComposedValue/ComposedNotTest.php | 40 +------ tests/ComposedValue/ComposedOneOfTest.php | 72 ++----------- tests/Issues/Issue/Issue70Test.php | 2 +- .../AbstractNumericPropertyTestCase.php | 16 +-- tests/Objects/AnyPropertyTest.php | 9 +- tests/Objects/ArrayPropertyTest.php | 75 ++----------- tests/Objects/BooleanPropertyTest.php | 6 +- tests/Objects/ConstPropertyTest.php | 4 +- tests/Objects/EnumPropertyTest.php | 35 ++---- tests/Objects/IntegerPropertyTest.php | 6 +- tests/Objects/MultiTypePropertyTest.php | 18 ++-- tests/Objects/NullPropertyTest.php | 6 +- tests/Objects/NumberPropertyTest.php | 8 +- tests/Objects/ObjectPropertyTest.php | 14 +-- tests/Objects/ReferencePropertyTest.php | 51 ++------- tests/Objects/RequiredPropertyTest.php | 8 -- tests/Objects/StringPropertyTest.php | 29 +---- tests/Objects/TupleArrayPropertyTest.php | 24 ----- ...nalPropertiesAccessorPostProcessorTest.php | 15 --- tests/PostProcessor/EnumPostProcessorTest.php | 22 ++-- ...ernPropertiesAccessorPostProcessorTest.php | 22 +--- .../PopulatePostProcessorTest.php | 12 --- .../PropertyProcessorFactoryTest.php | 6 +- tests/manual/schema/person.json | 24 +++-- tests/manual/test.php | 8 +- 131 files changed, 475 insertions(+), 2382 deletions(-) create mode 100644 rector.php diff --git a/composer.json b/composer.json index 05d709c..572ab89 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ "ext-mbstring": "*" }, "require-dev": { - "phpunit/phpunit": "^9.4" + "phpunit/phpunit": "^9.4", + "rector/rector": "^1.2" }, "autoload": { "psr-4": { diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..8ff9a02 --- /dev/null +++ b/rector.php @@ -0,0 +1,36 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->withPhpSets() + ->withPreparedSets( + deadCode: true, + typeDeclarations: true, + privatization: true, + earlyReturn: true, + phpunitCodeQuality: true, + ) + ->withRules([ + ClassPropertyAssignToConstructorPromotionRector::class, + ]) + ->withSkip([ + GetDebugTypeRector::class, + ChangeOrIfContinueToMultiContinueRector::class, + YieldDataProviderRector::class, + DataProviderArrayItemsNewLinedRector::class + ]); diff --git a/src/Model/GeneratorConfiguration.php b/src/Model/GeneratorConfiguration.php index ff84d8e..5bc9744 100644 --- a/src/Model/GeneratorConfiguration.php +++ b/src/Model/GeneratorConfiguration.php @@ -65,10 +65,6 @@ public function __construct() /** * Add an additional filter * - * @param FilterInterface ...$additionalFilter - * - * @return $this - * * @throws Exception * @throws InvalidFilterException */ @@ -103,11 +99,6 @@ public function addFilter(FilterInterface ...$additionalFilter): self /** * Add an additional format - * - * @param string $formatKey - * @param FormatValidatorInterface $format - * - * @return $this */ public function addFormat(string $formatKey, FormatValidatorInterface $format): self { @@ -116,20 +107,12 @@ public function addFormat(string $formatKey, FormatValidatorInterface $format): return $this; } - /** - * @param string $formatKey - * - * @return FormatValidatorInterface|null - */ public function getFormat(string $formatKey): ?FormatValidatorInterface { return $this->formats[$formatKey] ?? null; } /** - * @param array $callback - * @param string $message - * * @throws InvalidFilterException */ private function validateFilterCallback(array $callback, string $message): void @@ -145,29 +128,17 @@ private function validateFilterCallback(array $callback, string $message): void /** * Get a filter by the given token - * - * @param string $token - * - * @return FilterInterface|null */ public function getFilter(string $token): ?FilterInterface { return $this->filter[$token] ?? null; } - /** - * @return ClassNameGeneratorInterface - */ public function getClassNameGenerator(): ClassNameGeneratorInterface { return $this->classNameGenerator; } - /** - * @param ClassNameGeneratorInterface $classNameGenerator - * - * @return $this - */ public function setClassNameGenerator(ClassNameGeneratorInterface $classNameGenerator): self { $this->classNameGenerator = $classNameGenerator; @@ -175,19 +146,11 @@ public function setClassNameGenerator(ClassNameGeneratorInterface $classNameGene return $this; } - /** - * @return string - */ public function getNamespacePrefix(): string { return $this->namespacePrefix; } - /** - * @param string $namespacePrefix - * - * @return $this - */ public function setNamespacePrefix(string $namespacePrefix): self { $this->namespacePrefix = trim($namespacePrefix, '\\'); @@ -195,19 +158,11 @@ public function setNamespacePrefix(string $namespacePrefix): self return $this; } - /** - * @return bool - */ public function isDefaultArraysToEmptyArrayEnabled(): bool { return $this->defaultArraysToEmptyArray; } - /** - * @param bool $defaultArraysToEmptyArray - * - * @return GeneratorConfiguration - */ public function setDefaultArraysToEmptyArray(bool $defaultArraysToEmptyArray): self { $this->defaultArraysToEmptyArray = $defaultArraysToEmptyArray; @@ -215,19 +170,11 @@ public function setDefaultArraysToEmptyArray(bool $defaultArraysToEmptyArray): s return $this; } - /** - * @return bool - */ public function isImmutable(): bool { return $this->immutable; } - /** - * @param bool $immutable - * - * @return GeneratorConfiguration - */ public function setImmutable(bool $immutable): self { $this->immutable = $immutable; @@ -235,19 +182,11 @@ public function setImmutable(bool $immutable): self return $this; } - /** - * @return bool - */ public function denyAdditionalProperties(): bool { return $this->denyAdditionalProperties; } - /** - * @param bool $denyAdditionalProperties - * - * @return $this - */ public function setDenyAdditionalProperties(bool $denyAdditionalProperties): self { $this->denyAdditionalProperties = $denyAdditionalProperties; @@ -255,19 +194,11 @@ public function setDenyAdditionalProperties(bool $denyAdditionalProperties): sel return $this; } - /** - * @return bool - */ public function hasSerializationEnabled(): bool { return $this->serialization; } - /** - * @param bool $serialization - * - * @return $this - */ public function setSerialization(bool $serialization): self { $this->serialization = $serialization; @@ -275,11 +206,6 @@ public function setSerialization(bool $serialization): self return $this; } - /** - * @param bool $outputEnabled - * - * @return $this - */ public function setOutputEnabled(bool $outputEnabled): self { $this->outputEnabled = $outputEnabled; @@ -287,27 +213,16 @@ public function setOutputEnabled(bool $outputEnabled): self return $this; } - /** - * @return bool - */ public function isOutputEnabled(): bool { return $this->outputEnabled; } - /** - * @return bool - */ public function collectErrors(): bool { return $this->collectErrors; } - /** - * @param bool $collectErrors - * - * @return GeneratorConfiguration - */ public function setCollectErrors(bool $collectErrors): self { $this->collectErrors = $collectErrors; @@ -315,19 +230,11 @@ public function setCollectErrors(bool $collectErrors): self return $this; } - /** - * @return string - */ public function getErrorRegistryClass(): string { return $this->errorRegistryClass; } - /** - * @param string $errorRegistryClass - * - * @return GeneratorConfiguration - */ public function setErrorRegistryClass(string $errorRegistryClass): self { $this->errorRegistryClass = $errorRegistryClass; @@ -335,19 +242,11 @@ public function setErrorRegistryClass(string $errorRegistryClass): self return $this; } - /** - * @return bool - */ public function isImplicitNullAllowed(): bool { return $this->allowImplicitNull; } - /** - * @param bool $allowImplicitNull - * - * @return GeneratorConfiguration - */ public function setImplicitNull(bool $allowImplicitNull): self { $this->allowImplicitNull = $allowImplicitNull; diff --git a/src/Model/MethodInterface.php b/src/Model/MethodInterface.php index bcf16a6..5655e37 100644 --- a/src/Model/MethodInterface.php +++ b/src/Model/MethodInterface.php @@ -8,8 +8,6 @@ interface MethodInterface { /** * Returns the code of the method including the function signature - * - * @return string */ public function getCode(): string; } diff --git a/src/Model/Property/AbstractProperty.php b/src/Model/Property/AbstractProperty.php index cf0f2ef..a58af8f 100644 --- a/src/Model/Property/AbstractProperty.php +++ b/src/Model/Property/AbstractProperty.php @@ -19,25 +19,18 @@ abstract class AbstractProperty implements PropertyInterface { use JsonSchemaTrait, ResolvableTrait; - /** @var string */ - protected $name = ''; - /** @var string */ - protected $attribute = ''; + protected string $attribute; /** * Property constructor. * - * @param string $name - * @param JsonSchema $jsonSchema - * * @throws SchemaException */ - public function __construct(string $name, JsonSchema $jsonSchema) + public function __construct(protected string $name, JsonSchema $jsonSchema) { - $this->name = $name; $this->jsonSchema = $jsonSchema; - $this->attribute = $this->processAttributeName($name); + $this->attribute = $this->processAttributeName($this->name); } /** @@ -63,10 +56,6 @@ public function getAttribute(bool $variableName = false): string /** * Convert a name of a JSON-field into a valid PHP variable name to be used as class attribute * - * @param string $name - * - * @return string - * * @throws SchemaException */ protected function processAttributeName(string $name): string diff --git a/src/Model/Property/CompositionPropertyDecorator.php b/src/Model/Property/CompositionPropertyDecorator.php index 3fba41b..ec41833 100644 --- a/src/Model/Property/CompositionPropertyDecorator.php +++ b/src/Model/Property/CompositionPropertyDecorator.php @@ -28,10 +28,6 @@ class CompositionPropertyDecorator extends PropertyProxy /** * CompositionPropertyDecorator constructor. * - * @param string $propertyName - * @param JsonSchema $jsonSchema - * @param PropertyInterface $property - * * @throws SchemaException */ public function __construct(string $propertyName, JsonSchema $jsonSchema, PropertyInterface $property) @@ -50,10 +46,8 @@ public function __construct(string $propertyName, JsonSchema $jsonSchema, Proper /** * Append an object property which is affected by the composition validator - * - * @param PropertyInterface $property */ - public function appendAffectedObjectProperty(PropertyInterface $property) + public function appendAffectedObjectProperty(PropertyInterface $property): void { $this->affectedObjectProperties[] = $property; } diff --git a/src/Model/Property/Property.php b/src/Model/Property/Property.php index 6f5de66..d5be007 100644 --- a/src/Model/Property/Property.php +++ b/src/Model/Property/Property.php @@ -19,18 +19,14 @@ */ class Property extends AbstractProperty { - /** @var PropertyType */ - protected $type; /** @var PropertyType|null */ - protected $outputType = null; + protected $outputType; /** @var bool */ protected $isPropertyRequired = true; /** @var bool */ protected $isPropertyReadOnly = false; /** @var bool */ protected $isPropertyInternal = false; - /** @var string */ - protected $description = ''; /** @var mixed */ protected $defaultValue; @@ -43,27 +39,23 @@ class Property extends AbstractProperty /** @var TypeHintDecoratorInterface[] */ public $typeHintDecorators = []; - private $renderedTypeHints = []; - /** @var int Track the amount of unresolved validators */ - private $pendingValidators = 0; + private array $renderedTypeHints = []; + /** Track the amount of unresolved validators */ + private int $pendingValidators = 0; /** * Property constructor. * - * @param string $name - * @param PropertyType|null $type - * @param JsonSchema $jsonSchema - * @param string $description - * * @throws SchemaException */ - public function __construct(string $name, ?PropertyType $type, JsonSchema $jsonSchema, string $description = '') - { + public function __construct( + string $name, + protected ?PropertyType $type, + JsonSchema $jsonSchema, + protected string $description = '', + ) { parent::__construct($name, $jsonSchema); - $this->type = $type; - $this->description = $description; - $this->resolve(); } @@ -132,9 +124,7 @@ public function getTypeHint(bool $outputType = false, array $skipDecorators = [] $filteredDecorators = array_filter( $this->typeHintDecorators, - static function (TypeHintDecoratorInterface $decorator) use ($skipDec): bool { - return !in_array(get_class($decorator), $skipDec); - }, + static fn(TypeHintDecoratorInterface $decorator): bool => !in_array($decorator::class, $skipDec), ); foreach ($filteredDecorators as $decorator) { @@ -178,7 +168,7 @@ public function addValidator(PropertyValidatorInterface $validator, int $priorit $this->pendingValidators++; - $validator->onResolve(function () { + $validator->onResolve(function (): void { if (--$this->pendingValidators === 0) { $this->resolve(); } @@ -215,18 +205,12 @@ public function getOrderedValidators(): array { usort( $this->validators, - static function (Validator $validator, Validator $comparedValidator): int { - if ($validator->getPriority() == $comparedValidator->getPriority()) { - return 0; - } - return ($validator->getPriority() < $comparedValidator->getPriority()) ? -1 : 1; - }, + static fn(Validator $validator, Validator $comparedValidator): int => + $validator->getPriority() <=> $comparedValidator->getPriority(), ); return array_map( - static function (Validator $validator): PropertyValidatorInterface { - return $validator->getValidator(); - }, + static fn(Validator $validator): PropertyValidatorInterface => $validator->getValidator(), $this->validators, ); } diff --git a/src/Model/Property/PropertyInterface.php b/src/Model/Property/PropertyInterface.php index ac8ecb0..5214d29 100644 --- a/src/Model/Property/PropertyInterface.php +++ b/src/Model/Property/PropertyInterface.php @@ -19,33 +19,23 @@ */ interface PropertyInterface extends ResolvableInterface { - /** - * @return string - */ public function getName(): string; /** * @param bool $variableName If set to true the name for the variable is returned. Otherwise, the name for functions * will be returned - * - * @return string */ public function getAttribute(bool $variableName = false): string; /** * @param bool $outputType If set to true the output type will be returned (may differ from the base type) - * - * @return PropertyType|null */ public function getType(bool $outputType = false): ?PropertyType; /** - * @param PropertyType|null $type * @param PropertyType|null $outputType By default the output type will be equal to the base type but due to applied * filters the output type may change * @param bool $reset set to true for a full type reset (including type hint decorators like array, ...) - * - * @return PropertyInterface */ public function setType( ?PropertyType $type = null, @@ -57,21 +47,13 @@ public function setType( * @param bool $outputType If set to true the output type hint will be returned (may differ from the base type) * @param string[] $skipDecorators Provide a set of decorators (FQCN) which shouldn't be applied * (might be necessary to avoid infinite loops for recursive calls) - * @return string */ public function getTypeHint(bool $outputType = false, array $skipDecorators = []): string; - /** - * @param TypeHintDecoratorInterface $typeHintDecorator - * - * @return PropertyInterface - */ public function addTypeHintDecorator(TypeHintDecoratorInterface $typeHintDecorator): PropertyInterface; /** * Get a description for the property. If no description is available an empty string will be returned - * - * @return string */ public function getDescription(): string; @@ -87,11 +69,6 @@ public function getDescription(): string; * Priority 10+: Filter validators * Priority 99: Default priority used for casual validators * Priority 100: Validators for compositions - * - * @param PropertyValidatorInterface $validator - * @param int $priority - * - * @return PropertyInterface */ public function addValidator(PropertyValidatorInterface $validator, int $priority = 99): PropertyInterface; @@ -102,10 +79,6 @@ public function getValidators(): array; /** * Filter the assigned validators - * - * @param callable $filter - * - * @return PropertyInterface */ public function filterValidators(callable $filter): PropertyInterface; @@ -118,20 +91,11 @@ public function getOrderedValidators(): array; /** * Add a decorator to the property - * - * @param PropertyDecoratorInterface $decorator - * - * @return PropertyInterface */ public function addDecorator(PropertyDecoratorInterface $decorator): PropertyInterface; /** * Resolve all decorators of the property - * - * @param string $input - * @param bool $nestedProperty - * - * @return string */ public function resolveDecorator(string $input, bool $nestedProperty): string; @@ -140,76 +104,40 @@ public function resolveDecorator(string $input, bool $nestedProperty): string; */ public function getDecorators(): array; - /** - * @param bool $isPropertyRequired - * - * @return PropertyInterface - */ public function setRequired(bool $isPropertyRequired): PropertyInterface; - /** - * @param bool $isPropertyReadOnly - * - * @return PropertyInterface - */ public function setReadOnly(bool $isPropertyReadOnly): PropertyInterface; - /** - * @param bool $isPropertyInternal - * - * @return PropertyInterface - */ public function setInternal(bool $isPropertyInternal): PropertyInterface; /** - * @param mixed $defaultValue * @param bool $raw By default, the provided value will be added to the generated code via var_export. If the raw * option is enabled the value provided in $defaultValue will not be changed. - * - * @return PropertyInterface */ - public function setDefaultValue($defaultValue, bool $raw = false): PropertyInterface; + public function setDefaultValue(mixed $defaultValue, bool $raw = false): PropertyInterface; - /** - * @return string|null - */ public function getDefaultValue(): ?string; - /** - * @return bool - */ public function isRequired(): bool; - /** - * @return bool - */ public function isReadOnly(): bool; - /** - * @return bool - */ public function isInternal(): bool; /** * Set a nested schema * - * @param Schema $schema - * * @return PropertyInterface */ public function setNestedSchema(Schema $schema); /** * Get a nested schema if a schema was appended to the property - * - * @return null|Schema */ public function getNestedSchema(): ?Schema; /** * Get the JSON schema used to set up the property - * - * @return JsonSchema */ public function getJsonSchema(): JsonSchema; } diff --git a/src/Model/Property/PropertyProxy.php b/src/Model/Property/PropertyProxy.php index 73737b7..a1ded5e 100644 --- a/src/Model/Property/PropertyProxy.php +++ b/src/Model/Property/PropertyProxy.php @@ -19,39 +19,26 @@ */ class PropertyProxy extends AbstractProperty { - /** @var string */ - protected $key; - /** @var ResolvedDefinitionsCollection */ - protected $definitionsCollection; - /** * PropertyProxy constructor. * * @param string $name The name must be provided separately as the name is not bound to the structure of a * referenced schema. Consequently, two properties with different names can refer an identical schema utilizing the * PropertyProxy. By providing a name to each of the proxies the resulting properties will get the correct names. - * @param JsonSchema $jsonSchema - * @param ResolvedDefinitionsCollection $definitionsCollection - * @param string $key * * @throws SchemaException */ public function __construct( string $name, JsonSchema $jsonSchema, - ResolvedDefinitionsCollection $definitionsCollection, - string $key, + protected ResolvedDefinitionsCollection $definitionsCollection, + protected string $key, ) { parent::__construct($name, $jsonSchema); - - $this->key = $key; - $this->definitionsCollection = $definitionsCollection; } /** * Get the property out of the resolved definitions collection to proxy function calls - * - * @return PropertyInterface */ protected function getProperty(): PropertyInterface { @@ -131,9 +118,8 @@ public function filterValidators(callable $filter): PropertyInterface public function getOrderedValidators(): array { return array_map( - function (PropertyValidatorInterface $propertyValidator): PropertyValidatorInterface { - return $propertyValidator->withProperty($this); - }, + fn(PropertyValidatorInterface $propertyValidator): PropertyValidatorInterface => + $propertyValidator->withProperty($this), $this->getProperty()->getOrderedValidators(), ); } diff --git a/src/Model/Property/PropertyType.php b/src/Model/Property/PropertyType.php index 2e5c95c..ada5f41 100644 --- a/src/Model/Property/PropertyType.php +++ b/src/Model/Property/PropertyType.php @@ -6,11 +6,6 @@ class PropertyType { - /** @var string */ - private $name; - /** @var bool|null */ - private $nullable; - /** * PropertyType constructor. * @@ -18,23 +13,13 @@ class PropertyType * @param bool|null $nullable Is the property nullable? if not provided the nullability will be determined * automatically from the required flag/implicitNull setting etc. */ - public function __construct(string $name, ?bool $nullable = null) - { - $this->name = $name; - $this->nullable = $nullable; - } + public function __construct(private string $name, private ?bool $nullable = null) {} - /** - * @return string - */ public function getName(): string { return $this->name; } - /** - * @return bool|null - */ public function isNullable(): ?bool { return $this->nullable; diff --git a/src/Model/RenderJob.php b/src/Model/RenderJob.php index 10f9bd4..1cc9ca4 100644 --- a/src/Model/RenderJob.php +++ b/src/Model/RenderJob.php @@ -21,15 +21,6 @@ */ class RenderJob { - /** @var Schema */ - protected $schema; - /** @var string */ - protected $className; - /** @var string */ - protected $classPath; - /** @var string */ - protected $fileName; - /** * Create a new class render job * @@ -39,22 +30,16 @@ class RenderJob * @param Schema $schema The Schema object which holds properties and validators */ public function __construct( - string $fileName, - string $classPath, - string $className, - Schema $schema, - ) { - $this->fileName = $fileName; - $this->classPath = $classPath; - $this->className = $className; - $this->schema = $schema; - } + protected string $fileName, + protected string $classPath, + protected string $className, + protected Schema $schema, + ) {} /** * @param PostProcessor[] $postProcessors - * @param GeneratorConfiguration $generatorConfiguration */ - public function postProcess(array $postProcessors, GeneratorConfiguration $generatorConfiguration) + public function postProcess(array $postProcessors, GeneratorConfiguration $generatorConfiguration): void { foreach ($postProcessors as $postProcessor) { $postProcessor->process($this->schema, $generatorConfiguration); @@ -64,8 +49,6 @@ public function postProcess(array $postProcessors, GeneratorConfiguration $gener /** * Execute the render job and render the class * - * @param GeneratorConfiguration $generatorConfiguration - * * @throws FileSystemException * @throws RenderException */ @@ -112,9 +95,6 @@ protected function generateModelDirectory(): void /** * Render a class. Returns the php code of the class * - * @param GeneratorConfiguration $generatorConfiguration - * - * @return string * @throws RenderException */ protected function renderClass(GeneratorConfiguration $generatorConfiguration): string @@ -136,9 +116,7 @@ protected function renderClass(GeneratorConfiguration $generatorConfiguration): 'true' => true, 'baseValidatorsWithoutCompositions' => array_filter( $this->schema->getBaseValidators(), - static function ($validator): bool { - return !is_a($validator, AbstractComposedPropertyValidator::class); - }, + static fn($validator): bool => !is_a($validator, AbstractComposedPropertyValidator::class), ), ], ); @@ -150,9 +128,6 @@ static function ($validator): bool { } /** - * @param GeneratorConfiguration $generatorConfiguration - * @param string $namespace - * * @return string[] */ protected function getUseForSchema(GeneratorConfiguration $generatorConfiguration, string $namespace): array @@ -167,10 +142,10 @@ protected function getUseForSchema(GeneratorConfiguration $generatorConfiguratio ); // filter out non-compound uses and uses which link to the current namespace - $use = array_filter($use, static function ($classPath) use ($namespace): bool { - return strstr(trim(str_replace("$namespace", '', $classPath), '\\'), '\\') || - (!strstr($classPath, '\\') && !empty($namespace)); - }); + $use = array_filter($use, static fn($classPath): bool => + strstr(trim(str_replace("$namespace", '', $classPath), '\\'), '\\') || + (!strstr($classPath, '\\') && !empty($namespace)), + ); return $use; } diff --git a/src/Model/Schema.php b/src/Model/Schema.php index 314bcdd..ba5a684 100644 --- a/src/Model/Schema.php +++ b/src/Model/Schema.php @@ -24,10 +24,6 @@ class Schema { use JsonSchemaTrait; - /** @var string */ - protected $className; - /** @var string */ - protected $classPath; /** @var string */ protected $description; @@ -39,8 +35,6 @@ class Schema protected $properties = []; /** @var MethodInterface[] */ protected $methods = []; - /** @var bool */ - protected $initialClass = false; /** @var PropertyValidatorInterface[] A Collection of validators which must be applied * before adding properties to the model @@ -53,59 +47,39 @@ class Schema /** @var SchemaHookInterface[] */ protected $schemaHooks = []; - /** @var SchemaDefinitionDictionary */ - protected $schemaDefinitionDictionary; + protected SchemaDefinitionDictionary $schemaDefinitionDictionary; - /** @var int */ - private $resolvedProperties = 0; + private int $resolvedProperties = 0; /** @var callable[] */ - private $onAllPropertiesResolvedCallbacks = []; + private array $onAllPropertiesResolvedCallbacks = []; /** * Schema constructor. - * - * @param string $classPath - * @param string $className - * @param JsonSchema $schema - * @param SchemaDefinitionDictionary|null $dictionary - * @param bool $initialClass */ public function __construct( - string $classPath, - string $className, + protected string $classPath, + protected string $className, JsonSchema $schema, ?SchemaDefinitionDictionary $dictionary = null, - bool $initialClass = false, + protected bool $initialClass = false, ) { - $this->className = $className; - $this->classPath = $classPath; $this->jsonSchema = $schema; $this->schemaDefinitionDictionary = $dictionary ?? new SchemaDefinitionDictionary(''); $this->description = $schema->getJson()['description'] ?? ''; - $this->initialClass = $initialClass; $this->addInterface(JSONModelInterface::class); } - /** - * @return string - */ public function getClassName(): string { return $this->className; } - /** - * @return string - */ public function getClassPath(): string { return $this->classPath; } - /** - * @return string - */ public function getDescription(): string { return $this->description; @@ -145,23 +119,13 @@ static function ( ) use ($hasSchemaDependencyValidator): int { $propertyHasSchemaDependencyValidator = $hasSchemaDependencyValidator($property); $comparedPropertyHasSchemaDependencyValidator = $hasSchemaDependencyValidator($comparedProperty); - - if ($propertyHasSchemaDependencyValidator === $comparedPropertyHasSchemaDependencyValidator) { - return 0; - } - - return ($propertyHasSchemaDependencyValidator < $comparedPropertyHasSchemaDependencyValidator) ? 1 : -1; + return $comparedPropertyHasSchemaDependencyValidator <=> $propertyHasSchemaDependencyValidator; }, ); return $this->properties; } - /** - * @param PropertyInterface $property - * - * @return $this - */ public function addProperty(PropertyInterface $property): self { if (!isset($this->properties[$property->getName()])) { @@ -197,8 +161,6 @@ public function getBaseValidators(): array /** * Get the keys of all composition base validators - * - * @return array */ public function getCompositionValidatorKeys(): array { @@ -213,11 +175,6 @@ public function getCompositionValidatorKeys(): array return $keys; } - /** - * @param PropertyValidatorInterface $baseValidator - * - * @return $this - */ public function addBaseValidator(PropertyValidatorInterface $baseValidator): self { $this->baseValidators[] = $baseValidator; @@ -225,9 +182,6 @@ public function addBaseValidator(PropertyValidatorInterface $baseValidator): sel return $this; } - /** - * @return SchemaDefinitionDictionary - */ public function getSchemaDictionary(): SchemaDefinitionDictionary { return $this->schemaDefinitionDictionary; @@ -235,10 +189,6 @@ public function getSchemaDictionary(): SchemaDefinitionDictionary /** * Add a class to the schema which is required - * - * @param string $fqcn - * - * @return $this */ public function addUsedClass(string $fqcn): self { @@ -247,11 +197,6 @@ public function addUsedClass(string $fqcn): self return $this; } - /** - * @param SchemaNamespaceTransferDecorator $decorator - * - * @return $this - */ public function addNamespaceTransferDecorator(SchemaNamespaceTransferDecorator $decorator): self { $this->namespaceTransferDecorators[] = $decorator; @@ -277,9 +222,6 @@ public function getUsedClasses(array $visitedSchema = []): array /** * @param string $methodKey An unique key in the scope of the schema to identify the method - * @param MethodInterface $method - * - * @return $this */ public function addMethod(string $methodKey, MethodInterface $method): self { @@ -309,11 +251,6 @@ public function getTraits(): array return $this->traits; } - /** - * @param string $trait - * - * @return Schema - */ public function addTrait(string $trait): self { $this->traits[] = $trait; @@ -330,11 +267,6 @@ public function getInterfaces(): array return $this->interfaces; } - /** - * @param string $interface - * - * @return Schema - */ public function addInterface(string $interface): self { $this->interfaces[] = $interface; @@ -345,10 +277,6 @@ public function addInterface(string $interface): self /** * Add an additional schema hook - * - * @param SchemaHookInterface $schemaHook - * - * @return $this */ public function addSchemaHook(SchemaHookInterface $schemaHook): self { @@ -365,9 +293,6 @@ public function getSchemaHooks(): array return $this->schemaHooks; } - /** - * @return bool - */ public function isInitialClass(): bool { return $this->initialClass; diff --git a/src/Model/SchemaDefinition/JsonSchema.php b/src/Model/SchemaDefinition/JsonSchema.php index df0cf22..1b5f203 100644 --- a/src/Model/SchemaDefinition/JsonSchema.php +++ b/src/Model/SchemaDefinition/JsonSchema.php @@ -33,10 +33,7 @@ class JsonSchema 'patternProperties', ]; - /** @var array */ - protected $json; - /** @var string */ - private $file; + protected array $json; /** * JsonSchema constructor. @@ -44,7 +41,7 @@ class JsonSchema * @param string $file the source file for the schema * @param array $json Decoded json schema */ - public function __construct(string $file, array $json) + public function __construct(private string $file, array $json) { // wrap in an allOf to pass the processing to multiple handlers - ugly hack to be removed after rework if (isset($json['$ref']) && count(array_diff(array_intersect(array_keys($json), self::SCHEMA_SIGNATURE_RELEVANT_FIELDS), ['$ref', 'type']))) { @@ -63,12 +60,8 @@ public function __construct(string $file, array $json) } $this->json = $json; - $this->file = $file; } - /** - * @return array - */ public function getJson(): array { return $this->json; @@ -83,11 +76,6 @@ public function getSignature(): string return ArrayHash::hash($this->json, self::SCHEMA_SIGNATURE_RELEVANT_FIELDS); } - /** - * @param array $json - * - * @return JsonSchema - */ public function withJson(array $json): JsonSchema { $jsonSchema = clone $this; @@ -96,9 +84,6 @@ public function withJson(array $json): JsonSchema return $jsonSchema; } - /** - * @return string - */ public function getFile(): string { return $this->file; diff --git a/src/Model/SchemaDefinition/JsonSchemaTrait.php b/src/Model/SchemaDefinition/JsonSchemaTrait.php index 822913f..4a71aa3 100644 --- a/src/Model/SchemaDefinition/JsonSchemaTrait.php +++ b/src/Model/SchemaDefinition/JsonSchemaTrait.php @@ -16,8 +16,6 @@ trait JsonSchemaTrait /** * Get the JSON schema structure - * - * @return JsonSchema */ public function getJsonSchema(): JsonSchema { diff --git a/src/Model/SchemaDefinition/SchemaDefinition.php b/src/Model/SchemaDefinition/SchemaDefinition.php index d1e2775..0bf81a4 100644 --- a/src/Model/SchemaDefinition/SchemaDefinition.php +++ b/src/Model/SchemaDefinition/SchemaDefinition.php @@ -23,36 +23,21 @@ */ class SchemaDefinition { - /** @var JsonSchema */ - protected $source; - /** @var SchemaProcessor */ - protected $schemaProcessor; - /** @var Schema */ - protected $schema; - /** @var ResolvedDefinitionsCollection */ - protected $resolvedPaths; + protected ResolvedDefinitionsCollection $resolvedPaths; /** @var array */ protected $unresolvedProxies = []; /** * SchemaDefinition constructor. - * - * @param JsonSchema $jsonSchema - * @param SchemaProcessor $schemaProcessor - * @param Schema $schema */ - public function __construct(JsonSchema $jsonSchema, SchemaProcessor $schemaProcessor, Schema $schema) - { - $this->source = $jsonSchema; - $this->schemaProcessor = $schemaProcessor; - $this->schema = $schema; - + public function __construct( + protected JsonSchema $source, + protected SchemaProcessor $schemaProcessor, + protected Schema $schema, + ) { $this->resolvedPaths = new ResolvedDefinitionsCollection(); } - /** - * @return Schema - */ public function getSchema(): Schema { return $this->schema; @@ -61,12 +46,6 @@ public function getSchema(): Schema /** * Resolve a reference * - * @param string $propertyName - * @param array $path - * @param PropertyMetaDataCollection $propertyMetaDataCollection - * - * @return PropertyInterface - * * @throws PHPModelGeneratorException * @throws SchemaException */ diff --git a/src/Model/SchemaDefinition/SchemaDefinitionDictionary.php b/src/Model/SchemaDefinition/SchemaDefinitionDictionary.php index f2e8838..c98016e 100644 --- a/src/Model/SchemaDefinition/SchemaDefinitionDictionary.php +++ b/src/Model/SchemaDefinition/SchemaDefinitionDictionary.php @@ -16,28 +16,19 @@ */ class SchemaDefinitionDictionary extends ArrayObject { - /** @var string */ - private $sourceDirectory; /** @var Schema[] */ - private $parsedExternalFileSchemas = []; + private array $parsedExternalFileSchemas = []; /** * SchemaDefinitionDictionary constructor. - * - * @param string $sourceDirectory */ - public function __construct(string $sourceDirectory) + public function __construct(private string $sourceDirectory) { parent::__construct(); - - $this->sourceDirectory = $sourceDirectory; } /** * Set up the definition directory for the schema - * - * @param SchemaProcessor $schemaProcessor - * @param Schema $schema */ public function setUpDefinitionDictionary(SchemaProcessor $schemaProcessor, Schema $schema): void { // attach the root node to the definition dictionary @@ -60,10 +51,6 @@ public function setUpDefinitionDictionary(SchemaProcessor $schemaProcessor, Sche /** * Fetch all schema definitions with an ID for direct references - * - * @param JsonSchema $jsonSchema - * @param SchemaProcessor $schemaProcessor - * @param Schema $schema */ protected function fetchDefinitionsById( JsonSchema $jsonSchema, @@ -74,7 +61,7 @@ protected function fetchDefinitionsById( if (isset($json['$id'])) { $this->addDefinition( - strpos($json['$id'], '#') === 0 ? $json['$id'] : "#{$json['$id']}", + str_starts_with($json['$id'], '#') ? $json['$id'] : "#{$json['$id']}", new SchemaDefinition($jsonSchema, $schemaProcessor, $schema), ); } @@ -91,9 +78,6 @@ protected function fetchDefinitionsById( /** * Add a partial schema definition to the schema * - * @param string $key - * @param SchemaDefinition $definition - * * @return $this */ public function addDefinition(string $key, SchemaDefinition $definition): self @@ -108,17 +92,11 @@ public function addDefinition(string $key, SchemaDefinition $definition): self } /** - * @param string $key - * @param SchemaProcessor $schemaProcessor - * @param array $path - * - * @return SchemaDefinition|null - * * @throws SchemaException */ public function getDefinition(string $key, SchemaProcessor $schemaProcessor, array &$path = []): ?SchemaDefinition { - if (strpos($key, '#') === 0 && strpos($key, '/')) { + if (str_starts_with($key, '#') && strpos($key, '/')) { $path = explode('/', $key); array_shift($path); $key = array_shift($path); @@ -149,13 +127,6 @@ public function getDefinition(string $key, SchemaProcessor $schemaProcessor, arr } /** - * @param string $jsonSchemaFile - * @param string $externalKey - * @param SchemaProcessor $schemaProcessor - * @param array $path - * - * @return SchemaDefinition|null - * * @throws SchemaException */ protected function parseExternalFile( diff --git a/src/Model/Validator.php b/src/Model/Validator.php index 84ae536..a06f732 100644 --- a/src/Model/Validator.php +++ b/src/Model/Validator.php @@ -13,28 +13,13 @@ */ class Validator { - /** @var PropertyValidatorInterface */ - protected $validator; - /** @var int */ - protected $priority; + public function __construct(protected PropertyValidatorInterface $validator, protected int $priority) {} - public function __construct(PropertyValidatorInterface $validator, int $priority) - { - $this->validator = $validator; - $this->priority = $priority; - } - - /** - * @return PropertyValidatorInterface - */ public function getValidator(): PropertyValidatorInterface { return $this->validator; } - /** - * @return int - */ public function getPriority(): int { return $this->priority; diff --git a/src/Model/Validator/AbstractComposedPropertyValidator.php b/src/Model/Validator/AbstractComposedPropertyValidator.php index f080814..9e27a2b 100644 --- a/src/Model/Validator/AbstractComposedPropertyValidator.php +++ b/src/Model/Validator/AbstractComposedPropertyValidator.php @@ -18,9 +18,6 @@ abstract class AbstractComposedPropertyValidator extends ExtractedMethodValidato /** @var CompositionPropertyDecorator[] */ protected $composedProperties; - /** - * @return string - */ public function getCompositionProcessor(): string { return $this->compositionProcessor; diff --git a/src/Model/Validator/AbstractPropertyValidator.php b/src/Model/Validator/AbstractPropertyValidator.php index 2e9990c..08e2469 100644 --- a/src/Model/Validator/AbstractPropertyValidator.php +++ b/src/Model/Validator/AbstractPropertyValidator.php @@ -17,26 +17,14 @@ abstract class AbstractPropertyValidator implements PropertyValidatorInterface { use ResolvableTrait; - /** @var string */ - protected $exceptionClass; - /** @var array */ - protected $exceptionParams; - /** @var PropertyInterface */ - protected $property; - /** * AbstractPropertyValidator constructor. - * - * @param PropertyInterface $property - * @param string $exceptionClass - * @param array $exceptionParams */ - public function __construct(PropertyInterface $property, string $exceptionClass, array $exceptionParams = []) - { - $this->property = $property; - $this->exceptionClass = $exceptionClass; - $this->exceptionParams = $exceptionParams; - } + public function __construct( + protected PropertyInterface $property, + protected string $exceptionClass, + protected array $exceptionParams = [], + ) {} /** * @inheritDoc @@ -67,8 +55,6 @@ public function getExceptionParams(): array /** * By default a validator doesn't require a set up - * - * @return string */ public function getValidatorSetUp(): string { @@ -77,15 +63,13 @@ public function getValidatorSetUp(): string /** * Helper function to remove a RequiredPropertyValidator - * - * @param PropertyInterface $property */ protected function removeRequiredPropertyValidator(PropertyInterface $property): void { $property->onResolve(static function () use ($property): void { - $property->filterValidators(static function (Validator $validator): bool { - return !is_a($validator->getValidator(), RequiredPropertyValidator::class); - }); + $property->filterValidators(static fn(Validator $validator): bool => + !is_a($validator->getValidator(), RequiredPropertyValidator::class) + ); }); } } diff --git a/src/Model/Validator/AdditionalPropertiesValidator.php b/src/Model/Validator/AdditionalPropertiesValidator.php index 2076c11..e23cab9 100644 --- a/src/Model/Validator/AdditionalPropertiesValidator.php +++ b/src/Model/Validator/AdditionalPropertiesValidator.php @@ -30,19 +30,12 @@ class AdditionalPropertiesValidator extends PropertyTemplateValidator protected const EXCEPTION_CLASS = InvalidAdditionalPropertiesException::class; - /** @var PropertyInterface */ - private $validationProperty; - /** @var bool */ - private $collectAdditionalProperties = false; + private PropertyInterface $validationProperty; + private bool $collectAdditionalProperties = false; /** * AdditionalPropertiesValidator constructor. * - * @param SchemaProcessor $schemaProcessor - * @param Schema $schema - * @param JsonSchema $propertiesStructure - * @param string|null $propertyName - * * @throws SchemaException */ public function __construct( @@ -97,17 +90,11 @@ public function getCheck(): string return parent::getCheck(); } - /** - * @param bool $collectAdditionalProperties - */ public function setCollectAdditionalProperties(bool $collectAdditionalProperties): void { $this->collectAdditionalProperties = $collectAdditionalProperties; } - /** - * @return PropertyInterface - */ public function getValidationProperty(): PropertyInterface { return $this->validationProperty; @@ -115,8 +102,6 @@ public function getValidationProperty(): PropertyInterface /** * Initialize all variables which are required to execute a property names validator - * - * @return string */ public function getValidatorSetUp(): string { diff --git a/src/Model/Validator/ArrayItemValidator.php b/src/Model/Validator/ArrayItemValidator.php index 6f43bfe..001b7d0 100644 --- a/src/Model/Validator/ArrayItemValidator.php +++ b/src/Model/Validator/ArrayItemValidator.php @@ -23,19 +23,12 @@ */ class ArrayItemValidator extends ExtractedMethodValidator { - /** @var string */ - private $variableSuffix = ''; - /** @var PropertyInterface */ - private $nestedProperty; + private string $variableSuffix; + private PropertyInterface $nestedProperty; /** * ArrayItemValidator constructor. * - * @param SchemaProcessor $schemaProcessor - * @param Schema $schema - * @param JsonSchema $itemStructure - * @param PropertyInterface $property - * * @throws SchemaException */ public function __construct( @@ -92,8 +85,6 @@ public function getCheck(): string /** * Initialize all variables which are required to execute a property names validator - * - * @return string */ public function getValidatorSetUp(): string { diff --git a/src/Model/Validator/ArrayTupleValidator.php b/src/Model/Validator/ArrayTupleValidator.php index 09b89b5..2bd44d8 100644 --- a/src/Model/Validator/ArrayTupleValidator.php +++ b/src/Model/Validator/ArrayTupleValidator.php @@ -24,16 +24,11 @@ class ArrayTupleValidator extends PropertyTemplateValidator { /** @var PropertyInterface[] */ - private $tupleProperties; + private array $tupleProperties; /** * ArrayTupleValidator constructor. * - * @param SchemaProcessor $schemaProcessor - * @param Schema $schema - * @param JsonSchema $propertiesStructure - * @param string $propertyName - * * @throws SchemaException */ public function __construct( @@ -91,8 +86,6 @@ public function getCheck(): string /** * Initialize all variables which are required to execute a property names validator - * - * @return string */ public function getValidatorSetUp(): string { diff --git a/src/Model/Validator/ComposedPropertyValidator.php b/src/Model/Validator/ComposedPropertyValidator.php index 70afdbd..5697f0d 100644 --- a/src/Model/Validator/ComposedPropertyValidator.php +++ b/src/Model/Validator/ComposedPropertyValidator.php @@ -18,7 +18,7 @@ */ class ComposedPropertyValidator extends AbstractComposedPropertyValidator { - private $modifiedValuesMethod; + private string $modifiedValuesMethod; public function __construct( GeneratorConfiguration $generatorConfiguration, @@ -55,16 +55,11 @@ public function getCheck(): string $this->scope->addMethod( $this->modifiedValuesMethod, new class ($this->composedProperties, $this->modifiedValuesMethod) implements MethodInterface { - /** @var CompositionPropertyDecorator[] $compositionProperties */ - private $compositionProperties; - /** @var string */ - private $modifiedValuesMethod; - - public function __construct(array $compositionProperties, string $modifiedValuesMethod) - { - $this->compositionProperties = $compositionProperties; - $this->modifiedValuesMethod = $modifiedValuesMethod; - } + public function __construct( + /** @var CompositionPropertyDecorator[] $compositionProperties */ + private array $compositionProperties, + private string $modifiedValuesMethod + ) {} public function getCode(): string { @@ -113,8 +108,6 @@ private function %s(array $originalModelData, object $nestedCompositionObject): /** * Initialize all variables which are required to execute a composed property validator - * - * @return string */ public function getValidatorSetUp(): string { @@ -137,9 +130,7 @@ public function withoutNestedCompositionValidation(): self /** @var CompositionPropertyDecorator $composedProperty */ foreach ($validator->composedProperties as $composedProperty) { $composedProperty->onResolve(static function () use ($composedProperty): void { - $composedProperty->filterValidators(static function (Validator $validator): bool { - return !is_a($validator->getValidator(), AbstractComposedPropertyValidator::class); - }); + $composedProperty->filterValidators(static fn(Validator $validator): bool => !is_a($validator->getValidator(), AbstractComposedPropertyValidator::class)); }); } @@ -148,10 +139,6 @@ public function withoutNestedCompositionValidation(): self /** * Parse the composition type (allOf, anyOf, ...) from the given processor and get the corresponding exception class - * - * @param string $compositionProcessor - * - * @return string */ private function getExceptionByProcessor(string $compositionProcessor): string { diff --git a/src/Model/Validator/EnumValidator.php b/src/Model/Validator/EnumValidator.php index 66fda24..c0cad26 100644 --- a/src/Model/Validator/EnumValidator.php +++ b/src/Model/Validator/EnumValidator.php @@ -17,9 +17,6 @@ class EnumValidator extends PropertyValidator { /** * EnumValidator constructor. - * - * @param PropertyInterface $property - * @param array $allowedValues */ public function __construct(PropertyInterface $property, array $allowedValues) { diff --git a/src/Model/Validator/ExtractedMethodValidator.php b/src/Model/Validator/ExtractedMethodValidator.php index 6a63b61..bf37c9c 100644 --- a/src/Model/Validator/ExtractedMethodValidator.php +++ b/src/Model/Validator/ExtractedMethodValidator.php @@ -15,21 +15,16 @@ */ abstract class ExtractedMethodValidator extends PropertyTemplateValidator { - /** @var string */ - private $extractedMethodName; - /** @var GeneratorConfiguration */ - private $generatorConfiguration; + private string $extractedMethodName; public function __construct( - GeneratorConfiguration $generatorConfiguration, + private GeneratorConfiguration $generatorConfiguration, PropertyInterface $property, string $template, array $templateValues, string $exceptionClass, array $exceptionParams = [], ) { - $this->generatorConfiguration = $generatorConfiguration; - $this->extractedMethodName = sprintf( 'validate%s_%s_%s', str_replace(' ', '', ucfirst($property->getAttribute())), @@ -43,18 +38,10 @@ public function __construct( public function getMethod(): MethodInterface { return new class ($this, $this->generatorConfiguration) implements MethodInterface { - /** @var ExtractedMethodValidator */ - private $validator; - /** @var GeneratorConfiguration */ - private $generatorConfiguration; - public function __construct( - ExtractedMethodValidator $validator, - GeneratorConfiguration $generatorConfiguration, - ) { - $this->validator = $validator; - $this->generatorConfiguration = $generatorConfiguration; - } + private ExtractedMethodValidator $validator, + private GeneratorConfiguration $generatorConfiguration, + ) {} public function getCode(): string { diff --git a/src/Model/Validator/FilterValidator.php b/src/Model/Validator/FilterValidator.php index 3f4fb06..21fdc49 100644 --- a/src/Model/Validator/FilterValidator.php +++ b/src/Model/Validator/FilterValidator.php @@ -22,74 +22,63 @@ */ class FilterValidator extends PropertyTemplateValidator { - /** @var FilterInterface $filter */ - protected $filter; - /** @var array */ - protected $filterOptions; - /** * FilterValidator constructor. * - * @param GeneratorConfiguration $generatorConfiguration - * @param FilterInterface $filter - * @param PropertyInterface $property - * @param array $filterOptions - * @param TransformingFilterInterface|null $transformingFilter - * * @throws SchemaException * @throws ReflectionException */ public function __construct( GeneratorConfiguration $generatorConfiguration, - FilterInterface $filter, + protected FilterInterface $filter, PropertyInterface $property, - array $filterOptions = [], + protected array $filterOptions = [], ?TransformingFilterInterface $transformingFilter = null, ) { $this->isResolved = true; - $this->filter = $filter; - $this->filterOptions = $filterOptions; - $transformingFilter === null - ? $this->validateFilterCompatibilityWithBaseType($filter, $property) - : $this->validateFilterCompatibilityWithTransformedType($filter, $transformingFilter, $property); + ? $this->validateFilterCompatibilityWithBaseType($this->filter, $property) + : $this->validateFilterCompatibilityWithTransformedType($this->filter, $transformingFilter, $property); parent::__construct( $property, DIRECTORY_SEPARATOR . 'Validator' . DIRECTORY_SEPARATOR . 'Filter.phptpl', [ 'skipTransformedValuesCheck' => $transformingFilter !== null ? '!$transformationFailed' : '', - 'isTransformingFilter' => $filter instanceof TransformingFilterInterface, + 'isTransformingFilter' => $this->filter instanceof TransformingFilterInterface, // check if the given value has a type matched by the filter - 'typeCheck' => !empty($filter->getAcceptedTypes()) + 'typeCheck' => !empty($this->filter->getAcceptedTypes()) ? '(' . - implode(' && ', array_map(static function (string $type) use ($property): string { - return ReflectionTypeCheckValidator::fromType($type, $property)->getCheck(); - }, $this->mapDataTypes($filter->getAcceptedTypes()))) . + implode( + ' && ', + array_map( + static fn(string $type): string => + ReflectionTypeCheckValidator::fromType($type, $property)->getCheck(), + $this->mapDataTypes($this->filter->getAcceptedTypes()), + ), + ) . ')' : '', - 'filterClass' => $filter->getFilter()[0], - 'filterMethod' => $filter->getFilter()[1], - 'filterOptions' => var_export($filterOptions, true), + 'filterClass' => $this->filter->getFilter()[0], + 'filterMethod' => $this->filter->getFilter()[1], + 'filterOptions' => var_export($this->filterOptions, true), 'filterValueValidator' => new PropertyValidator( $property, '', InvalidFilterValueException::class, - [$filter->getToken(), '&$filterException'], + [$this->filter->getToken(), '&$filterException'], ), 'viewHelper' => new RenderHelper($generatorConfiguration), ], IncompatibleFilterException::class, - [$filter->getToken()], + [$this->filter->getToken()], ); } /** * Track if a transformation failed. If a transformation fails don't execute subsequent filter as they'd fail with * an invalid type - * - * @return string */ public function getValidatorSetUp(): string { @@ -105,11 +94,6 @@ public function getValidatorSetUp(): string * If transformed values are provided neither filters defined before the transforming filter in the filter chain nor * the transforming filter must be executed as they are only compatible with the original value * - * @param TransformingFilterInterface $filter - * @param PropertyInterface $property - * - * @return self - * * @throws ReflectionException */ public function addTransformedCheck(TransformingFilterInterface $filter, PropertyInterface $property): self { @@ -131,12 +115,9 @@ public function addTransformedCheck(TransformingFilterInterface $filter, Propert /** * Check if the given filter is compatible with the base type of the property defined in the schema * - * @param FilterInterface $filter - * @param PropertyInterface $property - * * @throws SchemaException */ - private function validateFilterCompatibilityWithBaseType(FilterInterface $filter, PropertyInterface $property) + private function validateFilterCompatibilityWithBaseType(FilterInterface $filter, PropertyInterface $property): void { if (empty($filter->getAcceptedTypes()) || !$property->getType()) { return; @@ -165,10 +146,6 @@ private function validateFilterCompatibilityWithBaseType(FilterInterface $filter /** * Check if the given filter is compatible with the result of the given transformation filter * - * @param FilterInterface $filter - * @param TransformingFilterInterface $transformingFilter - * @param PropertyInterface $property - * * @throws ReflectionException * @throws SchemaException */ @@ -204,35 +181,22 @@ private function validateFilterCompatibilityWithTransformedType( /** * Map a list of accepted data types to their corresponding PHP types - * - * @param array $acceptedTypes - * - * @return array */ private function mapDataTypes(array $acceptedTypes): array { - return array_map(static function (string $jsonSchemaType): string { - switch ($jsonSchemaType) { - case 'integer': return 'int'; - case 'number': return 'float'; - case 'boolean': return 'bool'; - - default: return $jsonSchemaType; - } + return array_map(static fn(string $jsonSchemaType): string => match ($jsonSchemaType) { + 'integer' => 'int', + 'number' => 'float', + 'boolean' => 'bool', + default => $jsonSchemaType, }, $acceptedTypes); } - /** - * @return FilterInterface - */ public function getFilter(): FilterInterface { return $this->filter; } - /** - * @return array - */ public function getFilterOptions(): array { return $this->filterOptions; diff --git a/src/Model/Validator/FormatValidator.php b/src/Model/Validator/FormatValidator.php index c533ba2..80fc7de 100644 --- a/src/Model/Validator/FormatValidator.php +++ b/src/Model/Validator/FormatValidator.php @@ -16,40 +16,30 @@ */ class FormatValidator extends AbstractPropertyValidator { - /** @var FormatValidatorInterface */ - protected $validator; - /** * FormatValidator constructor. - * - * @param PropertyInterface $property - * @param FormatValidatorInterface $validator - * @param array $exceptionParams */ public function __construct( PropertyInterface $property, - FormatValidatorInterface $validator, + protected FormatValidatorInterface $validator, array $exceptionParams = [], ) { $this->isResolved = true; - $this->validator = $validator; parent::__construct($property, FormatException::class, $exceptionParams); } /** * Get the source code for the check to perform - * - * @return string */ public function getCheck(): string { return $this->validator instanceof FormatValidatorFromRegEx ? sprintf( '!\%s::validate($value, %s)', - get_class($this->validator), + $this->validator::class, var_export($this->validator->getPattern(), true), ) - : sprintf('!\%s::validate($value)', get_class($this->validator)); + : sprintf('!\%s::validate($value)', $this->validator::class); } } diff --git a/src/Model/Validator/InstanceOfValidator.php b/src/Model/Validator/InstanceOfValidator.php index 6171295..02be09c 100644 --- a/src/Model/Validator/InstanceOfValidator.php +++ b/src/Model/Validator/InstanceOfValidator.php @@ -16,8 +16,6 @@ class InstanceOfValidator extends PropertyValidator { /** * InstanceOfValidator constructor. - * - * @param PropertyInterface $property */ public function __construct(PropertyInterface $property) { diff --git a/src/Model/Validator/MultiTypeCheckValidator.php b/src/Model/Validator/MultiTypeCheckValidator.php index 0ef885c..58f8def 100644 --- a/src/Model/Validator/MultiTypeCheckValidator.php +++ b/src/Model/Validator/MultiTypeCheckValidator.php @@ -14,22 +14,15 @@ */ class MultiTypeCheckValidator extends PropertyValidator implements TypeCheckInterface { - /** @var string[] */ - protected $types; - /** * MultiTypeCheckValidator constructor. * * @param string[] $types - * @param PropertyInterface $property - * @param bool $allowImplicitNull */ - public function __construct(array $types, PropertyInterface $property, bool $allowImplicitNull) + public function __construct(protected array $types, PropertyInterface $property, bool $allowImplicitNull) { - $this->types = $types; - // if null is explicitly allowed we don't need an implicit null pass through - if (in_array('null', $types)) { + if (in_array('null', $this->types)) { $allowImplicitNull = false; } @@ -38,14 +31,13 @@ public function __construct(array $types, PropertyInterface $property, bool $all join( ' && ', array_map( - static function (string $allowedType) use ($property) : string { - return ReflectionTypeCheckValidator::fromType($allowedType, $property)->getCheck(); - }, - $types, + static fn(string $allowedType): string => + ReflectionTypeCheckValidator::fromType($allowedType, $property)->getCheck(), + $this->types, ) ) . ($allowImplicitNull ? ' && $value !== null' : ''), InvalidTypeException::class, - [$types], + [$this->types], ); } diff --git a/src/Model/Validator/NoAdditionalPropertiesValidator.php b/src/Model/Validator/NoAdditionalPropertiesValidator.php index 53830ef..3fe6199 100644 --- a/src/Model/Validator/NoAdditionalPropertiesValidator.php +++ b/src/Model/Validator/NoAdditionalPropertiesValidator.php @@ -17,9 +17,6 @@ class NoAdditionalPropertiesValidator extends PropertyTemplateValidator { /** * PropertyDependencyValidator constructor. - * - * @param PropertyInterface $property - * @param array $json */ public function __construct(PropertyInterface $property, array $json) { diff --git a/src/Model/Validator/PassThroughTypeCheckValidator.php b/src/Model/Validator/PassThroughTypeCheckValidator.php index 082f246..ee61418 100644 --- a/src/Model/Validator/PassThroughTypeCheckValidator.php +++ b/src/Model/Validator/PassThroughTypeCheckValidator.php @@ -16,14 +16,10 @@ class PassThroughTypeCheckValidator extends PropertyValidator implements TypeCheckInterface { /** @var string[] */ - protected $types; + protected array $types; /** * PassThroughTypeCheckValidator constructor. - * - * @param ReflectionType $passThroughType - * @param PropertyInterface $property - * @param TypeCheckValidator $typeCheckValidator */ public function __construct( ReflectionType $passThroughType, diff --git a/src/Model/Validator/PatternPropertiesValidator.php b/src/Model/Validator/PatternPropertiesValidator.php index 2c1853f..7f35957 100644 --- a/src/Model/Validator/PatternPropertiesValidator.php +++ b/src/Model/Validator/PatternPropertiesValidator.php @@ -23,30 +23,20 @@ */ class PatternPropertiesValidator extends PropertyTemplateValidator { - /** @var PropertyInterface */ - private $validationProperty; - /** @var string */ - private $pattern; - /** @var string */ - private $key; + private PropertyInterface $validationProperty; + private string $key; /** * PatternPropertiesValidator constructor. * - * @param SchemaProcessor $schemaProcessor - * @param Schema $schema - * @param string $pattern - * @param JsonSchema $propertyStructure - * * @throws SchemaException */ public function __construct( SchemaProcessor $schemaProcessor, Schema $schema, - string $pattern, + private string $pattern, JsonSchema $propertyStructure, ) { - $this->pattern = $pattern; $this->key = md5($propertyStructure->getJson()['key'] ?? $this->pattern); $propertyFactory = new PropertyFactory(new PropertyProcessorFactory()); @@ -89,25 +79,16 @@ public function getCheck(): string return parent::getCheck(); } - /** - * @return string - */ public function getPattern(): string { return $this->pattern; } - /** - * @return string - */ public function getKey(): string { return $this->key; } - /** - * @return PropertyInterface - */ public function getValidationProperty(): PropertyInterface { return $this->validationProperty; @@ -115,8 +96,6 @@ public function getValidationProperty(): PropertyInterface /** * Initialize all variables which are required to execute a property names validator - * - * @return string */ public function getValidatorSetUp(): string { diff --git a/src/Model/Validator/PropertyDependencyValidator.php b/src/Model/Validator/PropertyDependencyValidator.php index d14f0af..6363d57 100644 --- a/src/Model/Validator/PropertyDependencyValidator.php +++ b/src/Model/Validator/PropertyDependencyValidator.php @@ -17,9 +17,6 @@ class PropertyDependencyValidator extends PropertyTemplateValidator { /** * PropertyDependencyValidator constructor. - * - * @param PropertyInterface $property - * @param array $dependencies */ public function __construct(PropertyInterface $property, array $dependencies) { @@ -38,8 +35,6 @@ public function __construct(PropertyInterface $property, array $dependencies) /** * Initialize all variables which are required to execute a property names validator - * - * @return string */ public function getValidatorSetUp(): string { diff --git a/src/Model/Validator/PropertyNamesValidator.php b/src/Model/Validator/PropertyNamesValidator.php index e738e55..65512bb 100644 --- a/src/Model/Validator/PropertyNamesValidator.php +++ b/src/Model/Validator/PropertyNamesValidator.php @@ -26,10 +26,6 @@ class PropertyNamesValidator extends PropertyTemplateValidator /** * PropertyNamesValidator constructor. * - * @param SchemaProcessor $schemaProcessor - * @param Schema $schema - * @param JsonSchema $propertiesNames - * * @throws SchemaException */ public function __construct( @@ -50,10 +46,10 @@ public function __construct( $nameValidationProperty = (new $processor(new PropertyMetaDataCollection(), $schemaProcessor, $schema)) ->process('property name', $propertiesNames) // the property name validator doesn't need type checks or required checks so simply filter them out - ->filterValidators(static function (Validator $validator): bool { - return !is_a($validator->getValidator(), RequiredPropertyValidator::class) && - !is_a($validator->getValidator(), TypeCheckValidator::class); - }); + ->filterValidators(static fn(Validator $validator): bool => + !is_a($validator->getValidator(), RequiredPropertyValidator::class) && + !is_a($validator->getValidator(), TypeCheckValidator::class), + ); parent::__construct( new Property($schema->getClassName(), null, $propertiesNames), @@ -71,8 +67,6 @@ public function __construct( /** * Initialize all variables which are required to execute a property names validator - * - * @return string */ public function getValidatorSetUp(): string { diff --git a/src/Model/Validator/PropertyTemplateValidator.php b/src/Model/Validator/PropertyTemplateValidator.php index 7040daf..bef91ef 100644 --- a/src/Model/Validator/PropertyTemplateValidator.php +++ b/src/Model/Validator/PropertyTemplateValidator.php @@ -17,33 +17,23 @@ */ class PropertyTemplateValidator extends AbstractPropertyValidator { - /** @var string */ - protected $template; /** @var array */ protected $templateValues; /** @var Schema|null */ - protected $scope = null; + protected $scope; - /** @var Render */ - static private $renderer; + static private ?Render $renderer = null; /** * PropertyTemplateValidator constructor. - * - * @param PropertyInterface $property - * @param string $template - * @param array $templateValues - * @param string $exceptionClass - * @param array $exceptionParams */ public function __construct( PropertyInterface $property, - string $template, + protected string $template, array $templateValues, string $exceptionClass, array $exceptionParams = [], ) { - $this->template = $template; $this->templateValues = $templateValues; parent::__construct($property, $exceptionClass, $exceptionParams); @@ -63,8 +53,6 @@ public function setScope(Schema $schema): void /** * Get the source code for the check to perform * - * @return string - * * @throws RenderException */ public function getCheck(): string @@ -80,9 +68,6 @@ public function getCheck(): string } } - /** - * @return Render - */ protected function getRenderer(): Render { if (!self::$renderer) { diff --git a/src/Model/Validator/PropertyValidator.php b/src/Model/Validator/PropertyValidator.php index 3f54b17..ec66252 100644 --- a/src/Model/Validator/PropertyValidator.php +++ b/src/Model/Validator/PropertyValidator.php @@ -13,33 +13,22 @@ */ class PropertyValidator extends AbstractPropertyValidator { - /** @var string */ - protected $check; - /** * PropertyValidator constructor. - * - * @param PropertyInterface $property - * @param string $check - * @param string $exceptionClass - * @param array $exceptionParams */ public function __construct( PropertyInterface $property, - string $check, + protected string $check, string $exceptionClass, array $exceptionParams = [], ) { $this->isResolved = true; - $this->check = $check; parent::__construct($property, $exceptionClass, $exceptionParams); } /** * Get the source code for the check to perform - * - * @return string */ public function getCheck(): string { diff --git a/src/Model/Validator/PropertyValidatorInterface.php b/src/Model/Validator/PropertyValidatorInterface.php index 9893186..da17528 100644 --- a/src/Model/Validator/PropertyValidatorInterface.php +++ b/src/Model/Validator/PropertyValidatorInterface.php @@ -16,38 +16,26 @@ interface PropertyValidatorInterface extends ResolvableInterface { /** * Get the source code for the check to perform - * - * @return string */ public function getCheck(): string; /** * Get the class of the exception which is thrown if the validation fails - * - * @return string */ public function getExceptionClass(): string; /** * Get the additional data of the exception which is thrown if the validation fails - * - * @return array */ public function getExceptionParams(): array; /** * Get the source code which is required to set up the validator (eg. initialize variables) - * - * @return string */ public function getValidatorSetUp(): string; /** * Get an instance of the validator which is mapped to the property $property - * - * @param PropertyInterface $property - * - * @return PropertyValidatorInterface */ public function withProperty(PropertyInterface $property): PropertyValidatorInterface; } diff --git a/src/Model/Validator/ReflectionTypeCheckValidator.php b/src/Model/Validator/ReflectionTypeCheckValidator.php index e27b51b..ffe6f03 100644 --- a/src/Model/Validator/ReflectionTypeCheckValidator.php +++ b/src/Model/Validator/ReflectionTypeCheckValidator.php @@ -14,12 +14,6 @@ */ class ReflectionTypeCheckValidator extends PropertyValidator { - /** - * @param ReflectionType $reflectionType - * @param PropertyInterface $property - * - * @return static - */ public static function fromReflectionType( ReflectionType $reflectionType, PropertyInterface $property, @@ -31,12 +25,6 @@ public static function fromReflectionType( ); } - /** - * @param string $type - * @param PropertyInterface $property - * - * @return static - */ public static function fromType( string $type, PropertyInterface $property, @@ -50,10 +38,6 @@ public static function fromType( /** * ReflectionTypeCheckValidator constructor. - * - * @param bool $isBuiltin - * @param string $name - * @param PropertyInterface $property */ public function __construct(bool $isBuiltin, string $name, PropertyInterface $property) { diff --git a/src/Model/Validator/RequiredPropertyValidator.php b/src/Model/Validator/RequiredPropertyValidator.php index 5b8028c..3099052 100644 --- a/src/Model/Validator/RequiredPropertyValidator.php +++ b/src/Model/Validator/RequiredPropertyValidator.php @@ -16,8 +16,6 @@ class RequiredPropertyValidator extends PropertyValidator { /** * RequiredPropertyValidator constructor. - * - * @param PropertyInterface $property */ public function __construct(PropertyInterface $property) { diff --git a/src/Model/Validator/SchemaDependencyValidator.php b/src/Model/Validator/SchemaDependencyValidator.php index f12ca80..79d8c4b 100644 --- a/src/Model/Validator/SchemaDependencyValidator.php +++ b/src/Model/Validator/SchemaDependencyValidator.php @@ -23,10 +23,6 @@ class SchemaDependencyValidator extends PropertyTemplateValidator /** * SchemaDependencyValidator constructor. * - * @param SchemaProcessor $schemaProcessor - * @param PropertyInterface $property - * @param Schema $schema - * * @throws SchemaException */ public function __construct(SchemaProcessor $schemaProcessor, PropertyInterface $property, Schema $schema) @@ -54,8 +50,6 @@ public function __construct(SchemaProcessor $schemaProcessor, PropertyInterface /** * Initialize all variables which are required to execute a property names validator - * - * @return string */ public function getValidatorSetUp(): string { diff --git a/src/Model/Validator/TypeCheckValidator.php b/src/Model/Validator/TypeCheckValidator.php index 5deebb2..266d8c3 100644 --- a/src/Model/Validator/TypeCheckValidator.php +++ b/src/Model/Validator/TypeCheckValidator.php @@ -14,15 +14,10 @@ */ class TypeCheckValidator extends PropertyValidator implements TypeCheckInterface { - /** @var string */ - protected $type; + protected string $type; /** * TypeCheckValidator constructor. - * - * @param string $type - * @param PropertyInterface $property - * @param bool $allowImplicitNull */ public function __construct(string $type, PropertyInterface $property, bool $allowImplicitNull) { diff --git a/src/ModelGenerator.php b/src/ModelGenerator.php index 5419afa..6831678 100644 --- a/src/ModelGenerator.php +++ b/src/ModelGenerator.php @@ -30,8 +30,7 @@ */ class ModelGenerator { - /** @var GeneratorConfiguration */ - protected $generatorConfiguration; + protected GeneratorConfiguration $generatorConfiguration; /** @var PostProcessor[] */ protected $postProcessors = []; @@ -52,11 +51,6 @@ public function __construct(?GeneratorConfiguration $generatorConfiguration = nu ->addPostProcessor(new ExtendObjectPropertiesMatchingPatternPropertiesPostProcessor()); } - /** - * @param PostProcessor $postProcessor - * - * @return $this - */ public function addPostProcessor(PostProcessor $postProcessor): self { $this->postProcessors[] = $postProcessor; @@ -70,8 +64,6 @@ public function addPostProcessor(PostProcessor $postProcessor): self * * @param string $modelPath The absolute path to the directory * @param int $directoryMode The mode to create the directory with - * - * @return ModelGenerator */ public function generateModelDirectory(string $modelPath, int $directoryMode = 0777): self { @@ -95,8 +87,6 @@ public function generateModelDirectory(string $modelPath, int $directoryMode = 0 * @param SchemaProviderInterface $schemaProvider The provider used to fetch the JSON schemas to process * @param string $destination The directory where to put the generated PHP models * - * @return array - * * @throws FileSystemException Will be thrown if either the $source or the $destination directory doesn't exist * or the $destination directory is not empty * @throws SchemaException Will be thrown if a schema is invalid or can't be parsed diff --git a/src/PropertyProcessor/ComposedValue/AbstractComposedValueProcessor.php b/src/PropertyProcessor/ComposedValue/AbstractComposedValueProcessor.php index 49f3b74..fa2cf20 100644 --- a/src/PropertyProcessor/ComposedValue/AbstractComposedValueProcessor.php +++ b/src/PropertyProcessor/ComposedValue/AbstractComposedValueProcessor.php @@ -29,28 +29,18 @@ */ abstract class AbstractComposedValueProcessor extends AbstractValueProcessor { - /** @var bool */ - private $rootLevelComposition; - /** @var PropertyInterface|null */ - private $mergedProperty = null; + private ?PropertyInterface $mergedProperty = null; /** * AbstractComposedValueProcessor constructor. - * - * @param PropertyMetaDataCollection $propertyMetaDataCollection - * @param SchemaProcessor $schemaProcessor - * @param Schema $schema - * @param bool $rootLevelComposition */ public function __construct( PropertyMetaDataCollection $propertyMetaDataCollection, SchemaProcessor $schemaProcessor, Schema $schema, - bool $rootLevelComposition, + private bool $rootLevelComposition, ) { parent::__construct($propertyMetaDataCollection, $schemaProcessor, $schema); - - $this->rootLevelComposition = $rootLevelComposition; } /** @@ -123,9 +113,6 @@ function () use (&$resolvedCompositions, $property, $compositionProperties, $pro /** * Set up composition properties for the given property schema * - * @param PropertyInterface $property - * @param JsonSchema $propertySchema - * * @return CompositionPropertyDecorator[] * * @throws SchemaException @@ -157,10 +144,10 @@ protected function getCompositionProperties(PropertyInterface $property, JsonSch ); $compositionProperty->onResolve(function () use ($compositionProperty, $property): void { - $compositionProperty->filterValidators(static function (Validator $validator): bool { - return !is_a($validator->getValidator(), RequiredPropertyValidator::class) && - !is_a($validator->getValidator(), ComposedPropertyValidator::class); - }); + $compositionProperty->filterValidators(static fn(Validator $validator): bool => + !is_a($validator->getValidator(), RequiredPropertyValidator::class) && + !is_a($validator->getValidator(), ComposedPropertyValidator::class) + ); // only create a composed type hint if we aren't a AnyOf or an AllOf processor and the // compositionProperty contains no object. This results in objects being composed each separately for a @@ -180,17 +167,15 @@ protected function getCompositionProperties(PropertyInterface $property, JsonSch /** * Check if the provided property can inherit a single type from the composition properties. * - * @param PropertyInterface $property * @param CompositionPropertyDecorator[] $compositionProperties */ - private function transferPropertyType(PropertyInterface $property, array $compositionProperties) + private function transferPropertyType(PropertyInterface $property, array $compositionProperties): void { $compositionPropertyTypes = array_values( array_unique( array_map( - static function (CompositionPropertyDecorator $property): string { - return $property->getType() ? $property->getType()->getName() : ''; - }, + static fn(CompositionPropertyDecorator $property): string => + $property->getType() ? $property->getType()->getName() : '', $compositionProperties, ) ), @@ -210,8 +195,6 @@ static function (CompositionPropertyDecorator $property): string { /** * @param int $composedElements The amount of elements which are composed together - * - * @return string */ abstract protected function getComposedValueValidation(int $composedElements): string; } diff --git a/src/PropertyProcessor/ComposedValue/IfProcessor.php b/src/PropertyProcessor/ComposedValue/IfProcessor.php index e21df09..fb358eb 100644 --- a/src/PropertyProcessor/ComposedValue/IfProcessor.php +++ b/src/PropertyProcessor/ComposedValue/IfProcessor.php @@ -7,7 +7,6 @@ use PHPModelGenerator\Exception\SchemaException; use PHPModelGenerator\Model\Property\CompositionPropertyDecorator; use PHPModelGenerator\Model\Property\PropertyInterface; -use PHPModelGenerator\Model\Schema; use PHPModelGenerator\Model\SchemaDefinition\JsonSchema; use PHPModelGenerator\Model\Validator; use PHPModelGenerator\Model\Validator\ComposedPropertyValidator; @@ -17,7 +16,6 @@ use PHPModelGenerator\PropertyProcessor\PropertyMetaDataCollection; use PHPModelGenerator\PropertyProcessor\PropertyFactory; use PHPModelGenerator\PropertyProcessor\PropertyProcessorFactory; -use PHPModelGenerator\SchemaProcessor\SchemaProcessor; use PHPModelGenerator\Utils\RenderHelper; /** @@ -70,10 +68,10 @@ protected function generateValidators(PropertyInterface $property, JsonSchema $p ); $compositionProperty->onResolve(static function () use ($compositionProperty): void { - $compositionProperty->filterValidators(static function (Validator $validator): bool { - return !is_a($validator->getValidator(), RequiredPropertyValidator::class) && - !is_a($validator->getValidator(), ComposedPropertyValidator::class); - }); + $compositionProperty->filterValidators(static fn(Validator $validator): bool => + !is_a($validator->getValidator(), RequiredPropertyValidator::class) && + !is_a($validator->getValidator(), ComposedPropertyValidator::class), + ); }); $properties[$compositionElement] = $compositionProperty; diff --git a/src/PropertyProcessor/ComposedValueProcessorFactory.php b/src/PropertyProcessor/ComposedValueProcessorFactory.php index 7bf65ae..f22179a 100644 --- a/src/PropertyProcessor/ComposedValueProcessorFactory.php +++ b/src/PropertyProcessor/ComposedValueProcessorFactory.php @@ -16,18 +16,12 @@ */ class ComposedValueProcessorFactory implements ProcessorFactoryInterface { - /** @var bool */ - private $rootLevelComposition; - /** * ComposedValueProcessorFactory constructor. * * @param bool $rootLevelComposition is the composed value on object root level (true) or on property level (false)? */ - public function __construct(bool $rootLevelComposition) - { - $this->rootLevelComposition = $rootLevelComposition; - } + public function __construct(private bool $rootLevelComposition) {} /** * @inheritdoc diff --git a/src/PropertyProcessor/Decorator/Property/ObjectInstantiationDecorator.php b/src/PropertyProcessor/Decorator/Property/ObjectInstantiationDecorator.php index 9c09623..07a2686 100644 --- a/src/PropertyProcessor/Decorator/Property/ObjectInstantiationDecorator.php +++ b/src/PropertyProcessor/Decorator/Property/ObjectInstantiationDecorator.php @@ -20,22 +20,12 @@ class ObjectInstantiationDecorator implements PropertyDecoratorInterface { /** @var Render */ protected static $renderer; - /** @var string */ - protected $className; - /** @var GeneratorConfiguration */ - protected $generatorConfiguration; /** * ObjectInstantiationDecorator constructor. - * - * @param string $className - * @param GeneratorConfiguration $generatorConfiguration */ - public function __construct(string $className, GeneratorConfiguration $generatorConfiguration) + public function __construct(protected string $className, protected GeneratorConfiguration $generatorConfiguration) { - $this->className = $className; - $this->generatorConfiguration = $generatorConfiguration; - if (!static::$renderer) { static::$renderer = new Render( join(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', '..', 'Templates']) . DIRECTORY_SEPARATOR, diff --git a/src/PropertyProcessor/Decorator/Property/PropertyDecoratorInterface.php b/src/PropertyProcessor/Decorator/Property/PropertyDecoratorInterface.php index 72c176d..f574195 100644 --- a/src/PropertyProcessor/Decorator/Property/PropertyDecoratorInterface.php +++ b/src/PropertyProcessor/Decorator/Property/PropertyDecoratorInterface.php @@ -16,11 +16,7 @@ interface PropertyDecoratorInterface /** * Decorate a given string * - * @param string $input * @param PropertyInterface $property The property getting decorated - * @param bool $nestedProperty - * - * @return string */ public function decorate(string $input, PropertyInterface $property, bool $nestedProperty): string; } diff --git a/src/PropertyProcessor/Decorator/Property/PropertyTransferDecorator.php b/src/PropertyProcessor/Decorator/Property/PropertyTransferDecorator.php index 17d48c3..a8199ab 100644 --- a/src/PropertyProcessor/Decorator/Property/PropertyTransferDecorator.php +++ b/src/PropertyProcessor/Decorator/Property/PropertyTransferDecorator.php @@ -16,18 +16,10 @@ */ class PropertyTransferDecorator implements PropertyDecoratorInterface { - /** @var Property */ - private $property; - /** * PropertyTransferDecorator constructor. - * - * @param PropertyInterface $property */ - public function __construct(PropertyInterface $property) - { - $this->property = $property; - } + public function __construct(private PropertyInterface $property) {} /** * @inheritdoc diff --git a/src/PropertyProcessor/Decorator/SchemaNamespaceTransferDecorator.php b/src/PropertyProcessor/Decorator/SchemaNamespaceTransferDecorator.php index beab652..e5fb919 100644 --- a/src/PropertyProcessor/Decorator/SchemaNamespaceTransferDecorator.php +++ b/src/PropertyProcessor/Decorator/SchemaNamespaceTransferDecorator.php @@ -11,25 +11,15 @@ */ class SchemaNamespaceTransferDecorator { - /** @var Schema */ - private $schema; - /** * SchemaNamespaceTransferDecorator constructor. - * - * @param Schema $schema */ - public function __construct(Schema $schema) - { - $this->schema = $schema; - } + public function __construct(private Schema $schema) {} /** * Get all used classes to use the referenced schema * * @param Schema[] $visitedSchema - * - * @return array */ public function resolve(array $visitedSchema): array { diff --git a/src/PropertyProcessor/Decorator/TypeHint/ArrayTypeHintDecorator.php b/src/PropertyProcessor/Decorator/TypeHint/ArrayTypeHintDecorator.php index a244896..c9baa7b 100644 --- a/src/PropertyProcessor/Decorator/TypeHint/ArrayTypeHintDecorator.php +++ b/src/PropertyProcessor/Decorator/TypeHint/ArrayTypeHintDecorator.php @@ -13,20 +13,9 @@ */ class ArrayTypeHintDecorator implements TypeHintDecoratorInterface { - /** @var PropertyInterface */ - protected $nestedProperty; + private int $recursiveArrayCheck = 0; - private $recursiveArrayCheck = 0; - - /** - * ArrayTypeHintDecorator constructor. - * - * @param PropertyInterface $nestedProperty - */ - public function __construct(PropertyInterface $nestedProperty) - { - $this->nestedProperty = $nestedProperty; - } + public function __construct(protected PropertyInterface $nestedProperty) {} /** * @inheritdoc @@ -41,9 +30,7 @@ public function decorate(string $input, bool $outputType = false): string $result = implode( '|', array_map( - static function (string $typeHint): string { - return "{$typeHint}[]"; - }, + static fn(string $typeHint): string => "{$typeHint}[]", explode('|', $this->nestedProperty->getTypeHint($outputType)), ) ); diff --git a/src/PropertyProcessor/Decorator/TypeHint/CompositionTypeHintDecorator.php b/src/PropertyProcessor/Decorator/TypeHint/CompositionTypeHintDecorator.php index e74fa2c..55614de 100644 --- a/src/PropertyProcessor/Decorator/TypeHint/CompositionTypeHintDecorator.php +++ b/src/PropertyProcessor/Decorator/TypeHint/CompositionTypeHintDecorator.php @@ -13,18 +13,7 @@ */ class CompositionTypeHintDecorator implements TypeHintDecoratorInterface { - /** @var PropertyInterface */ - protected $nestedProperty; - - /** - * CompositionTypeHintDecorator constructor. - * - * @param PropertyInterface $nestedProperty - */ - public function __construct(PropertyInterface $nestedProperty) - { - $this->nestedProperty = $nestedProperty; - } + public function __construct(protected PropertyInterface $nestedProperty) {} /** * @inheritdoc diff --git a/src/PropertyProcessor/Decorator/TypeHint/TypeHintDecorator.php b/src/PropertyProcessor/Decorator/TypeHint/TypeHintDecorator.php index 7fd6589..b78e8e8 100644 --- a/src/PropertyProcessor/Decorator/TypeHint/TypeHintDecorator.php +++ b/src/PropertyProcessor/Decorator/TypeHint/TypeHintDecorator.php @@ -11,18 +11,7 @@ */ class TypeHintDecorator implements TypeHintDecoratorInterface { - /** @var array */ - protected $types; - - /** - * TypeHintDecorator constructor. - * - * @param array $types - */ - public function __construct(array $types) - { - $this->types = $types; - } + public function __construct(protected array $types) {} /** * @inheritdoc diff --git a/src/PropertyProcessor/Decorator/TypeHint/TypeHintDecoratorInterface.php b/src/PropertyProcessor/Decorator/TypeHint/TypeHintDecoratorInterface.php index 4fc92d4..1716fea 100644 --- a/src/PropertyProcessor/Decorator/TypeHint/TypeHintDecoratorInterface.php +++ b/src/PropertyProcessor/Decorator/TypeHint/TypeHintDecoratorInterface.php @@ -15,9 +15,6 @@ interface TypeHintDecoratorInterface * Decorate a given string * * @param string $input The input getting decorated - * @param bool $outputType - * - * @return string */ public function decorate(string $input, bool $outputType = false): string; } diff --git a/src/PropertyProcessor/Decorator/TypeHint/TypeHintTransferDecorator.php b/src/PropertyProcessor/Decorator/TypeHint/TypeHintTransferDecorator.php index 0c64c74..48e477b 100644 --- a/src/PropertyProcessor/Decorator/TypeHint/TypeHintTransferDecorator.php +++ b/src/PropertyProcessor/Decorator/TypeHint/TypeHintTransferDecorator.php @@ -13,18 +13,7 @@ */ class TypeHintTransferDecorator implements TypeHintDecoratorInterface { - /** @var PropertyInterface */ - protected $property; - - /** - * ArrayTypeHintDecorator constructor. - * - * @param PropertyInterface $property - */ - public function __construct(PropertyInterface $property) - { - $this->property = $property; - } + public function __construct(protected PropertyInterface $property) {} /** * @inheritdoc diff --git a/src/PropertyProcessor/Filter/FilterProcessor.php b/src/PropertyProcessor/Filter/FilterProcessor.php index 70c63fd..365081d 100644 --- a/src/PropertyProcessor/Filter/FilterProcessor.php +++ b/src/PropertyProcessor/Filter/FilterProcessor.php @@ -32,17 +32,12 @@ class FilterProcessor { /** - * @param PropertyInterface $property - * @param mixed $filterList - * @param GeneratorConfiguration $generatorConfiguration - * @param Schema $schema - * * @throws ReflectionException * @throws SchemaException */ public function process( PropertyInterface $property, - $filterList, + mixed $filterList, GeneratorConfiguration $generatorConfiguration, Schema $schema, ): void { @@ -149,10 +144,6 @@ public function process( * By adding the pass through eg. a trim filter executed before a dateTime transforming filter will not be executed * if a DateTime object is provided for the property * - * @param PropertyInterface $property - * @param TransformingFilterInterface $filter - * @param ReflectionType $filteredType - * * @throws ReflectionException */ private function addTransformedValuePassThrough( @@ -168,9 +159,9 @@ private function addTransformedValuePassThrough( } if ($validator instanceof EnumValidator) { - $property->filterValidators(static function (Validator $validator): bool { - return !is_a($validator->getValidator(), EnumValidator::class); - }); + $property->filterValidators( + static fn(Validator $validator): bool => !is_a($validator->getValidator(), EnumValidator::class), + ); // shift the name from the validator to avoid adding it twice by wrapping the validator into another one $exceptionParams = $validator->getExceptionParams(); @@ -196,9 +187,6 @@ private function addTransformedValuePassThrough( /** * Extend a type check of the given property so the type check also allows the type of $typeAfterFilter. This is * used to allow also already transformed values as valid input values - * - * @param PropertyInterface $property - * @param ReflectionType $typeAfterFilter */ private function extendTypeCheckValidatorToAllowTransformedValue( PropertyInterface $property, diff --git a/src/PropertyProcessor/ProcessorFactoryInterface.php b/src/PropertyProcessor/ProcessorFactoryInterface.php index 15398f6..2484dad 100644 --- a/src/PropertyProcessor/ProcessorFactoryInterface.php +++ b/src/PropertyProcessor/ProcessorFactoryInterface.php @@ -16,11 +16,6 @@ interface ProcessorFactoryInterface { /** * @param string|array $type - * @param PropertyMetaDataCollection $propertyMetaDataCollection - * @param SchemaProcessor $schemaProcessor - * @param Schema $schema - * - * @return PropertyProcessorInterface */ public function getProcessor( $type, diff --git a/src/PropertyProcessor/Property/AbstractNumericProcessor.php b/src/PropertyProcessor/Property/AbstractNumericProcessor.php index c26df69..bb0b29c 100644 --- a/src/PropertyProcessor/Property/AbstractNumericProcessor.php +++ b/src/PropertyProcessor/Property/AbstractNumericProcessor.php @@ -91,9 +91,6 @@ protected function addRangeValidator( /** * Adds a multiple of validator to the property - * - * @param PropertyInterface $property - * @param JsonSchema $propertySchema */ protected function addMultipleOfValidator(PropertyInterface $property, JsonSchema $propertySchema) { diff --git a/src/PropertyProcessor/Property/AbstractPropertyProcessor.php b/src/PropertyProcessor/Property/AbstractPropertyProcessor.php index 3198400..908e512 100644 --- a/src/PropertyProcessor/Property/AbstractPropertyProcessor.php +++ b/src/PropertyProcessor/Property/AbstractPropertyProcessor.php @@ -31,36 +31,15 @@ */ abstract class AbstractPropertyProcessor implements PropertyProcessorInterface { - /** @var PropertyMetaDataCollection */ - protected $propertyMetaDataCollection; - /** @var SchemaProcessor */ - protected $schemaProcessor; - /** @var Schema */ - protected $schema; - - /** - * AbstractPropertyProcessor constructor. - * - * @param PropertyMetaDataCollection $propertyMetaDataCollection - * @param SchemaProcessor $schemaProcessor - * @param Schema $schema - */ public function __construct( - PropertyMetaDataCollection $propertyMetaDataCollection, - SchemaProcessor $schemaProcessor, - Schema $schema, - ) { - $this->propertyMetaDataCollection = $propertyMetaDataCollection; - $this->schemaProcessor = $schemaProcessor; - $this->schema = $schema; - } + protected PropertyMetaDataCollection $propertyMetaDataCollection, + protected SchemaProcessor $schemaProcessor, + protected Schema $schema + ) {} /** * Generates the validators for the property * - * @param PropertyInterface $property - * @param JsonSchema $propertySchema - * * @throws SchemaException */ protected function generateValidators(PropertyInterface $property, JsonSchema $propertySchema): void @@ -83,9 +62,6 @@ protected function generateValidators(PropertyInterface $property, JsonSchema $p /** * Add a validator to a property which validates the value against a list of allowed values * - * @param PropertyInterface $property - * @param array $allowedValues - * * @throws SchemaException */ protected function addEnumValidator(PropertyInterface $property, array $allowedValues): void @@ -105,9 +81,7 @@ protected function addEnumValidator(PropertyInterface $property, array $allowedV // no type information provided - inherit the types from the enum values if (!$property->getType()) { $typesOfEnum = array_unique(array_map( - static function ($value): string { - return TypeConverter::gettypeToInternal(gettype($value)); - }, + static fn($value): string => TypeConverter::gettypeToInternal(gettype($value)), $allowedValues, )); @@ -125,9 +99,6 @@ static function ($value): string { } /** - * @param PropertyInterface $property - * @param array $dependencies - * * @throws SchemaException */ protected function addDependencyValidator(PropertyInterface $property, array $dependencies): void @@ -167,8 +138,6 @@ static function ($dependency, $index) use (&$propertyDependency): void { /** * Transfer all properties from $dependencySchema to the base schema of the current property - * - * @param Schema $dependencySchema */ private function transferDependentPropertiesToBaseSchema(Schema $dependencySchema): void { @@ -179,17 +148,12 @@ private function transferDependentPropertiesToBaseSchema(Schema $dependencySchem (clone $property) ->setRequired(false) ->setType(null) - ->filterValidators(static function (): bool { - return false; - }), + ->filterValidators(static fn(): bool => false), ); } } /** - * @param PropertyInterface $property - * @param JsonSchema $propertySchema - * * @throws SchemaException */ protected function addComposedValueValidator(PropertyInterface $property, JsonSchema $propertySchema): void @@ -234,11 +198,6 @@ protected function addComposedValueValidator(PropertyInterface $property, JsonSc /** * If the type of a property containing a composition is defined outside of the composition make sure each * composition which doesn't define a type inherits the type - * - * @param JsonSchema $propertySchema - * @param string $composedValueKeyword - * - * @return JsonSchema */ protected function inheritPropertyType(JsonSchema $propertySchema, string $composedValueKeyword): JsonSchema { @@ -273,10 +232,6 @@ protected function inheritPropertyType(JsonSchema $propertySchema, string $compo /** * Inherit the type of a property into all composed components of a conditional composition - * - * @param JsonSchema $propertySchema - * - * @return JsonSchema */ protected function inheritIfPropertyType(JsonSchema $propertySchema): JsonSchema { @@ -298,10 +253,6 @@ protected function inheritIfPropertyType(JsonSchema $propertySchema): JsonSchema /** * Check if implicit null values are allowed for the given property (a not required property which has no * explicit null type and is passed with a null value will be accepted) - * - * @param PropertyInterface $property - * - * @return bool */ protected function isImplicitNullAllowed(PropertyInterface $property): bool { diff --git a/src/PropertyProcessor/Property/AbstractTypedValueProcessor.php b/src/PropertyProcessor/Property/AbstractTypedValueProcessor.php index 495cb26..6947a35 100644 --- a/src/PropertyProcessor/Property/AbstractTypedValueProcessor.php +++ b/src/PropertyProcessor/Property/AbstractTypedValueProcessor.php @@ -23,10 +23,6 @@ abstract class AbstractTypedValueProcessor extends AbstractValueProcessor /** * AbstractTypedValueProcessor constructor. - * - * @param PropertyMetaDataCollection $propertyMetaDataCollection - * @param SchemaProcessor $schemaProcessor - * @param Schema $schema */ public function __construct( PropertyMetaDataCollection $propertyMetaDataCollection, @@ -37,11 +33,6 @@ public function __construct( } /** - * @param string $propertyName - * @param JsonSchema $propertySchema - * - * @return PropertyInterface - * * @throws SchemaException */ public function process(string $propertyName, JsonSchema $propertySchema): PropertyInterface @@ -56,13 +47,9 @@ public function process(string $propertyName, JsonSchema $propertySchema): Prope } /** - * @param PropertyInterface $property - * @param mixed $default - * @param JsonSchema $propertySchema - * * @throws SchemaException */ - public function setDefaultValue(PropertyInterface $property, $default, JsonSchema $propertySchema): void + public function setDefaultValue(PropertyInterface $property, mixed $default, JsonSchema $propertySchema): void { // allow integer default values for Number properties if ($this instanceof NumberProcessor && is_int($default)) { diff --git a/src/PropertyProcessor/Property/AbstractValueProcessor.php b/src/PropertyProcessor/Property/AbstractValueProcessor.php index 585f0e0..d47c001 100644 --- a/src/PropertyProcessor/Property/AbstractValueProcessor.php +++ b/src/PropertyProcessor/Property/AbstractValueProcessor.php @@ -22,24 +22,16 @@ */ abstract class AbstractValueProcessor extends AbstractPropertyProcessor { - private $type = ''; - /** * AbstractValueProcessor constructor. - * - * @param PropertyMetaDataCollection $propertyMetaDataCollection - * @param SchemaProcessor $schemaProcessor - * @param Schema $schema - * @param string $type */ public function __construct( PropertyMetaDataCollection $propertyMetaDataCollection, SchemaProcessor $schemaProcessor, Schema $schema, - string $type = '', + private string $type = '', ) { parent::__construct($propertyMetaDataCollection, $schemaProcessor, $schema); - $this->type = $type; } /** diff --git a/src/PropertyProcessor/Property/AnyProcessor.php b/src/PropertyProcessor/Property/AnyProcessor.php index 69524cc..9cc41e9 100644 --- a/src/PropertyProcessor/Property/AnyProcessor.php +++ b/src/PropertyProcessor/Property/AnyProcessor.php @@ -14,12 +14,6 @@ */ class AnyProcessor extends AbstractValueProcessor { - /** - * @param string $propertyName - * @param JsonSchema $propertySchema - * - * @return PropertyInterface - */ public function process(string $propertyName, JsonSchema $propertySchema): PropertyInterface { $property = parent::process($propertyName, $propertySchema); diff --git a/src/PropertyProcessor/Property/ArrayProcessor.php b/src/PropertyProcessor/Property/ArrayProcessor.php index 0057fcb..709352b 100644 --- a/src/PropertyProcessor/Property/ArrayProcessor.php +++ b/src/PropertyProcessor/Property/ArrayProcessor.php @@ -44,9 +44,6 @@ class ArrayProcessor extends AbstractTypedValueProcessor private const JSON_FIELD_CONTAINS = 'contains'; /** - * @param PropertyInterface $property - * @param JsonSchema $propertySchema - * * @throws FileSystemException * @throws SchemaException * @throws SyntaxErrorException @@ -81,9 +78,6 @@ protected function generateValidators(PropertyInterface $property, JsonSchema $p /** * Add the vaidation for the allowed amount of items in the array - * - * @param PropertyInterface $property - * @param JsonSchema $propertySchema */ private function addLengthValidation(PropertyInterface $property, JsonSchema $propertySchema): void { @@ -114,9 +108,6 @@ private function addLengthValidation(PropertyInterface $property, JsonSchema $pr /** * Add the validator to check if the items inside an array are unique - * - * @param PropertyInterface $property - * @param JsonSchema $propertySchema */ private function addUniqueItemsValidation(PropertyInterface $property, JsonSchema $propertySchema): void { @@ -139,9 +130,6 @@ private function addUniqueItemsValidation(PropertyInterface $property, JsonSchem /** * Add the validator to check for constraints required for each item * - * @param PropertyInterface $property - * @param JsonSchema $propertySchema - * * @throws FileSystemException * @throws SchemaException * @throws SyntaxErrorException @@ -177,9 +165,6 @@ private function addItemsValidation(PropertyInterface $property, JsonSchema $pro /** * Add the validator to check a tuple validation for each item of the array * - * @param PropertyInterface $property - * @param JsonSchema $propertySchema - * * @throws SchemaException * @throws FileSystemException * @throws SyntaxErrorException @@ -204,9 +189,6 @@ private function addTupleValidator(PropertyInterface $property, JsonSchema $prop } /** - * @param PropertyInterface $property - * @param JsonSchema $propertySchema - * * @throws FileSystemException * @throws SchemaException * @throws SyntaxErrorException @@ -244,9 +226,6 @@ private function addAdditionalItemsValidator(PropertyInterface $property, JsonSc /** * Add the validator to check for constraints required for at least one item * - * @param PropertyInterface $property - * @param JsonSchema $propertySchema - * * @throws SchemaException */ private function addContainsValidation(PropertyInterface $property, JsonSchema $propertySchema): void @@ -266,9 +245,9 @@ private function addContainsValidation(PropertyInterface $property, JsonSchema $ $propertySchema->withJson($propertySchema->getJson()[self::JSON_FIELD_CONTAINS]), ); - $nestedProperty->filterValidators(static function (Validator $validator): bool { - return !is_a($validator->getValidator(), RequiredPropertyValidator::class); - }); + $nestedProperty->filterValidators(static fn(Validator $validator): bool => + !is_a($validator->getValidator(), RequiredPropertyValidator::class) + ); $property->addValidator( new PropertyTemplateValidator( diff --git a/src/PropertyProcessor/Property/BaseProcessor.php b/src/PropertyProcessor/Property/BaseProcessor.php index 9a1995e..cf7fb25 100644 --- a/src/PropertyProcessor/Property/BaseProcessor.php +++ b/src/PropertyProcessor/Property/BaseProcessor.php @@ -52,11 +52,6 @@ class BaseProcessor extends AbstractPropertyProcessor /** * @inheritdoc * - * @param string $propertyName - * @param JsonSchema $propertySchema - * - * @return PropertyInterface - * * @throws FileSystemException * @throws SchemaException * @throws SyntaxErrorException @@ -88,8 +83,6 @@ public function process(string $propertyName, JsonSchema $propertySchema): Prope /** * Add a validator to check all provided property names * - * @param JsonSchema $propertySchema - * * @throws SchemaException * @throws FileSystemException * @throws SyntaxErrorException @@ -113,8 +106,6 @@ protected function addPropertyNamesValidator(JsonSchema $propertySchema): void /** * Add an object validator to specify constraints for properties which are not defined in the schema * - * @param JsonSchema $propertySchema - * * @throws FileSystemException * @throws SchemaException * @throws SyntaxErrorException @@ -155,8 +146,6 @@ protected function addAdditionalPropertiesValidator(JsonSchema $propertySchema): } /** - * @param JsonSchema $propertySchema - * * @throws SchemaException */ protected function addPatternPropertiesValidator(JsonSchema $propertySchema): void @@ -190,9 +179,6 @@ protected function addPatternPropertiesValidator(JsonSchema $propertySchema): vo /** * Add an object validator to limit the amount of provided properties * - * @param string $propertyName - * @param JsonSchema $propertySchema - * * @throws SchemaException */ protected function addMaxPropertiesValidator(string $propertyName, JsonSchema $propertySchema): void @@ -220,9 +206,6 @@ protected function addMaxPropertiesValidator(string $propertyName, JsonSchema $p /** * Add an object validator to force at least the defined amount of properties to be provided * - * @param string $propertyName - * @param JsonSchema $propertySchema - * * @throws SchemaException */ protected function addMinPropertiesValidator(string $propertyName, JsonSchema $propertySchema): void @@ -250,8 +233,6 @@ protected function addMinPropertiesValidator(string $propertyName, JsonSchema $p /** * Add the properties defined in the JSON schema to the current schema model * - * @param JsonSchema $propertySchema - * * @throws SchemaException */ protected function addPropertiesToSchema(JsonSchema $propertySchema): void @@ -264,7 +245,7 @@ protected function addPropertiesToSchema(JsonSchema $propertySchema): void $json['dependencies'] ?? [], ); - $json['properties'] = $json['properties'] ?? []; + $json['properties'] ??= []; // setup empty properties for required properties which aren't defined in the properties section of the schema $json['properties'] += array_fill_keys( array_diff($json['required'] ?? [], array_keys($json['properties'])), @@ -288,8 +269,6 @@ protected function addPropertiesToSchema(JsonSchema $propertySchema): void * Transfer properties of composed properties to the current schema to offer a complete model including all * composed properties. * - * @param PropertyInterface $property - * * @throws SchemaException */ protected function transferComposedPropertiesToSchema(PropertyInterface $property): void @@ -346,20 +325,15 @@ function () use ($composedProperty, $validator): void { /** * Clone the provided property to transfer it to a schema. Sets the nullability and required flag based on the * composition processor used to set up the composition - * - * @param PropertyInterface $property - * @param string $compositionProcessor - * - * @return PropertyInterface */ private function cloneTransferredProperty( PropertyInterface $property, string $compositionProcessor, ): PropertyInterface { $transferredProperty = (clone $property) - ->filterValidators(static function (Validator $validator): bool { - return is_a($validator->getValidator(), PropertyTemplateValidator::class); - }); + ->filterValidators(static fn(Validator $validator): bool => + is_a($validator->getValidator(), PropertyTemplateValidator::class) + ); if (!is_a($compositionProcessor, AllOfProcessor::class, true)) { $transferredProperty->setRequired(false); diff --git a/src/PropertyProcessor/Property/MultiTypeProcessor.php b/src/PropertyProcessor/Property/MultiTypeProcessor.php index 750b111..edf563c 100644 --- a/src/PropertyProcessor/Property/MultiTypeProcessor.php +++ b/src/PropertyProcessor/Property/MultiTypeProcessor.php @@ -35,12 +35,6 @@ class MultiTypeProcessor extends AbstractValueProcessor /** * MultiTypePropertyProcessor constructor. * - * @param PropertyProcessorFactory $propertyProcessorFactory - * @param array $types - * @param PropertyMetaDataCollection $propertyMetaDataCollection - * @param SchemaProcessor $schemaProcessor - * @param Schema $schema - * * @throws SchemaException */ public function __construct( @@ -68,8 +62,6 @@ public function __construct( * @param string $propertyName The name of the property * @param JsonSchema $propertySchema The schema of the property * - * @return PropertyInterface - * * @throws SchemaException * @throws ReflectionException */ @@ -86,7 +78,7 @@ public function process(string $propertyName, JsonSchema $propertySchema): Prope $processedSubProperties = 0; foreach ($subProperties as $subProperty) { - $subProperty->onResolve(function () use ($property, $subProperties, &$processedSubProperties) { + $subProperty->onResolve(function () use ($property, $subProperties, &$processedSubProperties): void { if (++$processedSubProperties === count($subProperties)) { if (empty($this->allowedPropertyTypes)) { return; @@ -95,9 +87,7 @@ public function process(string $propertyName, JsonSchema $propertySchema): Prope $property->addTypeHintDecorator( new TypeHintDecorator( array_map( - static function (PropertyInterface $subProperty): string { - return $subProperty->getTypeHint(); - }, + static fn(PropertyInterface $subProperty): string => $subProperty->getTypeHint(), $subProperties, ) ), @@ -121,9 +111,6 @@ static function (PropertyInterface $subProperty): string { /** * Move validators from the $source property to the $destination property - * - * @param PropertyInterface $source - * @param PropertyInterface $destination */ protected function transferValidators(PropertyInterface $source, PropertyInterface $destination) { @@ -148,10 +135,6 @@ protected function transferValidators(PropertyInterface $source, PropertyInterfa } /** - * @param string $propertyName - * @param JsonSchema $propertySchema - * @param PropertyInterface $property - * * @return PropertyInterface[] * * @throws SchemaException diff --git a/src/PropertyProcessor/Property/NullProcessor.php b/src/PropertyProcessor/Property/NullProcessor.php index 268f35b..9fdb680 100644 --- a/src/PropertyProcessor/Property/NullProcessor.php +++ b/src/PropertyProcessor/Property/NullProcessor.php @@ -19,11 +19,6 @@ class NullProcessor extends AbstractTypedValueProcessor /** * Explicitly unset the type of the property - * - * @param string $propertyName - * @param JsonSchema $propertySchema - * - * @return PropertyInterface */ public function process(string $propertyName, JsonSchema $propertySchema): PropertyInterface { diff --git a/src/PropertyProcessor/Property/StringProcessor.php b/src/PropertyProcessor/Property/StringProcessor.php index 8b9f8bb..24e8819 100644 --- a/src/PropertyProcessor/Property/StringProcessor.php +++ b/src/PropertyProcessor/Property/StringProcessor.php @@ -28,9 +28,6 @@ class StringProcessor extends AbstractTypedValueProcessor protected const JSON_FIELD_MAX_LENGTH = 'maxLength'; /** - * @param PropertyInterface $property - * @param JsonSchema $propertySchema - * * @throws SchemaException */ protected function generateValidators(PropertyInterface $property, JsonSchema $propertySchema): void @@ -45,9 +42,6 @@ protected function generateValidators(PropertyInterface $property, JsonSchema $p /** * Add a regex pattern validator * - * @param PropertyInterface $property - * @param JsonSchema $propertySchema - * * @throws SchemaException */ protected function addPatternValidator(PropertyInterface $property, JsonSchema $propertySchema): void @@ -85,9 +79,6 @@ protected function addPatternValidator(PropertyInterface $property, JsonSchema $ /** * Add min and max length validator - * - * @param PropertyInterface $property - * @param JsonSchema $propertySchema */ protected function addLengthValidator(PropertyInterface $property, JsonSchema $propertySchema): void { @@ -117,9 +108,6 @@ protected function addLengthValidator(PropertyInterface $property, JsonSchema $p } /** - * @param PropertyInterface $property - * @param JsonSchema $propertySchema - * * @throws SchemaException */ protected function addFormatValidator(PropertyInterface $property, JsonSchema $propertySchema): void diff --git a/src/PropertyProcessor/PropertyFactory.php b/src/PropertyProcessor/PropertyFactory.php index 7be1c1d..5ef4b1d 100644 --- a/src/PropertyProcessor/PropertyFactory.php +++ b/src/PropertyProcessor/PropertyFactory.php @@ -17,29 +17,11 @@ */ class PropertyFactory { - /** @var ProcessorFactoryInterface */ - protected $processorFactory; - - /** - * PropertyFactory constructor. - * - * @param ProcessorFactoryInterface $processorFactory - */ - public function __construct(ProcessorFactoryInterface $processorFactory) - { - $this->processorFactory = $processorFactory; - } + public function __construct(protected ProcessorFactoryInterface $processorFactory) {} /** * Create a property * - * @param PropertyMetaDataCollection $propertyMetaDataCollection - * @param SchemaProcessor $schemaProcessor - * @param Schema $schema - * @param string $propertyName - * @param JsonSchema $propertySchema - * - * @return PropertyInterface * @throws SchemaException */ public function create( diff --git a/src/PropertyProcessor/PropertyMetaDataCollection.php b/src/PropertyProcessor/PropertyMetaDataCollection.php index 6e7e9fb..1c9b6bc 100644 --- a/src/PropertyProcessor/PropertyMetaDataCollection.php +++ b/src/PropertyProcessor/PropertyMetaDataCollection.php @@ -13,11 +13,6 @@ */ class PropertyMetaDataCollection { - /** @var array */ - protected $requiredAttributes = []; - /** @var array */ - protected $dependencies = []; - /** * PropertyMetaDataCollection constructor. * @@ -27,18 +22,10 @@ class PropertyMetaDataCollection * are required if the key attribute is present or a valid schema which must be * fulfilled if the key attribute is present */ - public function __construct(array $requiredAttributes = [], array $dependencies = []) - { - $this->requiredAttributes = $requiredAttributes; - $this->dependencies = $dependencies; - } + public function __construct(protected array $requiredAttributes = [], protected array $dependencies = []) {} /** * Check if a given attribute is required - * - * @param string $attribute - * - * @return bool */ public function isAttributeRequired(string $attribute): bool { @@ -47,10 +34,6 @@ public function isAttributeRequired(string $attribute): bool /** * Get the dependencies for the requested attribute - * - * @param string $attribute - * - * @return array|null */ public function getAttributeDependencies(string $attribute): ?array { diff --git a/src/PropertyProcessor/PropertyProcessorFactory.php b/src/PropertyProcessor/PropertyProcessorFactory.php index 3ea1a69..9b7f5f3 100644 --- a/src/PropertyProcessor/PropertyProcessorFactory.php +++ b/src/PropertyProcessor/PropertyProcessorFactory.php @@ -18,11 +18,7 @@ class PropertyProcessorFactory implements ProcessorFactoryInterface { /** * @param string|array $type - * @param PropertyMetaDataCollection $propertyMetaDataCollection - * @param SchemaProcessor $schemaProcessor - * @param Schema $schema * - * @return PropertyProcessorInterface * @throws SchemaException */ public function getProcessor( @@ -54,12 +50,6 @@ public function getProcessor( } /** - * @param string $type - * @param PropertyMetaDataCollection $propertyMetaDataCollection - * @param SchemaProcessor $schemaProcessor - * @param Schema $schema - * - * @return PropertyProcessorInterface * @throws SchemaException */ protected function getSingleTypePropertyProcessor( diff --git a/src/PropertyProcessor/PropertyProcessorInterface.php b/src/PropertyProcessor/PropertyProcessorInterface.php index 4d74410..dca0ec0 100644 --- a/src/PropertyProcessor/PropertyProcessorInterface.php +++ b/src/PropertyProcessor/PropertyProcessorInterface.php @@ -19,8 +19,6 @@ interface PropertyProcessorInterface * * @param string $propertyName The name of the property * @param JsonSchema $propertySchema The schema of the property - * - * @return PropertyInterface */ public function process(string $propertyName, JsonSchema $propertySchema): PropertyInterface; } diff --git a/src/SchemaProcessor/Hook/SchemaHookResolver.php b/src/SchemaProcessor/Hook/SchemaHookResolver.php index f60b671..3eb6efc 100644 --- a/src/SchemaProcessor/Hook/SchemaHookResolver.php +++ b/src/SchemaProcessor/Hook/SchemaHookResolver.php @@ -9,13 +9,7 @@ class SchemaHookResolver { - /** @var Schema */ - private $schema; - - public function __construct(Schema $schema) - { - $this->schema = $schema; - } + public function __construct(private Schema $schema) {} public function resolveConstructorBeforeValidationHook(): string { @@ -47,23 +41,22 @@ public function resolveSerializationHook(): string return $this->resolveHook(SerializationHookInterface::class); } + /** + * @return SchemaHookInterface[] + */ private function getHooks(string $filterHook): array { return array_filter( $this->schema->getSchemaHooks(), - static function (SchemaHookInterface $hook) use ($filterHook): bool { - return is_a($hook, $filterHook); - }, + static fn(SchemaHookInterface $hook): bool => is_a($hook, $filterHook), ); } - private function resolveHook(string $filterHook, ...$parameters): string + private function resolveHook(string $filterHook, mixed ...$parameters): string { return join( "\n\n", - array_map(static function ($hook) use ($parameters): string { - return $hook->getCode(...$parameters); - }, $this->getHooks($filterHook)), + array_map(static fn($hook): string => $hook->getCode(...$parameters), $this->getHooks($filterHook)), ); } } diff --git a/src/SchemaProcessor/PostProcessor/AdditionalPropertiesAccessorPostProcessor.php b/src/SchemaProcessor/PostProcessor/AdditionalPropertiesAccessorPostProcessor.php index 922946f..2c254f3 100644 --- a/src/SchemaProcessor/PostProcessor/AdditionalPropertiesAccessorPostProcessor.php +++ b/src/SchemaProcessor/PostProcessor/AdditionalPropertiesAccessorPostProcessor.php @@ -28,28 +28,19 @@ */ class AdditionalPropertiesAccessorPostProcessor extends PostProcessor { - /** @var bool */ - private $addForModelsWithoutAdditionalPropertiesDefinition; - /** * AdditionalPropertiesAccessorPostProcessor constructor. * - * @param bool $addForModelsWithoutAdditionalPropertiesDefinition By default the additional properties accessor + * @param bool $addForModelsWithoutAdditionalPropertiesDefinition By default, the additional properties accessor * methods will be added only to schemas defining additionalProperties constraints as these models expect additional * properties. If set to true the accessor methods will be generated for models which don't define * additionalProperties constraints. */ - public function __construct(bool $addForModelsWithoutAdditionalPropertiesDefinition = false) - { - $this->addForModelsWithoutAdditionalPropertiesDefinition = $addForModelsWithoutAdditionalPropertiesDefinition; - } + public function __construct(private bool $addForModelsWithoutAdditionalPropertiesDefinition = false) {} /** * Add methods to handle additional properties to the provided schema * - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration - * * @throws SchemaException */ public function process(Schema $schema, GeneratorConfiguration $generatorConfiguration): void @@ -92,10 +83,6 @@ public function process(Schema $schema, GeneratorConfiguration $generatorConfigu /** * Adds a method to add or update an additional property - * - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration - * @param PropertyInterface|null $validationProperty */ private function addSetAdditionalPropertyMethod( Schema $schema, @@ -104,14 +91,10 @@ private function addSetAdditionalPropertyMethod( ): void { $objectProperties = RenderHelper::varExportArray( array_map( - static function (PropertyInterface $property): string { - return $property->getName(); - }, + static fn(PropertyInterface $property): string => $property->getName(), array_filter( $schema->getProperties(), - static function (PropertyInterface $property): bool { - return !$property->isInternal(); - }, + static fn(PropertyInterface $property): bool => !$property->isInternal(), ) ), ); @@ -135,9 +118,6 @@ static function (PropertyInterface $property): bool { /** * Adds a method to remove an additional property from the object via property key * - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration - * * @throws SchemaException */ private function addRemoveAdditionalPropertyMethod( @@ -172,10 +152,6 @@ private function addRemoveAdditionalPropertyMethod( /** * Adds a method to get a single additional property via property key - * - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration - * @param PropertyInterface|null $validationProperty */ private function addGetAdditionalPropertyMethod( Schema $schema, diff --git a/src/SchemaProcessor/PostProcessor/EnumPostProcessor.php b/src/SchemaProcessor/PostProcessor/EnumPostProcessor.php index d96dba0..e3915c8 100644 --- a/src/SchemaProcessor/PostProcessor/EnumPostProcessor.php +++ b/src/SchemaProcessor/PostProcessor/EnumPostProcessor.php @@ -28,16 +28,11 @@ */ class EnumPostProcessor extends PostProcessor { - private $generatedEnums = []; + private array $generatedEnums = []; - /** @var string */ - private $namespace; - /** @var Render */ - private $renderer; - /** @var string */ - private $targetDirectory; - /** @var bool */ - private $skipNonMappedEnums; + private string $namespace; + private Render $renderer; + private string $targetDirectory; /** * @param string $targetDirectory The directory where to put the generated PHP enums @@ -50,7 +45,7 @@ class EnumPostProcessor extends PostProcessor public function __construct( string $targetDirectory, string $namespace, - bool $skipNonMappedEnums = false, + private bool $skipNonMappedEnums = false, ) { if (PHP_VERSION_ID < 80100) { // @codeCoverageIgnoreStart @@ -63,7 +58,6 @@ public function __construct( $this->renderer = new Render(__DIR__ . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR); $this->namespace = trim($namespace, '\\'); $this->targetDirectory = $targetDirectory; - $this->skipNonMappedEnums = $skipNonMappedEnums; } public function process(Schema $schema, GeneratorConfiguration $generatorConfiguration): void @@ -123,9 +117,9 @@ public function process(Schema $schema, GeneratorConfiguration $generatorConfigu } // remove the enum validator as the validation is performed by the PHP enum - $property->filterValidators(static function (Validator $validator): bool { - return !is_a($validator->getValidator(), EnumValidator::class); - }); + $property->filterValidators( + static fn(Validator $validator): bool => !is_a($validator->getValidator(), EnumValidator::class), + ); // if an enum value is provided the transforming filter will add a value pass through. As the filter doesn't // know the exact enum type the pass through allows every UnitEnum instance. Consequently add a validator to @@ -213,7 +207,7 @@ private function validateEnum(PropertyInterface $property): bool || count(array_uintersect( $json['enum-map'], $json['enum'], - function ($a, $b): int { return $a === $b ? 0 : 1; }, + fn($a, $b): int => $a === $b ? 0 : 1, )) !== count($json['enum']) ) { $throw('invalid enum map %s in file %s'); @@ -226,9 +220,7 @@ function ($a, $b): int { return $a === $b ? 0 : 1; }, private function getArrayTypes(array $array): array { return array_unique(array_map( - static function ($item): string { - return gettype($item); - }, + static fn($item): string => gettype($item), $array, )); } diff --git a/src/SchemaProcessor/PostProcessor/Internal/AdditionalPropertiesPostProcessor.php b/src/SchemaProcessor/PostProcessor/Internal/AdditionalPropertiesPostProcessor.php index 3252c02..373a3ad 100644 --- a/src/SchemaProcessor/PostProcessor/Internal/AdditionalPropertiesPostProcessor.php +++ b/src/SchemaProcessor/PostProcessor/Internal/AdditionalPropertiesPostProcessor.php @@ -25,9 +25,6 @@ class AdditionalPropertiesPostProcessor extends PostProcessor { /** - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration - * * @throws SchemaException */ public function process(Schema $schema, GeneratorConfiguration $generatorConfiguration): void @@ -40,8 +37,6 @@ public function process(Schema $schema, GeneratorConfiguration $generatorConfigu } /** - * @param Schema $schema - * * @throws SchemaException */ public function addAdditionalPropertiesCollectionProperty(Schema $schema): void @@ -82,8 +77,6 @@ public function addAdditionalPropertiesCollectionProperty(Schema $schema): void * the internal storage of the additional properties. If no additional property constraints are defined for the * schema the provided additional properties must be updated separately as no AdditionalPropertiesValidator is added * to the generated class. - * - * @param Schema $schema */ private function addUpdateAdditionalProperties(Schema $schema): void { diff --git a/src/SchemaProcessor/PostProcessor/Internal/CompositionValidationPostProcessor.php b/src/SchemaProcessor/PostProcessor/Internal/CompositionValidationPostProcessor.php index 0eb8e6c..b3b6300 100644 --- a/src/SchemaProcessor/PostProcessor/Internal/CompositionValidationPostProcessor.php +++ b/src/SchemaProcessor/PostProcessor/Internal/CompositionValidationPostProcessor.php @@ -28,13 +28,9 @@ */ class CompositionValidationPostProcessor extends PostProcessor { - /** - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration - */ public function process(Schema $schema, GeneratorConfiguration $generatorConfiguration): void { - $validatorPropertyMap = $this->generateValidatorPropertyMap($schema, $generatorConfiguration); + $validatorPropertyMap = $this->generateValidatorPropertyMap($schema); if (empty($validatorPropertyMap)) { return; @@ -53,13 +49,8 @@ public function process(Schema $schema, GeneratorConfiguration $generatorConfigu /** * Set up a map containing the properties and the corresponding composition validators which must be checked when * the property is updated - * - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration - * - * @return array */ - private function generateValidatorPropertyMap(Schema $schema, GeneratorConfiguration $generatorConfiguration): array + private function generateValidatorPropertyMap(Schema $schema): array { $validatorPropertyMap = []; @@ -103,11 +94,6 @@ private function generateValidatorPropertyMap(Schema $schema, GeneratorConfigura return $validatorPropertyMap; } - /** - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration - * @param array $validatorPropertyMap - */ private function addValidationMethods( Schema $schema, GeneratorConfiguration $generatorConfiguration, @@ -139,28 +125,19 @@ private function addValidationMethods( /** * Add internal calls to validation methods to the setters which are part of a composition validation. The * validation methods will validate the state of all compositions when the value is updated. - * - * @param Schema $schema - * @param array $validatorPropertyMap */ private function addValidationCallsToSetterMethods(Schema $schema, array $validatorPropertyMap): void { $schema->addSchemaHook(new class ($validatorPropertyMap) implements SetterBeforeValidationHookInterface { - protected $validatorPropertyMap; - - public function __construct(array $validatorPropertyMap) - { - $this->validatorPropertyMap = $validatorPropertyMap; - } + public function __construct(protected array $validatorPropertyMap) {} public function getCode(PropertyInterface $property, bool $batchUpdate = false): string { return join( "\n", array_map( - static function (int $validatorIndex): string { - return sprintf('$this->validateComposition_%s($modelData);', $validatorIndex); - }, + static fn(int $validatorIndex): string => + sprintf('$this->validateComposition_%s($modelData);', $validatorIndex), array_unique($this->validatorPropertyMap[$property->getName()] ?? []), ) ); diff --git a/src/SchemaProcessor/PostProcessor/Internal/ExtendObjectPropertiesMatchingPatternPropertiesPostProcessor.php b/src/SchemaProcessor/PostProcessor/Internal/ExtendObjectPropertiesMatchingPatternPropertiesPostProcessor.php index a8f1daa..28c70c4 100644 --- a/src/SchemaProcessor/PostProcessor/Internal/ExtendObjectPropertiesMatchingPatternPropertiesPostProcessor.php +++ b/src/SchemaProcessor/PostProcessor/Internal/ExtendObjectPropertiesMatchingPatternPropertiesPostProcessor.php @@ -20,9 +20,6 @@ class ExtendObjectPropertiesMatchingPatternPropertiesPostProcessor extends PostProcessor { /** - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration - * * @throws SchemaException */ public function process(Schema $schema, GeneratorConfiguration $generatorConfiguration): void @@ -31,13 +28,7 @@ public function process(Schema $schema, GeneratorConfiguration $generatorConfigu $schema->addSchemaHook( new class ($schema) implements SetterBeforeValidationHookInterface { - /** @var Schema */ - private $schema; - - public function __construct(Schema $schema) - { - $this->schema = $schema; - } + public function __construct(private Schema $schema) {} public function getCode(PropertyInterface $property, bool $batchUpdate = false): string { @@ -75,9 +66,6 @@ public function getCode(PropertyInterface $property, bool $batchUpdate = false): } /** - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration - * * @throws SchemaException */ protected function transferPatternPropertiesFilterToProperty( @@ -86,9 +74,7 @@ protected function transferPatternPropertiesFilterToProperty( ): void { $patternPropertiesValidators = array_filter( $schema->getBaseValidators(), - static function (PropertyValidatorInterface $validator): bool { - return $validator instanceof PatternPropertiesValidator; - }); + static fn(PropertyValidatorInterface $validator): bool => $validator instanceof PatternPropertiesValidator); if (empty($patternPropertiesValidators)) { return; @@ -98,10 +84,9 @@ static function (PropertyValidatorInterface $validator): bool { $propertyHasTransformingFilter = !empty( array_filter( $property->getValidators(), - static function (Validator $validator): bool { - return $validator->getValidator() instanceof FilterValidator && - $validator->getValidator()->getFilter() instanceof TransformingFilterInterface; - }, + static fn(Validator $validator): bool => + $validator->getValidator() instanceof FilterValidator && + $validator->getValidator()->getFilter() instanceof TransformingFilterInterface, ) ); @@ -110,17 +95,17 @@ static function (Validator $validator): bool { if (!preg_match( '/' . addcslashes($patternPropertiesValidator->getPattern(), '/') . '/', $property->getName(), - ) - || !isset( - $schema->getJsonSchema()->getJson() - ['patternProperties'] - [$patternPropertiesValidator->getPattern()] - ['filter'], - ) - ) { + )) { + continue; + } + if (!isset( + $schema->getJsonSchema()->getJson() + ['patternProperties'] + [$patternPropertiesValidator->getPattern()] + ['filter'], + )) { continue; } - if ($propertyHasTransformingFilter) { foreach ( $patternPropertiesValidator->getValidationProperty()->getValidators() as $validator diff --git a/src/SchemaProcessor/PostProcessor/Internal/PatternPropertiesPostProcessor.php b/src/SchemaProcessor/PostProcessor/Internal/PatternPropertiesPostProcessor.php index c1360bf..51a9fb8 100644 --- a/src/SchemaProcessor/PostProcessor/Internal/PatternPropertiesPostProcessor.php +++ b/src/SchemaProcessor/PostProcessor/Internal/PatternPropertiesPostProcessor.php @@ -23,9 +23,6 @@ class PatternPropertiesPostProcessor extends PostProcessor { /** - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration - * * @throws SchemaException */ public function process(Schema $schema, GeneratorConfiguration $generatorConfiguration): void @@ -77,9 +74,6 @@ static function ( /** * Adds an internal array property to the schema which holds all pattern properties grouped by key * - * @param Schema $schema - * @param array $patternHashes - * * @throws SchemaException */ private function addPatternPropertiesCollectionProperty( @@ -101,8 +95,6 @@ private function addPatternPropertiesCollectionProperty( /** * Adds an internal array property to the schema which holds all pattern properties grouped by key * - * @param Schema $schema - * * @throws SchemaException */ private function addPatternPropertiesMapProperty(Schema $schema): void { @@ -131,19 +123,11 @@ private function addPatternPropertiesMapProperty(Schema $schema): void { * which not only match a pattern but are also properties of the object (eg. the pattern is "^n" and the object * contains a property "name") initialize the corresponding field for each matching property in the array with a * reference to the object attribute representing the property (in the example case reference "$this->name"). - * - * @param Schema $schema - * @param array $patternHashes */ private function initObjectPropertiesMatchingPatternProperties(Schema $schema, array $patternHashes): void { $schema->addSchemaHook(new class ($patternHashes) implements ConstructorBeforeValidationHookInterface { - private $patternHashes; - - public function __construct(array $patternHashes) - { - $this->patternHashes = $patternHashes; - } + public function __construct(private array $patternHashes) {} public function getCode(): string { diff --git a/src/SchemaProcessor/PostProcessor/Internal/SerializationPostProcessor.php b/src/SchemaProcessor/PostProcessor/Internal/SerializationPostProcessor.php index c27cc43..53d588d 100644 --- a/src/SchemaProcessor/PostProcessor/Internal/SerializationPostProcessor.php +++ b/src/SchemaProcessor/PostProcessor/Internal/SerializationPostProcessor.php @@ -31,9 +31,6 @@ class SerializationPostProcessor extends PostProcessor { /** * Add serialization support to the provided schema - * - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration */ public function process(Schema $schema, GeneratorConfiguration $generatorConfiguration): void { @@ -57,9 +54,6 @@ public function process(Schema $schema, GeneratorConfiguration $generatorConfigu /** * Each transforming filter must provide a method to serialize the value. Add a method to the schema to call the * serialization for each property with a transforming filter - * - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration */ private function addSerializeFunctionsForTransformingFilters( Schema $schema, @@ -128,10 +122,6 @@ private function addSerializeFunctionsForTransformingFilters( } } - /** - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration - */ private function addSerializationHookMethod(Schema $schema, GeneratorConfiguration $generatorConfiguration): void { $schema->addMethod( @@ -149,9 +139,6 @@ private function addSerializationHookMethod(Schema $schema, GeneratorConfigurati /** * Adds code to merge serialized pattern properties into the serialization result - * - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration */ private function addPatternPropertiesSerialization( Schema $schema, @@ -179,9 +166,6 @@ public function getCode(): string /** * Adds a custom serialization function to the schema to merge all additional properties into the serialization * result on serializations - * - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration */ public function addAdditionalPropertiesSerialization( Schema $schema, @@ -244,14 +228,11 @@ private function addSkipNotProvidedPropertiesMap( } $skipNotProvidedValues = array_map( - static function (PropertyInterface $property): string { - return $property->getAttribute(true); - }, + static fn(PropertyInterface $property): string => $property->getAttribute(true), array_filter( $schema->getProperties(), - static function (PropertyInterface $property): bool { - return !$property->isRequired() && !$property->getDefaultValue(); - }, + static fn(PropertyInterface $property): bool => + !$property->isRequired() && !$property->getDefaultValue(), ) ); diff --git a/src/SchemaProcessor/PostProcessor/PatternPropertiesAccessorPostProcessor.php b/src/SchemaProcessor/PostProcessor/PatternPropertiesAccessorPostProcessor.php index 15f477b..40e11ca 100644 --- a/src/SchemaProcessor/PostProcessor/PatternPropertiesAccessorPostProcessor.php +++ b/src/SchemaProcessor/PostProcessor/PatternPropertiesAccessorPostProcessor.php @@ -21,9 +21,6 @@ class PatternPropertiesAccessorPostProcessor extends PostProcessor /** * Add methods to handle pattern properties * - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration - * * @throws SchemaException */ public function process(Schema $schema, GeneratorConfiguration $generatorConfiguration): void @@ -48,8 +45,6 @@ public function process(Schema $schema, GeneratorConfiguration $generatorConfigu /** * Adds a method to get a list of pattern properties by property key or pattern * - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration * @param PropertyType[] $patternTypes */ private function addGetPatternPropertiesMethod( @@ -74,25 +69,19 @@ private function addGetPatternPropertiesMethod( /** * @param PropertyType[] $patternTypes - * - * @return string */ private function getReturnTypeAnnotationForGetPatternProperties(array $patternTypes): string { $baseTypes = array_unique( array_map( - static function (PropertyType $type): string { - return $type->getName(); - }, + static fn(PropertyType $type): string => $type->getName(), $patternTypes, ) ); $nullable = array_reduce( $patternTypes, - static function (bool $carry, PropertyType $type): bool { - return $carry || $type->isNullable(); - }, + static fn(bool $carry, PropertyType $type): bool => $carry || $type->isNullable(), false, ); diff --git a/src/SchemaProcessor/PostProcessor/PostProcessor.php b/src/SchemaProcessor/PostProcessor/PostProcessor.php index 37baeae..e196423 100644 --- a/src/SchemaProcessor/PostProcessor/PostProcessor.php +++ b/src/SchemaProcessor/PostProcessor/PostProcessor.php @@ -11,9 +11,6 @@ abstract class PostProcessor { /** * Have fun doin' crazy stuff with the schema - * - * @param Schema $schema - * @param GeneratorConfiguration $generatorConfiguration */ abstract public function process(Schema $schema, GeneratorConfiguration $generatorConfiguration): void; diff --git a/src/SchemaProcessor/PostProcessor/RenderedMethod.php b/src/SchemaProcessor/PostProcessor/RenderedMethod.php index f37d8ea..da9e0a4 100644 --- a/src/SchemaProcessor/PostProcessor/RenderedMethod.php +++ b/src/SchemaProcessor/PostProcessor/RenderedMethod.php @@ -20,29 +20,14 @@ */ class RenderedMethod implements MethodInterface { - /** @var Render */ - static private $renderer; - - /** @var Schema */ - private $schema; - /** @var GeneratorConfiguration */ - private $generatorConfiguration; - /** @var string */ - private $template; - /** @var array */ - private $templateValues; + static private ?Render $renderer = null; public function __construct( - Schema $schema, - GeneratorConfiguration $generatorConfiguration, - string $template, - array $templateValues = [], - ) { - $this->schema = $schema; - $this->generatorConfiguration = $generatorConfiguration; - $this->template = $template; - $this->templateValues = $templateValues; - } + private Schema $schema, + private GeneratorConfiguration $generatorConfiguration, + private string $template, + private array $templateValues = [], + ) {} /** * @inheritDoc @@ -67,9 +52,6 @@ public function getCode(): string ); } - /** - * @return Render - */ protected function getRenderer(): Render { if (!self::$renderer) { diff --git a/src/SchemaProcessor/RenderQueue.php b/src/SchemaProcessor/RenderQueue.php index a619c2c..eea83be 100644 --- a/src/SchemaProcessor/RenderQueue.php +++ b/src/SchemaProcessor/RenderQueue.php @@ -21,8 +21,6 @@ class RenderQueue protected $jobs = []; /** - * @param RenderJob $renderJob - * * @return $this */ public function addRenderJob(RenderJob $renderJob): self @@ -35,7 +33,6 @@ public function addRenderJob(RenderJob $renderJob): self /** * Render all collected jobs of the RenderQueue and clear the queue * - * @param GeneratorConfiguration $generatorConfiguration * @param PostProcessor[] $postProcessors * * @throws FileSystemException diff --git a/src/SchemaProcessor/SchemaProcessor.php b/src/SchemaProcessor/SchemaProcessor.php index 4d94b0b..7e21556 100644 --- a/src/SchemaProcessor/SchemaProcessor.php +++ b/src/SchemaProcessor/SchemaProcessor.php @@ -28,15 +28,6 @@ */ class SchemaProcessor { - /** @var GeneratorConfiguration */ - protected $generatorConfiguration; - /** @var RenderQueue */ - protected $renderQueue; - /** @var string */ - protected $baseSource; - /** @var string */ - protected $destination; - /** @var string */ protected $currentClassPath; /** @var string */ @@ -51,29 +42,17 @@ class SchemaProcessor /** * SchemaProcessor constructor. - * - * @param string $baseSource - * @param string $destination - * @param GeneratorConfiguration $generatorConfiguration - * @param RenderQueue $renderQueue */ public function __construct( - string $baseSource, - string $destination, - GeneratorConfiguration $generatorConfiguration, - RenderQueue $renderQueue, - ) { - $this->baseSource = $baseSource; - $this->destination = $destination; - $this->generatorConfiguration = $generatorConfiguration; - $this->renderQueue = $renderQueue; - } + protected string $baseSource, + protected string $destination, + protected GeneratorConfiguration $generatorConfiguration, + protected RenderQueue $renderQueue, + ) {} /** * Process a given json schema file * - * @param JsonSchema $jsonSchema - * * @throws SchemaException */ public function process(JsonSchema $jsonSchema): void @@ -97,16 +76,11 @@ public function process(JsonSchema $jsonSchema): void /** * Process a JSON schema stored as an associative array * - * @param JsonSchema $jsonSchema - * @param string $classPath - * @param string $className * @param SchemaDefinitionDictionary $dictionary If a nested object of a schema is processed import the * definitions of the parent schema to make them available for the * nested schema as well * @param bool $initialClass Is it an initial class or a nested class? * - * @return Schema|null - * * @throws SchemaException */ public function processSchema( @@ -129,14 +103,6 @@ public function processSchema( /** * Generate a model and store the model to the file system * - * @param string $classPath - * @param string $className - * @param JsonSchema $jsonSchema - * @param SchemaDefinitionDictionary $dictionary - * @param bool $initialClass - * - * @return Schema - * * @throws SchemaException */ protected function generateModel( @@ -178,10 +144,6 @@ protected function generateModel( /** * Attach a new class file render job to the render proxy - * - * @param string $classPath - * @param string $className - * @param Schema $schema */ public function generateClassFile( string $classPath, @@ -209,12 +171,7 @@ public function generateClassFile( /** * Gather all nested object properties and merge them together into a single merged property * - * @param Schema $schema - * @param PropertyInterface $property * @param CompositionPropertyDecorator[] $compositionProperties - * @param JsonSchema $propertySchema - * - * @return PropertyInterface|null * * @throws SchemaException */ @@ -313,8 +270,6 @@ private function redirectMergedProperty(array $compositionProperties) } /** - * @param Schema $schema - * @param Schema $mergedPropertySchema * @param PropertyInterface[] $compositionProperties */ private function transferPropertiesToMergedSchema( @@ -333,9 +288,7 @@ function () use ($property, $schema, $mergedPropertySchema): void { $mergedPropertySchema->addProperty( // don't validate fields in merged properties. All fields were validated before // corresponding to the defined constraints of the composition property. - (clone $nestedProperty)->filterValidators(static function (): bool { - return false; - }), + (clone $nestedProperty)->filterValidators(static fn(): bool => false), ); } }, @@ -345,49 +298,33 @@ function () use ($property, $schema, $mergedPropertySchema): void { /** * Get the class path out of the file path of a schema file - * - * @param string $jsonSchemaFile */ protected function setCurrentClassPath(string $jsonSchemaFile): void { $path = str_replace($this->baseSource, '', dirname($jsonSchemaFile)); $pieces = array_map( - static function (string $directory): string { - return ucfirst($directory); - }, + static fn(string $directory): string => ucfirst($directory), explode(DIRECTORY_SEPARATOR, $path), ); $this->currentClassPath = join('\\', array_filter($pieces)); } - /** - * @return string - */ public function getCurrentClassPath(): string { return $this->currentClassPath; } - /** - * @return string - */ public function getCurrentClassName(): string { return $this->currentClassName; } - /** - * @return array - */ public function getGeneratedFiles(): array { return $this->generatedFiles; } - /** - * @return GeneratorConfiguration - */ public function getGeneratorConfiguration(): GeneratorConfiguration { return $this->generatorConfiguration; diff --git a/src/SchemaProvider/OpenAPIv3Provider.php b/src/SchemaProvider/OpenAPIv3Provider.php index 59e2c2f..486d889 100644 --- a/src/SchemaProvider/OpenAPIv3Provider.php +++ b/src/SchemaProvider/OpenAPIv3Provider.php @@ -16,29 +16,26 @@ class OpenAPIv3Provider implements SchemaProviderInterface { /** @var array */ private $openAPIv3Spec; - /** @var string */ - private $sourceFile; /** * OpenAPIv3Provider constructor. * - * @param string $sourceFile - * * @throws SchemaException */ - public function __construct(string $sourceFile) + public function __construct(private string $sourceFile) { - $this->sourceFile = $sourceFile; - $jsonSchema = file_get_contents($sourceFile); + $jsonSchema = file_get_contents($this->sourceFile); if (!$jsonSchema || !($this->openAPIv3Spec = json_decode($jsonSchema, true))) { - throw new SchemaException("Invalid JSON-Schema file $sourceFile"); + throw new SchemaException("Invalid JSON-Schema file {$this->sourceFile}"); } if (!isset($this->openAPIv3Spec['components']['schemas']) || empty($this->openAPIv3Spec['components']['schemas']) ) { - throw new SchemaException("Open API v3 spec file $sourceFile doesn't contain any schemas to process"); + throw new SchemaException( + "Open API v3 spec file {$this->sourceFile} doesn't contain any schemas to process" + ); } } diff --git a/src/SchemaProvider/RecursiveDirectoryProvider.php b/src/SchemaProvider/RecursiveDirectoryProvider.php index 460dfd3..5b98989 100644 --- a/src/SchemaProvider/RecursiveDirectoryProvider.php +++ b/src/SchemaProvider/RecursiveDirectoryProvider.php @@ -18,14 +18,11 @@ */ class RecursiveDirectoryProvider implements SchemaProviderInterface { - /** @var string */ - private $sourceDirectory; + private string $sourceDirectory; /** * RecursiveDirectoryProvider constructor. * - * @param string $sourceDirectory - * * @throws FileSystemException */ public function __construct(string $sourceDirectory) diff --git a/src/SchemaProvider/SchemaProviderInterface.php b/src/SchemaProvider/SchemaProviderInterface.php index 01b04f0..c342a91 100644 --- a/src/SchemaProvider/SchemaProviderInterface.php +++ b/src/SchemaProvider/SchemaProviderInterface.php @@ -23,8 +23,6 @@ public function getSchemas(): iterable; /** * Get the base directory of the provider - * - * @return string */ public function getBaseDirectory(): string; } diff --git a/src/Utils/ClassNameGeneratorInterface.php b/src/Utils/ClassNameGeneratorInterface.php index 7cda15f..eb39cab 100644 --- a/src/Utils/ClassNameGeneratorInterface.php +++ b/src/Utils/ClassNameGeneratorInterface.php @@ -21,8 +21,6 @@ interface ClassNameGeneratorInterface * @param JsonSchema $schema The structure of the schema which is represented by the generated class * @param bool $isMergeClass Is it a merge class? example: allOf schema composition * @param string $currentClassName The class name of the parent class if the class represents a nested object - * - * @return string */ public function getClassName( string $propertyName, diff --git a/src/Utils/NormalizedName.php b/src/Utils/NormalizedName.php index c4325b4..f17b523 100644 --- a/src/Utils/NormalizedName.php +++ b/src/Utils/NormalizedName.php @@ -13,16 +13,12 @@ public static function from(string $name, JsonSchema $jsonSchema): string { $attributeName = preg_replace_callback( '/([a-z][a-z0-9]*)([A-Z])/', - static function (array $matches): string { - return "{$matches[1]}-{$matches[2]}"; - }, + static fn(array $matches): string => "{$matches[1]}-{$matches[2]}", $name, ); $elements = array_map( - static function (string $element): string { - return ucfirst(strtolower($element)); - }, + static fn(string $element): string => ucfirst(strtolower($element)), preg_split('/[^a-z0-9]/i', $attributeName), ); diff --git a/src/Utils/RenderHelper.php b/src/Utils/RenderHelper.php index c69daaa..61a91f0 100644 --- a/src/Utils/RenderHelper.php +++ b/src/Utils/RenderHelper.php @@ -18,44 +18,18 @@ */ class RenderHelper { - /** @var GeneratorConfiguration */ - protected $generatorConfiguration; + public function __construct(protected GeneratorConfiguration $generatorConfiguration) {} - /** - * RenderHelper constructor. - * - * @param GeneratorConfiguration $generatorConfiguration - */ - public function __construct(GeneratorConfiguration $generatorConfiguration) - { - $this->generatorConfiguration = $generatorConfiguration; - } - - /** - * @param string $value - * - * @return string - */ public function ucfirst(string $value): string { return ucfirst($value); } - /** - * @param mixed $value - * - * @return bool - */ - public function isNull($value): bool + public function isNull(mixed $value): bool { return $value === null; } - /** - * @param string $fqcn - * - * @return string - */ public function getSimpleClassName(string $fqcn): string { $parts = explode('\\', $fqcn); @@ -63,11 +37,6 @@ public function getSimpleClassName(string $fqcn): string return end($parts); } - /** - * @param array $fqcns - * - * @return string - */ public function joinClassNames(array $fqcns): string { return join(', ', array_map([$this, 'getSimpleClassName'], $fqcns)); @@ -75,11 +44,6 @@ public function joinClassNames(array $fqcns): string /** * Resolve all associated decorators of a property - * - * @param PropertyInterface $property - * @param bool $nestedProperty - * - * @return string */ public function resolvePropertyDecorator(PropertyInterface $property, bool $nestedProperty = false): string { @@ -92,10 +56,6 @@ public function resolvePropertyDecorator(PropertyInterface $property, bool $nest /** * Generate code to handle a validation error - * - * @param PropertyValidatorInterface $validator - * - * @return string */ public function validationError(PropertyValidatorInterface $validator): string { @@ -120,11 +80,6 @@ public function validationError(PropertyValidatorInterface $validator): string * if implicitNull is enabled null may be set for the property * - except the property contains a default value and implicit null is disabled. in this case null is not * possible - * - * @param PropertyInterface $property - * @param bool $outputType - * - * @return bool */ public function isPropertyNullable(PropertyInterface $property, bool $outputType = false): bool { diff --git a/tests/AbstractPHPModelGeneratorTestCase.php b/tests/AbstractPHPModelGeneratorTestCase.php index 970b940..78d4ada 100644 --- a/tests/AbstractPHPModelGeneratorTestCase.php +++ b/tests/AbstractPHPModelGeneratorTestCase.php @@ -33,11 +33,11 @@ abstract class AbstractPHPModelGeneratorTestCase extends TestCase { protected const EXTERNAL_JSON_DIRECTORIES = []; - protected $modifyModelGenerator = null; + protected $modifyModelGenerator; - private $names = []; + private array $names = []; - private $generatedFiles = []; + private array $generatedFiles = []; /** * Set up an empty directory for the tests @@ -55,10 +55,6 @@ public function setUp(): void * * TODO: remove and switch all calls to assertMatchesRegularExpression when dropping support for PHPUnit < 9.1 * TODO: (dropping support for PHP < 7.4) - * - * @param string $pattern - * @param string $string - * @param string $message */ public static function assertRegExp(string $pattern, string $string, string $message = ''): void { @@ -124,14 +120,6 @@ private function copyExternalJSON(): void /** * Generate a class from a given JSON schema file and return the FQCN * - * @param string $file - * @param GeneratorConfiguration|null $generatorConfiguration - * @param bool $originalClassNames - * @param bool $implicitNull - * @param string $schemaProviderClass - * - * @return string - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -155,14 +143,7 @@ protected function generateClassFromFile( /** * Generate a class from a file template and apply all $values via sprintf to the template * - * @param string $file * @param string[] $values - * @param GeneratorConfiguration|null $generatorConfiguration - * @param bool $escape - * @param bool $implicitNull - * @param string $schemaProviderClass - * - * @return string * * @throws FileSystemException * @throws RenderException @@ -180,9 +161,8 @@ protected function generateClassFromFileTemplate( sprintf( file_get_contents($this->getSchemaFilePath($file)), ...array_map( - static function (string $item) use ($escape): string { - return $escape ? str_replace("'", '"', addcslashes($item, '"\\')) : $item; - }, + static fn(string $item): string => + $escape ? str_replace("'", '"', addcslashes($item, '"\\')) : $item, $values, ) ), @@ -196,14 +176,6 @@ static function (string $item) use ($escape): string { /** * Generate a class from a given JSON schema string and return the FQCN * - * @param string $jsonSchema - * @param GeneratorConfiguration|null $generatorConfiguration - * @param bool $originalClassNames - * @param bool $implicitNull - * @param string $schemaProviderClass - * - * @return string - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -298,10 +270,6 @@ public function getClassName( /** * Generate objects for all JSON-Schema files in the given directory * - * @param string $directory - * @param GeneratorConfiguration $configuration - * @return array - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -324,11 +292,6 @@ protected function generateDirectory(string $directory, GeneratorConfiguration $ /** * Combine two data providers - * - * @param array $dataProvider1 - * @param array $dataProvider2 - * - * @return array */ protected function combineDataProvider(array $dataProvider1, array $dataProvider2): array { @@ -344,11 +307,8 @@ protected function combineDataProvider(array $dataProvider1, array $dataProvider /** * Expect a validation error based on the given configuration - * - * @param GeneratorConfiguration $configuration - * @param array|string $messages */ - protected function expectValidationError(GeneratorConfiguration $configuration, $messages): void + protected function expectValidationError(GeneratorConfiguration $configuration, array | string $messages): void { if (!is_array($messages)) { $messages = [$messages]; @@ -365,12 +325,11 @@ protected function expectValidationError(GeneratorConfiguration $configuration, /** * Expect a validation error based on the given configuration matching the given message(s) - * - * @param GeneratorConfiguration $configuration - * @param array|string $messages */ - protected function expectValidationErrorRegExp(GeneratorConfiguration $configuration, $messages): void - { + protected function expectValidationErrorRegExp( + GeneratorConfiguration $configuration, + array | string $messages, + ): void { if (!is_array($messages)) { $messages = [$messages]; } @@ -386,10 +345,6 @@ protected function expectValidationErrorRegExp(GeneratorConfiguration $configura /** * Set up an ErrorRegistryException containing the given messages - * - * @param array $messages - * - * @return ErrorRegistryException */ protected function getErrorRegistryException(array $messages): ErrorRegistryException { @@ -405,11 +360,6 @@ protected function getErrorRegistryException(array $messages): ErrorRegistryExce /** * Check if the given error registry exception contains the requested exception. * - * @param ErrorRegistryException $registryException - * @param string $expectedException - * - * @return ValidationException - * * @throws AssertionFailedError */ protected function assertErrorRegistryContainsException( @@ -451,13 +401,8 @@ public function namespaceDataProvider(): array /** * Get the annotated type for an object property - * - * @param string|object $object - * @param string $property - * - * @return string */ - protected function getPropertyTypeAnnotation($object, string $property): string + protected function getPropertyTypeAnnotation(string | object $object, string $property): string { $matches = []; preg_match( @@ -471,13 +416,8 @@ protected function getPropertyTypeAnnotation($object, string $property): string /** * Get the annotated return type for an object method - * - * @param string|object $object - * @param string $method - * - * @return string */ - protected function getReturnTypeAnnotation($object, string $method): string + protected function getReturnTypeAnnotation(string | object $object, string $method): string { $matches = []; preg_match( @@ -491,14 +431,8 @@ protected function getReturnTypeAnnotation($object, string $method): string /** * Get the annotated parameter type for an object method - * - * @param string|object $object - * @param string $method - * @param int $parameter - * - * @return string */ - protected function getParameterTypeAnnotation($object, string $method, int $parameter = 0): string + protected function getParameterTypeAnnotation(string | object $object, string $method, int $parameter = 0): string { $matches = []; preg_match_all( @@ -532,8 +466,6 @@ protected function getSchemaFilePath(string $file): string /** * Generate a unique name for a class - * - * @return string */ private function getClassName(): string { diff --git a/tests/Basic/AdditionalPropertiesTest.php b/tests/Basic/AdditionalPropertiesTest.php index 6bbfc96..e8422fc 100644 --- a/tests/Basic/AdditionalPropertiesTest.php +++ b/tests/Basic/AdditionalPropertiesTest.php @@ -18,8 +18,6 @@ class AdditionalPropertiesTest extends AbstractPHPModelGeneratorTestCase { /** * @dataProvider additionalPropertiesDataProvider - * - * @param array $propertyValue */ public function testAdditionalPropertiesAreIgnoredByDefault(array $propertyValue): void { @@ -32,8 +30,6 @@ public function testAdditionalPropertiesAreIgnoredByDefault(array $propertyValue /** * @dataProvider additionalPropertiesDataProvider - * - * @param array $propertyValue */ public function testAdditionalPropertiesAreIgnoredWhenSetToTrue(array $propertyValue): void { @@ -60,8 +56,6 @@ public function additionalPropertiesDataProvider():array /** * @dataProvider definedPropertiesDataProvider - * - * @param array $propertyValue */ public function testDefinedPropertiesAreAcceptedWhenSetToFalse(array $propertyValue): void { @@ -83,8 +77,6 @@ public function definedPropertiesDataProvider():array /** * @dataProvider additionalPropertiesDataProvider - * - * @param array $propertyValue */ public function testAdditionalPropertiesThrowAnExceptionWhenSetToFalse(array $propertyValue): void { @@ -100,8 +92,6 @@ public function testAdditionalPropertiesThrowAnExceptionWhenSetToFalse(array $pr /** * @dataProvider additionalPropertiesDataProvider - * - * @param array $propertyValue */ public function testAdditionalPropertiesThrowAnExceptionWhenNotDefinedAndDeniedByGeneratorConfiguration( array $propertyValue, @@ -121,9 +111,6 @@ public function testAdditionalPropertiesThrowAnExceptionWhenNotDefinedAndDeniedB /** * @dataProvider validTypedAdditionalPropertiesDataProvider - * - * @param GeneratorConfiguration $generatorConfiguration - * @param array $propertyValue */ public function testValidTypedAdditionalPropertiesAreValid( GeneratorConfiguration $generatorConfiguration, @@ -154,10 +141,6 @@ public function validTypedAdditionalPropertiesDataProvider(): array /** * @dataProvider invalidTypedAdditionalPropertiesDataProvider - * - * @param GeneratorConfiguration $generatorConfiguration - * @param array $propertyValue - * @param string $errorMessage */ public function testInvalidTypedAdditionalPropertiesThrowsAnException( GeneratorConfiguration $generatorConfiguration, @@ -223,9 +206,6 @@ public function invalidTypedAdditionalPropertiesDataProvider(): array /** * @dataProvider validAdditionalPropertiesObjectsDataProvider - * - * @param GeneratorConfiguration $generatorConfiguration - * @param array $propertyValue */ public function testValidAdditionalPropertiesObjectsAreValid( GeneratorConfiguration $generatorConfiguration, @@ -263,10 +243,6 @@ public function validAdditionalPropertiesObjectsDataProvider(): array /** * @dataProvider invalidAdditionalPropertiesObjectsDataProvider - * - * @param GeneratorConfiguration $generatorConfiguration - * @param array $propertyValue - * @param string $errorMessage */ public function testInvalidAdditionalPropertiesObjectsThrowsAnException( GeneratorConfiguration $generatorConfiguration, diff --git a/tests/Basic/BasicSchemaGenerationTest.php b/tests/Basic/BasicSchemaGenerationTest.php index 21ff215..3891e95 100644 --- a/tests/Basic/BasicSchemaGenerationTest.php +++ b/tests/Basic/BasicSchemaGenerationTest.php @@ -28,7 +28,6 @@ class BasicSchemaGenerationTest extends AbstractPHPModelGeneratorTestCase /** * @dataProvider implicitNullDataProvider * - * @param bool $implicitNull * @param bool $nullable */ public function testGetterAndSetterAreGeneratedForMutableObjects(bool $implicitNull): void @@ -166,8 +165,8 @@ public function testSerializationFunctionsAreNotGeneratedByDefault(): void $this->assertFalse(is_callable([$object, 'toArray'])); $this->assertFalse(is_callable([$object, 'toJSON'])); - $this->assertFalse($object instanceof SerializationInterface); - $this->assertTrue($object instanceof JSONModelInterface); + $this->assertNotInstanceOf(SerializationInterface::class, $object); + $this->assertInstanceOf(JSONModelInterface::class, $object); } public function testSerializationFunctionsAreGeneratedWithEnabledSerialization(): void @@ -179,13 +178,13 @@ public function testSerializationFunctionsAreGeneratedWithEnabledSerialization() $object = new $className(['property' => 'Hello']); - $this->assertEquals(['property' => 'Hello'], $object->toArray()); - $this->assertEquals(['property' => 'Hello'], $object->jsonSerialize()); - $this->assertEquals('{"property":"Hello"}', $object->toJSON()); + $this->assertSame(['property' => 'Hello'], $object->toArray()); + $this->assertSame(['property' => 'Hello'], $object->jsonSerialize()); + $this->assertSame('{"property":"Hello"}', $object->toJSON()); - $this->assertTrue($object instanceof SerializationInterface); - $this->assertTrue($object instanceof JSONModelInterface); - $this->assertTrue($object instanceof JsonSerializable); + $this->assertInstanceOf(SerializationInterface::class, $object); + $this->assertInstanceOf(JSONModelInterface::class, $object); + $this->assertInstanceOf(JsonSerializable::class, $object); } public function testNestedSerializationFunctions(): void @@ -207,13 +206,13 @@ public function testNestedSerializationFunctions(): void $this->assertEquals($input, $object->toArray()); $this->assertEquals($input, $object->jsonSerialize()); - $this->assertEquals('{"name":"Hannes","address":{"street":"Test-Street","number":null}}', $object->toJSON()); + $this->assertSame('{"name":"Hannes","address":{"street":"Test-Street","number":null}}', $object->toJSON()); $this->assertEquals(['name' => 'Hannes', 'address' => null], $object->toArray([], 1)); - $this->assertEquals('{"name":"Hannes","address":null}', $object->toJSON([], 0, 1)); + $this->assertSame('{"name":"Hannes","address":null}', $object->toJSON([], 0, 1)); - $this->assertEquals(['name' => 'Hannes'], $object->toArray(['address'])); - $this->assertEquals('{"name":"Hannes"}', $object->toJSON(['address'])); + $this->assertSame(['name' => 'Hannes'], $object->toArray(['address'])); + $this->assertSame('{"name":"Hannes"}', $object->toJSON(['address'])); $this->assertFalse($object->toArray([], 0)); $this->assertFalse($object->toJSON([], 0, 0)); @@ -221,16 +220,12 @@ public function testNestedSerializationFunctions(): void /** * @dataProvider invalidStringPropertyValueProvider - * - * @param GeneratorConfiguration $configuration - * @param string $propertyValue - * @param array $exceptionMessage */ public function testInvalidSetterThrowsAnException( GeneratorConfiguration $configuration, string $propertyValue, array $exceptionMessage, - ) { + ): void { $this->expectValidationError($configuration, $exceptionMessage); $className = $this->generateClassFromFile('BasicSchema.json', $configuration->setImmutable(false)); diff --git a/tests/Basic/DefaultValueTest.php b/tests/Basic/DefaultValueTest.php index 7f2397c..a2bd536 100644 --- a/tests/Basic/DefaultValueTest.php +++ b/tests/Basic/DefaultValueTest.php @@ -20,15 +20,11 @@ class DefaultValueTest extends AbstractPHPModelGeneratorTestCase /** * @dataProvider defaultValueForTypedPropertyDataProvider * - * @param string $valueType - * @param mixed $defaultValue - * @param mixed $compareValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ - public function testDefaultValueForTypedProperty(string $valueType, $defaultValue, $compareValue): void + public function testDefaultValueForTypedProperty(string $valueType, mixed $defaultValue, mixed $compareValue): void { $className = $this->generateClassFromFileTemplate( 'DefaultValueTypedProperty.json', @@ -122,15 +118,14 @@ public function defaultValueForTypedPropertyDataProvider(): array /** * @dataProvider invalidDefaultValueForTypedPropertyDataProvider * - * @param string $valueType - * @param mixed $defaultValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ - public function testInvalidDefaultValueForTypedPropertyThrowsAnException(string $valueType, $defaultValue): void - { + public function testInvalidDefaultValueForTypedPropertyThrowsAnException( + string $valueType, + mixed $defaultValue, + ): void { $this->expectException(SchemaException::class); $this->expectExceptionMessage('Invalid type for default value of property property'); @@ -174,14 +169,12 @@ public function invalidDefaultValueForTypedPropertyDataProvider(): array /** * @dataProvider defaultValueForUntypedPropertyDataProvider * - * @param mixed $defaultValue - * @param mixed $compareValue * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ - public function testDefaultValueForUntypedTypedProperty($defaultValue, $compareValue): void + public function testDefaultValueForUntypedTypedProperty(mixed $defaultValue, mixed $compareValue): void { $className = $this->generateClassFromFileTemplate( 'DefaultValueUntypedProperty.json', diff --git a/tests/Basic/ErrorCollectionTest.php b/tests/Basic/ErrorCollectionTest.php index bab580a..d6db26a 100644 --- a/tests/Basic/ErrorCollectionTest.php +++ b/tests/Basic/ErrorCollectionTest.php @@ -21,8 +21,6 @@ class ErrorCollectionTest extends AbstractPHPModelGeneratorTestCase { /** * @dataProvider validValuesForSinglePropertyDataProvider - * - * @param string $value */ public function testValidValuesForMultipleChecksForSingleProperty(string $value): void { @@ -43,12 +41,9 @@ public function validValuesForSinglePropertyDataProvider(): array /** * @dataProvider invalidValuesForSinglePropertyDataProvider - * - * @param string $value - * @param array $messages */ public function testInvalidValuesForMultipleChecksForSinglePropertyThrowsAnException( - $value, + mixed $value, array $messages, ): void { try { @@ -57,7 +52,7 @@ public function testInvalidValuesForMultipleChecksForSinglePropertyThrowsAnExcep new $className(['property' => $value]); } catch (ErrorRegistryException $e) { $this->assertStringContainsString(join("\n", $messages), $e->getMessage()); - $this->assertSame(count($messages), count($e->getErrors())); + $this->assertCount(count($messages), $e->getErrors()); foreach ($messages as $expectedExceptionClass => $message) { $error = $this->assertErrorRegistryContainsException($e, $expectedExceptionClass); @@ -103,8 +98,10 @@ public function invalidValuesForSinglePropertyDataProvider(): array /** * @dataProvider invalidValuesForCompositionDataProvider */ - public function testInvalidValuesForMultipleValuesInCompositionThrowsAnException($value, string $message): void - { + public function testInvalidValuesForMultipleValuesInCompositionThrowsAnException( + int|string $value, + string $message, + ): void { $this->expectException(ErrorRegistryException::class); $this->expectExceptionMessageMatches("/$message/"); diff --git a/tests/Basic/ExplicitNullTest.php b/tests/Basic/ExplicitNullTest.php index bab2423..4c5d718 100644 --- a/tests/Basic/ExplicitNullTest.php +++ b/tests/Basic/ExplicitNullTest.php @@ -53,8 +53,6 @@ public function testNullForRequiredValueWithImplicitNullThrowsAnException(): voi /** * @dataProvider implicitNullDataProvider - * - * @param bool $implicitNull */ public function testNullForOptionalValueWithExplicitNullIsValid(bool $implicitNull): void { @@ -67,8 +65,6 @@ public function testNullForOptionalValueWithExplicitNullIsValid(bool $implicitNu /** * @dataProvider implicitNullDataProvider - * - * @param bool $implicitNull */ public function testNullForRequiredValueWithExplicitNullIsValid(bool $implicitNull): void { diff --git a/tests/Basic/FilterTest.php b/tests/Basic/FilterTest.php index e0b2dc5..28833aa 100644 --- a/tests/Basic/FilterTest.php +++ b/tests/Basic/FilterTest.php @@ -38,8 +38,6 @@ public function testGetFilterReturnsNullForNonExistingFilter(): void /** * @dataProvider invalidCustomFilterDataProvider - * - * @param array $customInvalidFilter */ public function testAddInvalidFilterThrowsAnException(array $customInvalidFilter): void { @@ -86,16 +84,11 @@ protected function getCustomFilter( array $acceptedTypes = ['string', 'null'], ): FilterInterface { return new class ($customFilter, $token, $acceptedTypes) implements FilterInterface { - private $customFilter; - private $token; - private $acceptedTypes; - - public function __construct(array $customFilter, string $token, array $acceptedTypes) - { - $this->customFilter = $customFilter; - $this->token = $token; - $this->acceptedTypes = $acceptedTypes; - } + public function __construct( + private array $customFilter, + private string $token, + private array $acceptedTypes, + ) {} public function getAcceptedTypes(): array { @@ -116,10 +109,6 @@ public function getFilter(): array /** * @dataProvider validBuiltInFilterDataProvider - * - * @param string $template - * @param array $input - * @param string|null $expected */ public function testValidUsageOfBuiltInFilter(string $template, array $input, ?string $expected): void { @@ -134,8 +123,6 @@ public function testValidUsageOfBuiltInFilter(string $template, array $input, ?s /** * @dataProvider validTrimDataFormatProvider - * - * @param string $template */ public function testNotProvidedOptionalValueWithFilterIsValid(string $template): void { @@ -171,10 +158,6 @@ public function validBuiltInFilterDataProvider(): array /** * @dataProvider invalidUsageOfBuiltInFilterDataProvider - * - * @param string $template - * @param string $jsonType - * @param string $phpType */ public function testInvalidUsageOfBuiltInFilterThrowsAnException( string $template, @@ -205,9 +188,6 @@ public function invalidUsageOfBuiltInFilterDataProvider(): array /** * @dataProvider validLengthAfterFilterDataProvider - * - * @param string|null $input - * @param string|null $expectedValue */ public function testLengthValidationForFilteredValueForValidValues(?string $input, ?string $expectedValue): void { @@ -227,8 +207,6 @@ public function validLengthAfterFilterDataProvider(): array /** * @dataProvider invalidLengthAfterFilterDataProvider - * - * @param string $input */ public function testLengthValidationForFilteredValueForInvalidValuesThrowsAnException(string $input): void { @@ -256,9 +234,6 @@ public static function uppercaseFilter(?string $value): ?string /** * @dataProvider customFilterDataProvider - * - * @param string|null $input - * @param string|null $expectedValue */ public function testCustomFilter(?string $input, ?string $expectedValue): void { @@ -348,7 +323,7 @@ public function validEncodingsDataProvider(): array ]; } - private function getEncodeFilter() + private function getEncodeFilter(): FilterInterface { return new class () implements FilterInterface, ValidateOptionsInterface { public function getAcceptedTypes(): array @@ -386,9 +361,6 @@ public static function encode(string $value, array $options): string /** * @dataProvider multipleFilterDataProvider - * - * @param string|null $input - * @param string|null $expectedValue */ public function testMultipleFilters(?string $input, ?string $expectedValue): void { @@ -420,8 +392,6 @@ public function multipleFilterDataProvider(): array /** * @dataProvider invalidCustomFilterDataProvider - * - * @param array $customInvalidFilter */ public function testAddFilterWithInvalidSerializerThrowsAnException(array $customInvalidFilter): void { @@ -441,22 +411,12 @@ protected function getCustomTransformingFilter( extends TrimFilter implements TransformingFilterInterface { - private $customSerializer; - private $customFilter; - private $token; - private $acceptedTypes; - public function __construct( - array $customSerializer, - array $customFilter, - string $token, - array $acceptedTypes, - ) { - $this->customSerializer = $customSerializer; - $this->customFilter = $customFilter; - $this->token = $token; - $this->acceptedTypes = $acceptedTypes; - } + private array $customSerializer, + private array $customFilter, + private string $token, + private array $acceptedTypes, + ) {} public function getAcceptedTypes(): array { @@ -560,9 +520,6 @@ public function testFilterExceptionsAreCaught(): void /** * @dataProvider additionalFilterOptionsDataProvider - * - * @param string $namespace - * @param string $schemaFile */ public function testAdditionalFilterOptions(string $namespace, string $schemaFile): void { @@ -685,11 +642,8 @@ public static function exceptionFilter(string $value): void /** * @dataProvider implicitNullNamespaceDataProvider - * - * @param bool $implicitNull - * @param string $namespace */ - public function testTransformingToScalarType(bool $implicitNull, string $namespace) + public function testTransformingToScalarType(bool $implicitNull, string $namespace): void { $className = $this->generateClassFromFile( 'TransformingScalarFilter.json', @@ -781,9 +735,6 @@ public function testFilterChainWithTransformingFilter(): void /** * @dataProvider implicitNullNamespaceDataProvider - * - * @param bool $implicitNull - * @param string $namespace */ public function testFilterChainWithTransformingFilterOnMultiTypeProperty( bool $implicitNull, @@ -913,9 +864,6 @@ public static function stripTimeFilterStrict(DateTime $value): DateTime /** * @dataProvider arrayFilterDataProvider - * - * @param array|null $input - * @param array|null $output */ public function testArrayFilter(?array $input, ?array $output): void { @@ -967,8 +915,6 @@ public function testEnumCheckWithTransformingFilterIsNotExecutedForTransformedVa /** * @dataProvider implicitNullDataProvider - * - * @param bool $implicitNull */ public function testDefaultValuesAreTransformed(bool $implicitNull): void { diff --git a/tests/Basic/IdenticalNestedSchemaTest.php b/tests/Basic/IdenticalNestedSchemaTest.php index 5788038..0caadd3 100644 --- a/tests/Basic/IdenticalNestedSchemaTest.php +++ b/tests/Basic/IdenticalNestedSchemaTest.php @@ -37,7 +37,7 @@ public function testIdenticalSchemaInSingleFileAreMappedToOneClass(): void $this->assertSame('Hello', $object->getObject1()->getProperty1()); $this->assertSame('Goodbye', $object->getObject2()->getProperty1()); - $this->assertSame(get_class($object->getObject1()), get_class($object->getObject2())); + $this->assertSame($object->getObject1()::class, $object->getObject2()::class); } public function testIdenticalReferencedSchemaInSingleFileAreMappedToOneClass(): void @@ -62,16 +62,12 @@ public function testIdenticalReferencedSchemaInSingleFileAreMappedToOneClass(): $this->assertSame('Frida', $object->getObject2()->getMember()->getName()); $this->assertSame(24, $object->getObject2()->getMember()->getAge()); - $this->assertSame(get_class($object->getObject1()->getMember()), get_class($object->getObject2()->getMember())); + $this->assertSame($object->getObject1()->getMember()::class, $object->getObject2()->getMember()::class); } /** * @dataProvider identicalReferencedSchemaDataProvider * - * @param string $file - * @param string $class1FQCN - * @param string $class2FQCN - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -96,7 +92,7 @@ public function testIdenticalReferencedSchemaInMultipleFilesAreMappedToOneClass( $this->assertSame('Frida', $object2->getMember()->getName()); $this->assertSame(24, $object2->getMember()->getAge()); - $this->assertSame(get_class($object1->getMember()), get_class($object2->getMember())); + $this->assertSame($object1->getMember()::class, $object2->getMember()::class); } public function identicalReferencedSchemaDataProvider(): array @@ -132,7 +128,7 @@ public function testIdenticalSchemasInDifferentNamespaceAreMappedToOneClass(): v $subObject2 = new $subClass2FQCN(['object1' => ['property1' => 'Goodbye']]); $this->assertSame('Goodbye', $subObject2->getObject1()->getProperty1()); - $this->assertSame(get_class($subObject1->getObject1()), get_class($subObject2->getObject1())); + $this->assertSame($subObject1->getObject1()::class, $subObject2->getObject1()::class); } public function testIdenticalSchemasInArraysAreMappedToOneClass(): void @@ -150,7 +146,7 @@ public function testIdenticalSchemasInArraysAreMappedToOneClass(): void $subObject2 = new $subClass2FQCN(['object1' => [['property1' => 'Goodbye']]]); $this->assertSame('Goodbye', $subObject2->getObject1()[0]->getProperty1()); - $this->assertSame(get_class($subObject1->getObject1()[0]), get_class($subObject2->getObject1()[0])); + $this->assertSame($subObject1->getObject1()[0]::class, $subObject2->getObject1()[0]::class); } public function testIdenticalSchemasInCompositionAreMappedToOneClass(): void @@ -186,9 +182,9 @@ public function testIdenticalSchemasInCompositionAreMappedToOneClass(): void $subObject2 = new $subClass2FQCN(['object1' => ['property1' => 'Goodbye'], 'property3' => true]); $this->assertSame('Goodbye', $subObject2->getObject1()->getProperty1()); - $this->assertSame(true, $subObject2->getProperty3()); + $this->assertTrue($subObject2->getProperty3()); - $this->assertSame(get_class($subObject1->getObject1()), get_class($subObject2->getObject1())); + $this->assertSame($subObject1->getObject1()::class, $subObject2->getObject1()::class); } public function testIdenticalSchemasInCompositionInArrayAreMappedToOneClass(): void @@ -208,9 +204,9 @@ public function testIdenticalSchemasInCompositionInArrayAreMappedToOneClass(): v $subObject2 = new $subClass2FQCN(['object1' => [['property1' => 'Goodbye']], 'property3' => true]); $this->assertSame('Goodbye', $subObject2->getObject1()[0]->getProperty1()); - $this->assertSame(true, $subObject2->getProperty3()); + $this->assertTrue($subObject2->getProperty3()); - $this->assertSame(get_class($subObject1->getObject1()[0]), get_class($subObject2->getObject1()[0])); + $this->assertSame($subObject1->getObject1()[0]::class, $subObject2->getObject1()[0]::class); } public function testIdenticalSchemasCombined1AreMappedToOneClass(): void @@ -230,9 +226,9 @@ public function testIdenticalSchemasCombined1AreMappedToOneClass(): void $subObject2 = new $subClass2FQCN(['object1' => [['property1' => 'Goodbye']], 'property3' => true]); $this->assertSame('Goodbye', $subObject2->getObject1()[0]->getProperty1()); - $this->assertSame(true, $subObject2->getProperty3()); + $this->assertTrue($subObject2->getProperty3()); - $this->assertSame(get_class($subObject1->getObject1()), get_class($subObject2->getObject1()[0])); + $this->assertSame($subObject1->getObject1()::class, $subObject2->getObject1()[0]::class); } public function testIdenticalSchemasCombined2AreMappedToOneClass(): void @@ -255,9 +251,9 @@ public function testIdenticalSchemasCombined2AreMappedToOneClass(): void ]); $this->assertSame('Goodbye', $subObject2->getObject1()[0]->getProperty1()); - $this->assertSame(true, $subObject2->getProperty3()); + $this->assertTrue($subObject2->getProperty3()); $this->assertSame('Wow so many compositions', $subObject2->getExtendedProperty()); - $this->assertSame(get_class($subObject1->getObject1()), get_class($subObject2->getObject1()[0])); + $this->assertSame($subObject1->getObject1()::class, $subObject2->getObject1()[0]::class); } } diff --git a/tests/Basic/ObjectSizeTest.php b/tests/Basic/ObjectSizeTest.php index 0d8b1fb..5b052f0 100644 --- a/tests/Basic/ObjectSizeTest.php +++ b/tests/Basic/ObjectSizeTest.php @@ -16,8 +16,6 @@ class ObjectSizeTest extends AbstractPHPModelGeneratorTestCase { /** * @dataProvider validObjectPropertyAmountDataProvider - * - * @param array $propertyValue */ public function testObjectWithPropertyAmountInRangeIsValid(array $propertyValue): void { @@ -37,9 +35,6 @@ public function validObjectPropertyAmountDataProvider(): array /** * @dataProvider invalidObjectPropertyAmountDataProvider - * - * @param array $propertyValue - * @param string $exceptionMessage */ public function testObjectWithInvalidPropertyAmountThrowsAnException( array $propertyValue, diff --git a/tests/Basic/PatternPropertiesTest.php b/tests/Basic/PatternPropertiesTest.php index 3fab49c..dd9e121 100644 --- a/tests/Basic/PatternPropertiesTest.php +++ b/tests/Basic/PatternPropertiesTest.php @@ -34,7 +34,7 @@ public function testTypedPatternPropertyWithInvalidInputThrowsAnException( $this->expectValidationError( $configuration, 'Invalid type for pattern property. Requires string, got ' . - (is_object($propertyValue) ? get_class($propertyValue) : gettype($propertyValue)), + (is_object($propertyValue) ? $propertyValue::class : gettype($propertyValue)), ); $className = $this->generateClassFromFile('TypedPatternProperty.json', $configuration); diff --git a/tests/Basic/PropertyDependencyTest.php b/tests/Basic/PropertyDependencyTest.php index c5b8f35..48216cb 100644 --- a/tests/Basic/PropertyDependencyTest.php +++ b/tests/Basic/PropertyDependencyTest.php @@ -16,8 +16,6 @@ class PropertyDependencyTest extends AbstractPHPModelGeneratorTestCase { /** * @dataProvider validPropertyDependencyDataProvider - * - * @param array $propertyValue */ public function testValidPropertyDependency(array $propertyValue): void { @@ -39,8 +37,6 @@ public function validPropertyDependencyDataProvider(): array /** * @dataProvider validMultiplePropertyDependenciesDataProvider - * - * @param array $propertyValue */ public function testValidMultiplePropertyDependencies(array $propertyValue): void { @@ -65,8 +61,6 @@ public function validMultiplePropertyDependenciesDataProvider(): array /** * @dataProvider validBidirectionalPropertyDependencyDataProvider - * - * @param array $propertyValue */ public function testValidBidirectionalPropertyDependency(array $propertyValue): void { @@ -87,8 +81,6 @@ public function validBidirectionalPropertyDependencyDataProvider(): array /** * @dataProvider validationMethodDataProvider - * - * @param GeneratorConfiguration $configuration */ public function testInvalidPropertyDependencyThrowsAnException(GeneratorConfiguration $configuration): void { $this->expectValidationError( @@ -106,10 +98,6 @@ public function testInvalidPropertyDependencyThrowsAnException(GeneratorConfigur /** * @dataProvider invalidMultiplePropertyDependenciesDataProvider - * - * @param GeneratorConfiguration $configuration - * @param array $propertyValue - * @param string $message */ public function testInvalidMultiplePropertyDependenciesThrowsAnException( GeneratorConfiguration $configuration, @@ -156,10 +144,6 @@ public function invalidMultiplePropertyDependenciesDataProvider(): array /** * @dataProvider invalidBidirectionalPropertyDependencyDataProvider - * - * @param GeneratorConfiguration $configuration - * @param array $propertyValue - * @param string $message */ public function testInvalidBidirectionalPropertyDependencyThrowsAnException( GeneratorConfiguration $configuration, diff --git a/tests/Basic/PropertyNamesTest.php b/tests/Basic/PropertyNamesTest.php index 42dd90f..739ca76 100644 --- a/tests/Basic/PropertyNamesTest.php +++ b/tests/Basic/PropertyNamesTest.php @@ -17,8 +17,6 @@ class PropertyNamesTest extends AbstractPHPModelGeneratorTestCase { /** * @dataProvider validationMethodDataProvider - * - * @param GeneratorConfiguration $generatorConfiguration */ public function testEmptyPropertyNamesAcceptsAllProperties(GeneratorConfiguration $generatorConfiguration): void { @@ -39,10 +37,6 @@ public function testEmptyPropertyNamesAcceptsAllProperties(GeneratorConfiguratio /** * @dataProvider validPropertyNamesDataProvider - * - * @param GeneratorConfiguration $generatorConfiguration - * @param string $propertyNames - * @param array $properties */ public function testValidPropertyNames( GeneratorConfiguration $generatorConfiguration, @@ -98,11 +92,6 @@ public function validPropertyNamesDataProvider(): array /** * @dataProvider invalidPropertyNamesDataProvider * @dataProvider invalidCombinedPropertyNamesDataProvider - * - * @param GeneratorConfiguration $generatorConfiguration - * @param string $propertyNames - * @param array $properties - * @param string $exceptionMessage */ public function testInvalidPropertyNamesThrowsAnException( GeneratorConfiguration $generatorConfiguration, diff --git a/tests/Basic/SchemaDependencyTest.php b/tests/Basic/SchemaDependencyTest.php index 426e80e..4852465 100644 --- a/tests/Basic/SchemaDependencyTest.php +++ b/tests/Basic/SchemaDependencyTest.php @@ -17,8 +17,6 @@ class SchemaDependencyTest extends AbstractPHPModelGeneratorTestCase { /** * @dataProvider validSchemaDependencyDataProvider - * - * @param array $propertyValue */ public function testValidSchemaDependency(array $propertyValue): void { @@ -47,10 +45,6 @@ public function validSchemaDependencyDataProvider(): array /** * @dataProvider invalidSchemaDependencyDataProvider - * - * @param GeneratorConfiguration $configuration - * @param array $propertyValue - * @param string $message */ public function testInvalidSchemaDependency( GeneratorConfiguration $configuration, @@ -96,8 +90,6 @@ public function invalidSchemaDependencyDataProvider(): array /** * @dataProvider validSchemaDependencyReferenceDataProvider - * - * @param array $propertyValue */ public function testSchemaDependencyReference(array $propertyValue): void { @@ -126,10 +118,6 @@ public function validSchemaDependencyReferenceDataProvider(): array /** * @dataProvider invalidSchemaDependencyReferenceDataProvider - * - * @param GeneratorConfiguration $configuration - * @param array $propertyValue - * @param string $message */ public function testInvalidSchemaDependencyReference( GeneratorConfiguration $configuration, @@ -175,8 +163,6 @@ public function invalidSchemaDependencyReferenceDataProvider(): array /** * @dataProvider validSchemaDependencyCompositionDataProvider - * - * @param array $propertyValue */ public function testSchemaDependencyComposition(array $propertyValue): void { @@ -204,9 +190,6 @@ public function validSchemaDependencyCompositionDataProvider(): array /** * @dataProvider invalidSchemaDependencyCompositionDataProvider - * - * @param array $propertyValue - * @param string $message */ public function testInvalidSchemaDependencyComposition( array $propertyValue, @@ -270,8 +253,6 @@ public function invalidSchemaDependencyCompositionDataProvider(): array /** * @dataProvider validSchemaDependencyNestedObejctDataProvider - * - * @param array $propertyValue */ public function testSchemaDependencyNestedObject(array $propertyValue): void { @@ -317,9 +298,6 @@ public function validSchemaDependencyNestedObejctDataProvider(): array /** * @dataProvider invalidSchemaDependencyNestedObjectDataProvider - * - * @param array $propertyValue - * @param string $message */ public function testInvalidSchemaDependencyNestedObject( array $propertyValue, diff --git a/tests/Basic/SchemaHookTest.php b/tests/Basic/SchemaHookTest.php index 964ecd5..82b1af4 100644 --- a/tests/Basic/SchemaHookTest.php +++ b/tests/Basic/SchemaHookTest.php @@ -47,13 +47,9 @@ public function getCode(): string /** * @dataProvider constructorAfterValidationHookDataProvider - * - * @param $value - * @param string $expectedException - * @param string $expectedExceptionMessage */ public function testConstructorAfterValidationHookIsResolved( - $value, + bool|string $value, string $expectedException, string $expectedExceptionMessage, ): void { @@ -136,13 +132,9 @@ public function getCode(PropertyInterface $property, bool $batchUpdate = false): /** * @dataProvider setterAfterValidationHookDataProvider - * - * @param $value - * @param string $expectedException - * @param string $expectedExceptionMessage */ public function testSetterAfterValidationHookIsResolved( - $value, + int $value, string $expectedException, string $expectedExceptionMessage, ): void { @@ -210,12 +202,8 @@ protected function addSchemaHook(SchemaHookInterface $schemaHook): void { $this->modifyModelGenerator = static function (ModelGenerator $modelGenerator) use ($schemaHook): void { $modelGenerator->addPostProcessor(new class ($schemaHook) extends PostProcessor { - private $schemaHook; + public function __construct(private SchemaHookInterface $schemaHook) {} - public function __construct(SchemaHookInterface $schemaHook) - { - $this->schemaHook = $schemaHook; - } public function process(Schema $schema, GeneratorConfiguration $generatorConfiguration): void { $schema->addSchemaHook($this->schemaHook); diff --git a/tests/ComposedValue/ComposedAllOfTest.php b/tests/ComposedValue/ComposedAllOfTest.php index 2d66328..d3a5b62 100644 --- a/tests/ComposedValue/ComposedAllOfTest.php +++ b/tests/ComposedValue/ComposedAllOfTest.php @@ -22,10 +22,8 @@ class ComposedAllOfTest extends AbstractPHPModelGeneratorTestCase { /** * @dataProvider validEmptyAllOfDataProvider - * - * @param $propertyValue */ - public function testEmptyAllOfIsValid($propertyValue): void + public function testEmptyAllOfIsValid(mixed $propertyValue): void { $className = $this->generateClassFromFile('EmptyAllOf.json'); @@ -47,8 +45,6 @@ public function validEmptyAllOfDataProvider(): array /** * @dataProvider propertyLevelAllOfSchemaFileDataProvider - * - * @param string $schema */ public function testNotProvidedPropertyLevelAllOfIsValid(string $schema): void { @@ -86,8 +82,6 @@ public function testNotProvidedObjectLevelAllOfNotMatchingAnyOptionThrowsAnExcep /** * @dataProvider implicitNullDataProvider - * - * @param bool $implicitNull */ public function testCompositionTypes(bool $implicitNull): void { @@ -153,8 +147,6 @@ public function testAllOfTypePropertyHasTypeAnnotation(): void /** * @dataProvider validComposedPropertyDataProvider - * - * @param int|null $propertyValue */ public function testComposedPropertyDefinitionWithValidValues(?int $propertyValue): void { @@ -183,12 +175,9 @@ public function validComposedPropertyDataProvider(): array /** * @dataProvider invalidComposedPropertyDataProvider - * - * @param $propertyValue - * @param string $exceptionMessage */ public function testComposedPropertyDefinitionWithInvalidValuesThrowsAnException( - $propertyValue, + int $propertyValue, string $exceptionMessage, ): void { $this->expectException(ValidationException::class); @@ -211,10 +200,8 @@ public function invalidComposedPropertyDataProvider(): array /** * @dataProvider validExtendedPropertyDataProvider - * - * @param $propertyValue */ - public function testExtendedPropertyDefinitionWithValidValues($propertyValue): void + public function testExtendedPropertyDefinitionWithValidValues(int|float|null $propertyValue): void { $className = $this->generateClassFromFile('ExtendedPropertyDefinition.json'); @@ -243,12 +230,9 @@ public function validExtendedPropertyDataProvider(): array /** * @dataProvider invalidExtendedPropertyDataProvider - * - * @param $propertyValue - * @param string $exceptionMessage */ public function testExtendedPropertyDefinitionWithInvalidValuesThrowsAnException( - $propertyValue, + mixed $propertyValue, string $exceptionMessage, ): void { $this->expectException(ValidationException::class); @@ -303,10 +287,10 @@ public function referencedPersonDataProvider(): array /** * @dataProvider invalidObjectPropertyWithReferencedPersonSchemaDataProvider - * - * @param $propertyValue */ - public function testNotMatchingObjectPropertyWithReferencedPersonSchemaThrowsAnException($propertyValue): void { + public function testNotMatchingObjectPropertyWithReferencedPersonSchemaThrowsAnException( + mixed $propertyValue, + ): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('Invalid value for property declined by composition constraint'); @@ -334,10 +318,8 @@ public function invalidObjectPropertyWithReferencedPersonSchemaDataProvider(): a /** * @dataProvider invalidObjectPropertyWithReferencedPetSchemaDataProvider - * - * @param $propertyValue */ - public function testNotMatchingObjectPropertyWithReferencedPetSchemaThrowsAnException($propertyValue): void + public function testNotMatchingObjectPropertyWithReferencedPetSchemaThrowsAnException(mixed $propertyValue): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('Invalid value for property declined by composition constraint'); @@ -365,10 +347,6 @@ public function invalidObjectPropertyWithReferencedPetSchemaDataProvider(): arra /** * @dataProvider validComposedObjectDataProvider * @dataProvider validComposedObjectWithRequiredPropertiesDataProvider - * - * @param array $input - * @param string|null $stringPropertyValue - * @param int|null $intPropertyValue */ public function testMatchingPropertyForComposedAllOfObjectIsValid( array $input, @@ -396,8 +374,6 @@ public function validComposedObjectDataProvider(): array /** * @dataProvider invalidComposedObjectDataProvider - * - * @param array $input */ public function testNotMatchingPropertyForComposedAllOfObjectThrowsAnException(array $input): void { @@ -408,7 +384,7 @@ public function testNotMatchingPropertyForComposedAllOfObjectThrowsAnException(a new $className($input); } - public function invalidComposedObjectDataProvider() + public function invalidComposedObjectDataProvider(): array { return [ 'both invalid types' => [['integerProperty' => '10', 'stringProperty' => 10]], @@ -430,8 +406,6 @@ public function invalidComposedObjectDataProvider() /** * @dataProvider validComposedObjectWithRequiredPropertiesDataProvider * Must throw an exception as only one option matches - * - * @param array $input */ public function testMatchingPropertyForComposedAllOfObjectWithRequiredPropertiesThrowsAnException( array $input, @@ -445,8 +419,6 @@ public function testMatchingPropertyForComposedAllOfObjectWithRequiredProperties /** * @dataProvider invalidComposedObjectDataProvider - * - * @param array $input */ public function testNotMatchingPropertyForComposedAllOfObjectWithRequiredPropertiesThrowsAnException( array $input, @@ -470,10 +442,8 @@ public function validComposedObjectWithRequiredPropertiesDataProvider(): array /** * @dataProvider nestedObjectDataProvider - * - * @param string $schema */ - public function testObjectLevelCompositionArrayWithNestedObject(string $schema) + public function testObjectLevelCompositionArrayWithNestedObject(string $schema): void { $className = $this->generateClassFromFile($schema); @@ -486,7 +456,7 @@ public function testObjectLevelCompositionArrayWithNestedObject(string $schema) $this->assertSame(112, $object->getCars()[0]->getPs()); } - public function nestedObjectDataProvider() + public function nestedObjectDataProvider(): array { return [ ['ObjectLevelCompositionNestedObject.json'], @@ -504,10 +474,6 @@ public function testNoNestedSchemaThrowsAnException(): void /** * @dataProvider validationInSetterDataProvider - * - * @param GeneratorConfiguration $generatorConfiguration - * @param string $exceptionMessageIntegerPropertyInvalid - * @param string $exceptionMessageStringPropertyInvalid */ public function testValidationInSetterMethods( GeneratorConfiguration $generatorConfiguration, @@ -611,7 +577,7 @@ public function testIdenticalMergedSchemaIsRedirected(): void 'CFO' => ['name' => 'Dieter', 'salary' => 75000], ]); - $this->assertSame(get_class($object->getCEO()), get_class($object->getCFO())); + $this->assertSame($object->getCEO()::class, $object->getCFO()::class); $this->assertRegExp( '/ComposedAllOfTest_\w+_Merged_CEO\w+\|null$/', diff --git a/tests/ComposedValue/ComposedAnyOfTest.php b/tests/ComposedValue/ComposedAnyOfTest.php index 04f216d..a25c010 100644 --- a/tests/ComposedValue/ComposedAnyOfTest.php +++ b/tests/ComposedValue/ComposedAnyOfTest.php @@ -32,7 +32,7 @@ public function testNullProvidedForEmptyOptionalAnyOfIsValid(): void * * @param $propertyValue */ - public function testValueProvidedForEmptyOptionalAnyOfIsInvalid($propertyValue): void + public function testValueProvidedForEmptyOptionalAnyOfIsInvalid(string|int|array $propertyValue): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage(<<generateClassFromFile('AnyOfType.json'); @@ -163,10 +157,6 @@ public function testValidProvidedAnyOfTypePropertyIsValid($propertyValue): void /** * @dataProvider annotationDataProvider - * - * @param string $schema - * @param string $annotationPattern - * @param int $generatedClasses */ public function testAnyOfTypePropertyHasTypeAnnotation( string $schema, @@ -214,10 +204,8 @@ public function annotationDataProvider(): array /** * @dataProvider invalidPropertyTypeDataProvider - * - * @param $propertyValue */ - public function testInvalidProvidedAnyOfTypePropertyThrowsAnException($propertyValue): void + public function testInvalidProvidedAnyOfTypePropertyThrowsAnException(mixed $propertyValue): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('Invalid value for property declined by composition constraint'); @@ -252,10 +240,8 @@ public function invalidPropertyTypeDataProvider(): array /** * @dataProvider validPropertyTypeDataProvider - * - * @param $propertyValue */ - public function testValidProvidedRequiredAnyOfTypePropertyIsValid($propertyValue): void + public function testValidProvidedRequiredAnyOfTypePropertyIsValid(mixed $propertyValue): void { $className = $this->generateClassFromFile('AnyOfTypeRequired.json'); @@ -266,10 +252,8 @@ public function testValidProvidedRequiredAnyOfTypePropertyIsValid($propertyValue /** * @dataProvider invalidPropertyTypeDataProvider * @dataProvider nullDataProvider - * - * @param $propertyValue */ - public function testInvalidProvidedRequiredAnyOfTypePropertyThrowsAnException($propertyValue): void + public function testInvalidProvidedRequiredAnyOfTypePropertyThrowsAnException(mixed $propertyValue): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('Invalid value for property declined by composition constraint'); @@ -286,10 +270,8 @@ public function nullDataProvider(): array /** * @dataProvider validExtendedPropertyDataProvider - * - * @param $propertyValue */ - public function testExtendedPropertyDefinitionWithValidValues($propertyValue): void + public function testExtendedPropertyDefinitionWithValidValues(int | float | null $propertyValue): void { $className = $this->generateClassFromFile('ExtendedPropertyDefinition.json'); @@ -313,12 +295,9 @@ public function validExtendedPropertyDataProvider(): array /** * @dataProvider invalidExtendedPropertyDataProvider - * - * @param $propertyValue - * @param string $exceptionMessage */ public function testExtendedPropertyDefinitionWithInvalidValuesThrowsAnException( - $propertyValue, + mixed $propertyValue, string $exceptionMessage, ): void { $this->expectException(ValidationException::class); @@ -344,12 +323,11 @@ public function invalidExtendedPropertyDataProvider(): array /** * @dataProvider composedPropertyWithReferencedSchemaDataProvider - * - * @param string $schema - * @param $propertyValue */ - public function testMatchingComposedPropertyWithReferencedSchemaIsValid(string $schema, $propertyValue): void - { + public function testMatchingComposedPropertyWithReferencedSchemaIsValid( + string $schema, + ?string $propertyValue, + ): void { $className = $this->generateClassFromFile($schema); $object = new $className(['property' => $propertyValue]); @@ -372,8 +350,6 @@ public function composedPropertyWithReferencedSchemaDataProvider(): array /** * @dataProvider referencedPersonDataProvider - * - * @param string $schema */ public function testMatchingObjectPropertyWithReferencedPersonSchemaIsValid(string $schema): void { @@ -405,8 +381,6 @@ public function referencedPetDataProvider(): array /** * @dataProvider referencedPetDataProvider - * - * @param string $schema */ public function testMatchingObjectPropertyWithReferencedPetSchemaIsValid(string $schema): void { @@ -420,13 +394,10 @@ public function testMatchingObjectPropertyWithReferencedPetSchemaIsValid(string /** * @dataProvider invalidObjectPropertyWithReferencedPersonSchemaDataProvider - * - * @param string $schema - * @param $propertyValue */ public function testNotMatchingObjectPropertyWithReferencedPersonSchemaThrowsAnException( string $schema, - $propertyValue, + mixed $propertyValue, ): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('Invalid value for property declined by composition constraint'); @@ -458,13 +429,10 @@ public function invalidObjectPropertyWithReferencedPersonSchemaDataProvider(): a /** * @dataProvider invalidObjectPropertyWithReferencedPetSchemaDataProvider - * - * @param string $schema - * @param $propertyValue */ public function testNotMatchingObjectPropertyWithReferencedPetSchemaThrowsAnException( string $schema, - $propertyValue, + mixed $propertyValue, ): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('Invalid value for property declined by composition constraint'); @@ -497,10 +465,6 @@ public function invalidObjectPropertyWithReferencedPetSchemaDataProvider(): arra * @dataProvider validComposedObjectDataProvider * @dataProvider validComposedObjectDataProviderRequired * @dataProvider validComposedObjectWithRequiredPropertiesDataProvider - * - * @param array $input - * @param string|null $stringPropertyValue - * @param int|null $intPropertyValue */ public function testMatchingPropertyForComposedAnyOfObjectIsValid( array $input, @@ -538,8 +502,6 @@ public function validComposedObjectDataProviderRequired(): array /** * @dataProvider invalidComposedObjectDataProvider - * - * @param array $input */ public function testNotMatchingPropertyForComposedAnyOfObjectThrowsAnException(array $input): void { @@ -550,7 +512,7 @@ public function testNotMatchingPropertyForComposedAnyOfObjectThrowsAnException(a new $className($input); } - public function invalidComposedObjectDataProvider() + public function invalidComposedObjectDataProvider(): array { return [ 'both invalid types' => [['integerProperty' => '10', 'stringProperty' => 10]], @@ -565,10 +527,6 @@ public function invalidComposedObjectDataProvider() /** * @dataProvider validComposedObjectDataProviderRequired * @dataProvider validComposedObjectWithRequiredPropertiesDataProvider - * - * @param array $input - * @param string|null $stringPropertyValue - * @param int|null $intPropertyValue */ public function testMatchingPropertyForComposedAnyOfObjectWithRequiredPropertiesIsValid( array $input, @@ -584,8 +542,6 @@ public function testMatchingPropertyForComposedAnyOfObjectWithRequiredProperties /** * @dataProvider invalidComposedObjectDataProvider - * - * @param array $input */ public function testNotMatchingPropertyForComposedAnyOfObjectWithRequiredPropertiesThrowsAnException(array $input): void { @@ -608,9 +564,6 @@ public function validComposedObjectWithRequiredPropertiesDataProvider(): array /** * @dataProvider validationInSetterDataProvider - * - * @param GeneratorConfiguration $generatorConfiguration - * @param string $exceptionMessageBothInvalid */ public function testValidationInSetterMethods( GeneratorConfiguration $generatorConfiguration, diff --git a/tests/ComposedValue/ComposedIfTest.php b/tests/ComposedValue/ComposedIfTest.php index ab6b005..c7ea079 100644 --- a/tests/ComposedValue/ComposedIfTest.php +++ b/tests/ComposedValue/ComposedIfTest.php @@ -20,8 +20,6 @@ class ComposedIfTest extends AbstractPHPModelGeneratorTestCase { /** * @dataProvider conditionalKeywordsDataProvider - * - * @param string $keyword */ public function testIncompleteConditionalsOnPropertyLevelResolveToProperties(string $keyword): void { @@ -44,7 +42,6 @@ public function conditionalKeywordsDataProvider(): array /** * @dataProvider validConditionalPropertyDefinitionDataProvider - * @param int $value */ public function testConditionalPropertyDefinition(int $value): void { @@ -68,9 +65,6 @@ public function validConditionalPropertyDefinitionDataProvider(): array /** * @dataProvider invalidConditionalPropertyDefinitionDataProvider - * - * @param int $value - * @param string $expectedExceptionMessage */ public function testInvalidConditionalPropertyDefinition(int $value, string $expectedExceptionMessage): void { $this->expectException(ConditionalException::class); @@ -117,12 +111,6 @@ public function invalidConditionalPropertyDefinitionDataProvider(): array /** * @dataProvider validConditionalObjectPropertyDataProvider - * - * @param string $schemaFile - * @param GeneratorConfiguration $configuration - * @param string|null $streetAddress - * @param string|null $country - * @param string|null $postalCode */ public function testConditionalObjectProperty( string $schemaFile, @@ -170,12 +158,6 @@ public function validConditionalObjectPropertyDataProvider(): array /** * @dataProvider invalidConditionalObjectPropertyDataProvider * - * @param string $schemaFile - * @param GeneratorConfiguration $configuration - * @param string|null $streetAddress - * @param string|null $country - * @param string|null $postalCode - * * @throws FileSystemException * @throws RenderException * @throws SchemaException diff --git a/tests/ComposedValue/ComposedNotTest.php b/tests/ComposedValue/ComposedNotTest.php index 0c5cb39..f964256 100644 --- a/tests/ComposedValue/ComposedNotTest.php +++ b/tests/ComposedValue/ComposedNotTest.php @@ -25,10 +25,8 @@ class ComposedNotTest extends AbstractPHPModelGeneratorTestCase { /** * @dataProvider emptyNotDataProvider - * - * @param $propertyValue */ - public function testEmptyNotIsInvalid($propertyValue): void + public function testEmptyNotIsInvalid(mixed $propertyValue): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage(<<generateClassFromFile('NotNull.json', $configuration); @@ -204,16 +191,13 @@ public function validNotNullPropertyDataProvider(): array /** * @dataProvider validExtendedPropertyDataProvider * - * @param GeneratorConfiguration $configuration - * @param $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ public function testExtendedPropertyDefinitionWithValidValues( GeneratorConfiguration $configuration, - $propertyValue, + float $propertyValue, ): void { $className = $this->generateClassFromFile('ExtendedPropertyDefinition.json', $configuration); @@ -236,17 +220,13 @@ public function validExtendedPropertyDataProvider(): array /** * @dataProvider invalidExtendedPropertyDataProvider * - * @param GeneratorConfiguration $configuration - * @param $propertyValue - * @param string $exceptionMessage - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ public function testExtendedPropertyDefinitionWithInvalidValuesThrowsAnException( GeneratorConfiguration $configuration, - $propertyValue, + mixed $propertyValue, string $exceptionMessage, ): void { $this->expectValidationError($configuration, $exceptionMessage); @@ -277,8 +257,6 @@ public function invalidExtendedPropertyDataProvider(): array /** * @dataProvider validationMethodDataProvider * - * @param GeneratorConfiguration $configuration - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -295,16 +273,13 @@ public function testNotProvidedObjectPropertyWithReferencedSchemaIsValid( /** * @dataProvider objectPropertyWithReferencedSchemaDataProvider * - * @param GeneratorConfiguration $configuration - * @param $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ public function testNotMatchingObjectPropertyWithReferencedSchemaIsValid( GeneratorConfiguration $configuration, - $propertyValue, + mixed $propertyValue, ): void { $className = $this->generateClassFromFile('ReferencedObjectSchema.json', $configuration); @@ -335,8 +310,6 @@ public function objectPropertyWithReferencedSchemaDataProvider(): array /** * @dataProvider validationMethodDataProvider * - * @param GeneratorConfiguration $configuration - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -353,9 +326,6 @@ public function testMatchingObjectPropertyWithReferencedSchemaThrowsAnException( /** * @dataProvider validationInSetterDataProvider - * - * @param GeneratorConfiguration $generatorConfiguration - * @param string $exceptionMessage */ public function testComposedNotValidationInSetterMethods( GeneratorConfiguration $generatorConfiguration, diff --git a/tests/ComposedValue/ComposedOneOfTest.php b/tests/ComposedValue/ComposedOneOfTest.php index c981d77..57e4287 100644 --- a/tests/ComposedValue/ComposedOneOfTest.php +++ b/tests/ComposedValue/ComposedOneOfTest.php @@ -29,10 +29,8 @@ public function testNullProvidedForEmptyOptionalOneOfIsValid(): void /** * @dataProvider validEmptyOneOfDataProvider - * - * @param $propertyValue */ - public function testValueProvidedForEmptyOptionalOneOfIsInvalid($propertyValue): void + public function testValueProvidedForEmptyOptionalOneOfIsInvalid(string|int|array $propertyValue): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage(<<generateClassFromFile('OneOfType.json'); @@ -163,9 +152,6 @@ public function testValidProvidedOneOfTypePropertyIsValid($propertyValue): void /** * @dataProvider annotationDataProvider - * - * @param string $schema - * @param string $annotationPattern */ public function testOneOfTypePropertyHasTypeAnnotation(string $schema, string $annotationPattern): void { @@ -187,10 +173,8 @@ public function annotationDataProvider(): array /** * @dataProvider invalidPropertyTypeDataProvider - * - * @param $propertyValue */ - public function testInvalidProvidedOneOfTypePropertyThrowsAnException($propertyValue): void + public function testInvalidProvidedOneOfTypePropertyThrowsAnException(mixed $propertyValue): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('Invalid value for property declined by composition constraint'); @@ -225,10 +209,8 @@ public function invalidPropertyTypeDataProvider(): array /** * @dataProvider validPropertyTypeDataProvider - * - * @param $propertyValue */ - public function testValidProvidedRequiredOneOfTypePropertyIsValid($propertyValue): void + public function testValidProvidedRequiredOneOfTypePropertyIsValid(string|int|bool $propertyValue): void { $className = $this->generateClassFromFile('OneOfTypeRequired.json'); @@ -239,10 +221,8 @@ public function testValidProvidedRequiredOneOfTypePropertyIsValid($propertyValue /** * @dataProvider invalidPropertyTypeDataProvider * @dataProvider nullDataProvider - * - * @param $propertyValue */ - public function testInvalidProvidedRequiredOneOfTypePropertyThrowsAnException($propertyValue): void + public function testInvalidProvidedRequiredOneOfTypePropertyThrowsAnException(mixed $propertyValue): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('Invalid value for property declined by composition constraint'); @@ -259,10 +239,8 @@ public function nullDataProvider(): array /** * @dataProvider validExtendedPropertyDataProvider - * - * @param $propertyValue */ - public function testExtendedPropertyDefinitionWithValidValues($propertyValue): void + public function testExtendedPropertyDefinitionWithValidValues(int|float|null $propertyValue): void { $className = $this->generateClassFromFile('ExtendedPropertyDefinition.json'); @@ -283,12 +261,9 @@ public function validExtendedPropertyDataProvider(): array /** * @dataProvider invalidExtendedPropertyDataProvider - * - * @param $propertyValue - * @param string $exceptionMessage */ public function testExtendedPropertyDefinitionWithInvalidValuesThrowsAnException( - $propertyValue, + mixed $propertyValue, string $exceptionMessage, ): void { $this->expectException(ValidationException::class); @@ -317,10 +292,8 @@ public function invalidExtendedPropertyDataProvider(): array /** * @dataProvider composedPropertyWithReferencedSchemaDataProvider - * - * @param $propertyValue */ - public function testMatchingComposedPropertyWithReferencedSchemaIsValid($propertyValue): void + public function testMatchingComposedPropertyWithReferencedSchemaIsValid(?string $propertyValue): void { $className = $this->generateClassFromFile('ReferencedObjectSchema.json'); @@ -338,8 +311,6 @@ public function composedPropertyWithReferencedSchemaDataProvider(): array /** * @dataProvider referencedPersonDataProvider - * - * @param string $schema */ public function testMatchingObjectPropertyWithReferencedPersonSchemaIsValid(string $schema): void { @@ -372,13 +343,10 @@ public function testMatchingObjectPropertyWithReferencedPetSchemaIsValid(): void /** * @dataProvider invalidObjectPropertyWithReferencedPersonSchemaDataProvider - * - * @param string $schema - * @param $propertyValue */ public function testNotMatchingObjectPropertyWithReferencedPersonSchemaThrowsAnException( string $schema, - $propertyValue, + mixed $propertyValue, ): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('Invalid value for property declined by composition constraint'); @@ -410,10 +378,8 @@ public function invalidObjectPropertyWithReferencedPersonSchemaDataProvider(): a /** * @dataProvider invalidObjectPropertyWithReferencedPetSchemaDataProvider - * - * @param $propertyValue */ - public function testNotMatchingObjectPropertyWithReferencedPetSchemaThrowsAnException($propertyValue): void + public function testNotMatchingObjectPropertyWithReferencedPetSchemaThrowsAnException(mixed $propertyValue): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('Invalid value for property declined by composition constraint'); @@ -440,10 +406,6 @@ public function invalidObjectPropertyWithReferencedPetSchemaDataProvider(): arra /** * @dataProvider validComposedObjectDataProvider - * - * @param array $input - * @param string|null $stringPropertyValue - * @param int|null $intPropertyValue */ public function testMatchingPropertyForComposedOneOfObjectIsValid( array $input, @@ -474,8 +436,6 @@ public function validComposedObjectDataProvider(): array * @dataProvider invalidComposedObjectDataProvider * @dataProvider validComposedObjectWithRequiredPropertiesDataProvider * Must throw an exception as the given input data is valid against both options - * - * @param array $input */ public function testNotMatchingPropertyForComposedOneOfObjectThrowsAnException(array $input): void { @@ -486,7 +446,7 @@ public function testNotMatchingPropertyForComposedOneOfObjectThrowsAnException(a new $className($input); } - public function invalidComposedObjectDataProvider() + public function invalidComposedObjectDataProvider(): array { return [ // valid against both options @@ -506,10 +466,6 @@ public function invalidComposedObjectDataProvider() /** * @dataProvider validComposedObjectDataProvider * @dataProvider validComposedObjectWithRequiredPropertiesDataProvider - * - * @param array $input - * @param string|null $stringPropertyValue - * @param int|null $intPropertyValue */ public function testMatchingPropertyForComposedOneOfObjectWithRequiredPropertiesIsValid( array $input, @@ -525,8 +481,6 @@ public function testMatchingPropertyForComposedOneOfObjectWithRequiredProperties /** * @dataProvider invalidComposedObjectDataProvider - * - * @param array $input */ public function testNotMatchingPropertyForComposedOneOfObjectWithRequiredPropertiesThrowsAnException(array $input): void { @@ -549,10 +503,6 @@ public function validComposedObjectWithRequiredPropertiesDataProvider(): array /** * @dataProvider validationInSetterDataProvider - * - * @param GeneratorConfiguration $generatorConfiguration - * @param string $exceptionMessageBothValid - * @param string $exceptionMessageBothInvalid */ public function testValidationInSetterMethods( GeneratorConfiguration $generatorConfiguration, diff --git a/tests/Issues/Issue/Issue70Test.php b/tests/Issues/Issue/Issue70Test.php index 4ba7463..50c49e8 100644 --- a/tests/Issues/Issue/Issue70Test.php +++ b/tests/Issues/Issue/Issue70Test.php @@ -13,7 +13,7 @@ class Issue70Test extends AbstractIssueTestCase /** * @dataProvider validInputDataProvider */ - public function testValidInput(string $filter, array $input, $expectedOutput): void + public function testValidInput(string $filter, array $input, string|int|null $expectedOutput): void { $className = $this->generateClassFromFileTemplate( 'filterInCompositionInArray.json', diff --git a/tests/Objects/AbstractNumericPropertyTestCase.php b/tests/Objects/AbstractNumericPropertyTestCase.php index f9a0bff..6cd8502 100644 --- a/tests/Objects/AbstractNumericPropertyTestCase.php +++ b/tests/Objects/AbstractNumericPropertyTestCase.php @@ -32,10 +32,8 @@ abstract public function invalidMultipleOfDataProvider(): iterable; /** * @dataProvider validRangeDataProvider - * - * @param $propertyValue */ - public function testValidValueForRangeValidator($propertyValue) + public function testValidValueForRangeValidator($propertyValue): void { $className = $this->generateClassFromFile($this->getRangeFile(false)); @@ -44,10 +42,8 @@ public function testValidValueForRangeValidator($propertyValue) } /** * @dataProvider validExclusiveRangeDataProvider - * - * @param $propertyValue */ - public function testValidValueForExclusiveRangeValidator($propertyValue) + public function testValidValueForExclusiveRangeValidator($propertyValue): void { $className = $this->generateClassFromFile($this->getRangeFile(true)); @@ -57,11 +53,8 @@ public function testValidValueForExclusiveRangeValidator($propertyValue) /** * @dataProvider invalidRangeDataProvider - * - * @param $propertyValue - * @param string $exceptionMessage */ - public function testInvalidValueForRangeValidatorThrowsAnException($propertyValue, string $exceptionMessage) + public function testInvalidValueForRangeValidatorThrowsAnException($propertyValue, string $exceptionMessage): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage($exceptionMessage); @@ -75,9 +68,8 @@ public function testInvalidValueForRangeValidatorThrowsAnException($propertyValu * @dataProvider invalidExclusiveRangeDataProvider * * @param $propertyValue - * @param string $exceptionMessage */ - public function testInvalidValueForExclusiveRangeValidatorThrowsAnException($propertyValue, string $exceptionMessage) + public function testInvalidValueForExclusiveRangeValidatorThrowsAnException($propertyValue, string $exceptionMessage): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage($exceptionMessage); diff --git a/tests/Objects/AnyPropertyTest.php b/tests/Objects/AnyPropertyTest.php index 6e316b2..6b581ec 100644 --- a/tests/Objects/AnyPropertyTest.php +++ b/tests/Objects/AnyPropertyTest.php @@ -21,8 +21,6 @@ class AnyPropertyTest extends AbstractPHPModelGeneratorTestCase /** * @dataProvider validationMethodDataProvider * - * @param GeneratorConfiguration $configuration - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -38,8 +36,6 @@ public function testNotProvidedOptionalAnyPropertyIsValid(GeneratorConfiguration /** * @dataProvider validationMethodDataProvider * - * @param GeneratorConfiguration $configuration - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -55,14 +51,11 @@ public function testNotProvidedRequiredAnyPropertyThrowsAnException(GeneratorCon /** * @dataProvider validPropertyTypeDataProvider * - * @param GeneratorConfiguration $configuration - * @param $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ - public function testAnyProvidedTypeIsValid(GeneratorConfiguration $configuration, $propertyValue): void + public function testAnyProvidedTypeIsValid(GeneratorConfiguration $configuration, mixed $propertyValue): void { $className = $this->generateClassFromFile('AnyProperty.json', $configuration); diff --git a/tests/Objects/ArrayPropertyTest.php b/tests/Objects/ArrayPropertyTest.php index 13c34c6..1b61c08 100644 --- a/tests/Objects/ArrayPropertyTest.php +++ b/tests/Objects/ArrayPropertyTest.php @@ -23,9 +23,6 @@ class ArrayPropertyTest extends AbstractPHPModelGeneratorTestCase /** * @dataProvider validArrayPropertyValueProvider * - * @param GeneratorConfiguration $configuration - * @param array $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -117,11 +114,8 @@ public function testNotProvidedValueDefaultsToEmptyArrayWithDefaultArraysToEmpty /** * @dataProvider defaultArraysToEmptyArrayDataProvider - * - * @param $input - * @param array $expectedOutput */ - public function testValidValueWithDefaultArraysToEmptyArrayEnabled($input, array $expectedOutput): void + public function testValidValueWithDefaultArraysToEmptyArrayEnabled(?array $input, array $expectedOutput): void { $className = $this->generateClassFromFile( 'ArrayProperty.json', @@ -170,9 +164,6 @@ public function testUntypedRequiredArrayType(bool $implicitNull): void /** * @dataProvider optionalArrayPropertyDataProvider * - * @param GeneratorConfiguration $configuration - * @param string $file - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -190,9 +181,6 @@ public function testNotProvidedOptionalArrayPropertyIsValid( /** * @dataProvider optionalArrayPropertyDataProvider * - * @param GeneratorConfiguration $configuration - * @param string $file - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -221,21 +209,18 @@ public function optionalArrayPropertyDataProvider(): array /** * @dataProvider invalidPropertyTypeDataProvider * - * @param GeneratorConfiguration $configuration - * @param $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ public function testInvalidPropertyTypeThrowsAnException( GeneratorConfiguration $configuration, - $propertyValue, + mixed $propertyValue, ): void { $this->expectValidationError( $configuration, 'Invalid type for property. Requires array, got ' . - (is_object($propertyValue) ? get_class($propertyValue) : gettype($propertyValue)), + (is_object($propertyValue) ? $propertyValue::class : gettype($propertyValue)), ); $className = $this->generateClassFromFile('ArrayProperty.json', $configuration); @@ -260,16 +245,13 @@ public function invalidPropertyTypeDataProvider(): array /** * @dataProvider validUniqueArrayPropertyValueProvider * - * @param GeneratorConfiguration $configuration - * @param $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ public function testUniqueArrayIsValidWithUniqueConstraint( GeneratorConfiguration $configuration, - $propertyValue, + ?array $propertyValue, ): void { $className = $this->generateClassFromFile('ArrayPropertyUnique.json', $configuration); @@ -294,9 +276,6 @@ public function validUniqueArrayPropertyValueProvider(): array /** * @dataProvider invalidUniqueArrayPropertyValueProvider * - * @param GeneratorConfiguration $configuration - * @param array $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -328,9 +307,6 @@ public function invalidUniqueArrayPropertyValueProvider(): array /** * @dataProvider arrayInItemAmountValidationRangePassesDataProvider * - * @param GeneratorConfiguration $configuration - * @param array $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -360,10 +336,6 @@ public function arrayInItemAmountValidationRangePassesDataProvider(): array /** * @dataProvider invalidItemAmountDataProvider * - * @param GeneratorConfiguration $configuration - * @param array $propertyValue - * @param string $exceptionMessage - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -395,11 +367,6 @@ public function invalidItemAmountDataProvider(): array /** * @dataProvider validTypedArrayDataProvider * - * @param GeneratorConfiguration $configuration - * @param string $type - * @param $propertyValue - * @param $expectedValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -407,8 +374,8 @@ public function invalidItemAmountDataProvider(): array public function testTypedArrayIsValid( GeneratorConfiguration $configuration, string $type, - $propertyValue, - $expectedValue = null, + ?array $propertyValue, + ?array $expectedValue = null, ): void { $className = $this->generateClassFromFileTemplate('ArrayPropertyTyped.json', [$type], $configuration, false); @@ -440,10 +407,6 @@ public function validTypedArrayDataProvider(): array /** * @dataProvider typedArrayTypeDataProvider - * - * @param bool $implicitNull - * @param string $type - * @param string $expectedAnnotation */ public function testTypedOptionalArrayType(bool $implicitNull, string $type, string $expectedAnnotation): void { @@ -476,10 +439,6 @@ public function testTypedOptionalArrayType(bool $implicitNull, string $type, str /** * @dataProvider typedArrayTypeDataProvider - * - * @param bool $implicitNull - * @param string $type - * @param string $expectedAnnotation */ public function testTypedRequiredArrayType(bool $implicitNull, string $type, string $expectedAnnotation): void { @@ -519,11 +478,6 @@ public function typedArrayTypeDataProvider(): array /** * @dataProvider invalidTypedArrayDataProvider * - * @param GeneratorConfiguration $configuration - * @param string $type - * @param $propertyValue - * @param string $message - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -531,7 +485,7 @@ public function typedArrayTypeDataProvider(): array public function testInvalidTypedArrayThrowsAnException( GeneratorConfiguration $configuration, string $type, - $propertyValue, + array $propertyValue, string $message = '', ): void { $this->expectValidationError($configuration, $message); @@ -666,9 +620,6 @@ public function invalidTypedArrayDataProvider(): array /** * @dataProvider validArrayContainsDataProvider - * - * @param GeneratorConfiguration $configuration - * @param array $propertyValue */ public function testValidValuesForArrayContains(GeneratorConfiguration $configuration, array $propertyValue): void { @@ -694,9 +645,6 @@ public function validArrayContainsDataProvider(): array /** * @dataProvider invalidArrayContainsDataProvider - * - * @param GeneratorConfiguration $configuration - * @param array $propertyValue */ public function testInvalidValuesForArrayContainsTrowsAnException( GeneratorConfiguration $configuration, @@ -726,10 +674,6 @@ public function invalidArrayContainsDataProvider(): array /** * @dataProvider validObjectArrayDataProvider * - * @param string $file - * @param GeneratorConfiguration $configuration - * @param array $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -789,11 +733,6 @@ public function validObjectArrayDataProvider(): array * @dataProvider invalidObjectArrayDataProvider * @dataProvider invalidCombinedObjectArrayDataProvider * - * @param string $file - * @param GeneratorConfiguration $configuration - * @param array $propertyValue - * @param string $message - * * @throws FileSystemException * @throws RenderException * @throws SchemaException diff --git a/tests/Objects/BooleanPropertyTest.php b/tests/Objects/BooleanPropertyTest.php index a22ef80..1d1d81b 100644 --- a/tests/Objects/BooleanPropertyTest.php +++ b/tests/Objects/BooleanPropertyTest.php @@ -60,18 +60,16 @@ public function validInputProvider(): array /** * @dataProvider invalidPropertyTypeDataProvider * - * @param $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ - public function testInvalidPropertyTypeThrowsAnException($propertyValue): void + public function testInvalidPropertyTypeThrowsAnException(mixed $propertyValue): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage( 'Invalid type for property. Requires bool, got ' . - (is_object($propertyValue) ? get_class($propertyValue) : gettype($propertyValue)), + (is_object($propertyValue) ? $propertyValue::class : gettype($propertyValue)), ); $className = $this->generateClassFromFile('BooleanProperty.json'); diff --git a/tests/Objects/ConstPropertyTest.php b/tests/Objects/ConstPropertyTest.php index 4ed8664..9b35ca5 100644 --- a/tests/Objects/ConstPropertyTest.php +++ b/tests/Objects/ConstPropertyTest.php @@ -166,13 +166,11 @@ public function testNotMatchingOneOfPropertyThrowsAnException(): void /** * @dataProvider invalidPropertyDataProvider * - * @param $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ - public function testNotMatchingProvidedDataThrowsAnException($propertyValue): void + public function testNotMatchingProvidedDataThrowsAnException(mixed $propertyValue): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('Invalid value for stringProperty declined by const constraint'); diff --git a/tests/Objects/EnumPropertyTest.php b/tests/Objects/EnumPropertyTest.php index e1a96a9..58273fe 100644 --- a/tests/Objects/EnumPropertyTest.php +++ b/tests/Objects/EnumPropertyTest.php @@ -35,7 +35,7 @@ public function testNotProvidedOptionalEnumItemIsValid(): void $className = $this->generateEnumClass('string', static::ENUM_STRING); $object = new $className([]); - $this->assertSame(null, $object->getProperty()); + $this->assertNull($object->getProperty()); } /** @@ -110,18 +110,16 @@ public function invalidEnumEntriesDataProvider(): array /** * @dataProvider invalidItemTypeDataProvider * - * @param $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ - public function testInvalidItemTypeThrowsAnException($propertyValue): void + public function testInvalidItemTypeThrowsAnException(mixed $propertyValue): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage( 'Invalid type for property. Requires string, got ' . - (is_object($propertyValue) ? get_class($propertyValue) : gettype($propertyValue)), + (is_object($propertyValue) ? $propertyValue::class : gettype($propertyValue)), ); $className = $this->generateEnumClass('string', static::ENUM_STRING); @@ -187,7 +185,7 @@ public function testNotProvidedEnumItemIsValidInOptionalUntypedEnum(bool $implic ); $object = new $className([]); - $this->assertSame(null, $object->getProperty()); + $this->assertNull($object->getProperty()); $this->assertSame('string|int|null', $this->getPropertyTypeAnnotation($object, 'property')); @@ -204,13 +202,11 @@ public function testNotProvidedEnumItemIsValidInOptionalUntypedEnum(bool $implic /** * @dataProvider validEnumEntriesUntypedEnumDataProvider * - * @param $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ - public function testEnumItemIsValidInUntypedEnum($propertyValue): void + public function testEnumItemIsValidInUntypedEnum(string|int|null $propertyValue): void { $className = $this->generateClassFromFile('UntypedEnumProperty.json'); @@ -239,7 +235,7 @@ public function testSuccessCreateObjectWithOptionalFieldsContainingZero(): void $object = new $className(['property' => 10]); $this->assertSame(10, $object->getProperty()); - $this->assertSame(null, $object->getPropertyWithZero()); + $this->assertNull($object->getPropertyWithZero()); $returnType = $this->getReturnType($object, 'getPropertyWithZero'); $this->assertSame('int', $returnType->getName()); @@ -264,13 +260,11 @@ public function testNullInUntypedEnumWithoutImplicitNullThrowsAnException(): voi /** * @dataProvider invalidEnumEntriesUntypedEnumDataProvider * - * @param $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ - public function testInvalidItemInUntypedEnumThrowsAnException($propertyValue): void + public function testInvalidItemInUntypedEnumThrowsAnException(mixed $propertyValue): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('Invalid value for property declined by enum constraint'); @@ -295,8 +289,6 @@ public function invalidEnumEntriesUntypedEnumDataProvider(): array /** * @dataProvider implicitNullDataProvider * - * @param bool $implicitNull - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -314,8 +306,6 @@ public function testNotProvidedEnumItemInRequiredUntypedEnumThrowsAnException(bo /** * @dataProvider implicitNullDataProvider * - * @param bool $implicitNull - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -344,8 +334,6 @@ public function testProvidedEnumItemForRequiredUntypedEnumIsValid(bool $implicit /** * @dataProvider implicitNullDataProvider * - * @param bool $implicitNull - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -382,8 +370,6 @@ public function testTypesAreInheritedFromEnumValuesForUntypedProperties(bool $im /** * @dataProvider implicitNullDataProvider * - * @param bool $implicitNull - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -407,12 +393,7 @@ public function testEmptyEnumThrowsSchemaException(): void protected function generateEnumClass(string $type, array $enumValues, $required = false): string { - $enumValues = array_map( - static function ($item): string { - return var_export($item, true); - }, - $enumValues, - ); + $enumValues = array_map(static fn($item): string => var_export($item, true), $enumValues); return $this->generateClassFromFileTemplate( 'EnumProperty.json', diff --git a/tests/Objects/IntegerPropertyTest.php b/tests/Objects/IntegerPropertyTest.php index 749ce2d..4cf90c3 100644 --- a/tests/Objects/IntegerPropertyTest.php +++ b/tests/Objects/IntegerPropertyTest.php @@ -60,18 +60,16 @@ public function validInputProvider(): array /** * @dataProvider invalidPropertyTypeDataProvider * - * @param $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ - public function testInvalidPropertyTypeThrowsAnException($propertyValue): void + public function testInvalidPropertyTypeThrowsAnException(mixed $propertyValue): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage( 'Invalid type for property. Requires int, got ' . - (is_object($propertyValue) ? get_class($propertyValue) : gettype($propertyValue)), + (is_object($propertyValue) ? $propertyValue::class : gettype($propertyValue)), ); $className = $this->generateClassFromFile('IntegerProperty.json'); diff --git a/tests/Objects/MultiTypePropertyTest.php b/tests/Objects/MultiTypePropertyTest.php index 490dc97..56f5eba 100644 --- a/tests/Objects/MultiTypePropertyTest.php +++ b/tests/Objects/MultiTypePropertyTest.php @@ -87,10 +87,8 @@ public function testRequiredMultiTypeAnnotation(bool $implicitNull): void /** * @dataProvider validValueDataProvider - * - * @param $propertyValue */ - public function testValidProvidedValuePassesValidation($propertyValue): void + public function testValidProvidedValuePassesValidation(mixed $propertyValue): void { $className = $this->generateClassFromFile('MultiTypeProperty.json'); @@ -111,11 +109,8 @@ public function validValueDataProvider(): array /** * @dataProvider invalidValueDataProvider - * - * @param $propertyValue - * @param string $exceptionMessage */ - public function testInvalidProvidedValueThrowsAnException($propertyValue, string $exceptionMessage): void + public function testInvalidProvidedValueThrowsAnException(mixed $propertyValue, string $exceptionMessage): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage($exceptionMessage); @@ -221,7 +216,7 @@ public function invalidNestedObjectDataProvider(): array /** * @dataProvider validRecursiveMultiTypeDataProvider */ - public function testValidRecursiveMultiType($input): void + public function testValidRecursiveMultiType(string|array $input): void { $className = $this->generateClassFromFile('RecursiveMultiTypeProperty.json'); @@ -242,8 +237,11 @@ public function validRecursiveMultiTypeDataProvider(): array /** * @dataProvider invalidRecursiveMultiTypeDataProvider */ - public function testInvalidRecursiveMultiType($input, string $expectedException, string $exceptionMessage): void - { + public function testInvalidRecursiveMultiType( + int|array $input, + string $expectedException, + string $exceptionMessage, + ): void { $this->expectException($expectedException); $this->expectExceptionMessage($exceptionMessage); diff --git a/tests/Objects/NullPropertyTest.php b/tests/Objects/NullPropertyTest.php index c8766c0..e6173ab 100644 --- a/tests/Objects/NullPropertyTest.php +++ b/tests/Objects/NullPropertyTest.php @@ -47,18 +47,16 @@ public function testProvidedOptionalNullPropertyIsValid(): void /** * @dataProvider invalidPropertyTypeDataProvider * - * @param $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ - public function testInvalidPropertyTypeThrowsAnException($propertyValue): void + public function testInvalidPropertyTypeThrowsAnException(mixed $propertyValue): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage( 'Invalid type for property. Requires null, got ' . - (is_object($propertyValue) ? get_class($propertyValue) : gettype($propertyValue)), + (is_object($propertyValue) ? $propertyValue::class : gettype($propertyValue)), ); $className = $this->generateClassFromFile('NullProperty.json'); diff --git a/tests/Objects/NumberPropertyTest.php b/tests/Objects/NumberPropertyTest.php index 6680045..354b2d7 100644 --- a/tests/Objects/NumberPropertyTest.php +++ b/tests/Objects/NumberPropertyTest.php @@ -52,7 +52,7 @@ public function testProvidedOptionalNumberPropertyIsValid(): void * @throws RenderException * @throws SchemaException */ - public function testProvidedNumberPropertyIsValid($input): void + public function testProvidedNumberPropertyIsValid(int|float|null $input): void { $className = $this->generateClassFromFile('NumberProperty.json'); @@ -76,18 +76,16 @@ public function validInputProvider(): array /** * @dataProvider invalidPropertyTypeDataProvider * - * @param $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ - public function testInvalidPropertyTypeThrowsAnException($propertyValue): void + public function testInvalidPropertyTypeThrowsAnException(mixed $propertyValue): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage( 'Invalid type for property. Requires float, got ' . - (is_object($propertyValue) ? get_class($propertyValue) : gettype($propertyValue)), + (is_object($propertyValue) ? $propertyValue::class : gettype($propertyValue)), ); $className = $this->generateClassFromFile('NumberProperty.json'); diff --git a/tests/Objects/ObjectPropertyTest.php b/tests/Objects/ObjectPropertyTest.php index b353da1..6160223 100644 --- a/tests/Objects/ObjectPropertyTest.php +++ b/tests/Objects/ObjectPropertyTest.php @@ -34,9 +34,6 @@ public function testNotProvidedOptionalObjectPropertyIsValid(): void /** * @dataProvider validInputProvider * - * @param array $input - * @param string $typeCheck - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -61,13 +58,11 @@ public function validInputProvider(): array /** * @dataProvider invalidPropertyTypeDataProvider * - * @param $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ - public function testInvalidPropertyTypeThrowsAnException($propertyValue): void + public function testInvalidPropertyTypeThrowsAnException(mixed $propertyValue): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('Invalid type for property. Requires object, got ' . gettype($propertyValue)); @@ -107,9 +102,6 @@ public function testInvalidPropertyObjectClassThrowsAnException(): void /** * @dataProvider validInputProviderObjectLevelValidation * - * @param array $input - * @param string $typeCheck - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -143,10 +135,6 @@ public function validInputProviderObjectLevelValidation(): array /** * @dataProvider invalidInputProviderObjectLevelValidation * - * @param array $input - * @param string $exceptionClass - * @param string $exceptionMessage - * * @throws FileSystemException * @throws RenderException * @throws SchemaException diff --git a/tests/Objects/ReferencePropertyTest.php b/tests/Objects/ReferencePropertyTest.php index 1cb5a99..4a963ad 100644 --- a/tests/Objects/ReferencePropertyTest.php +++ b/tests/Objects/ReferencePropertyTest.php @@ -26,8 +26,6 @@ class ReferencePropertyTest extends AbstractPHPModelGeneratorTestCase * @dataProvider internalReferenceProvider * @dataProvider notResolvedExternalReferenceProvider * - * @param string $reference - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -73,8 +71,6 @@ public function notResolvedExternalReferenceProvider(): array * @dataProvider internalReferenceProvider * @dataProvider externalReferenceProvider * - * @param string $reference - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -98,10 +94,6 @@ public function testIdWithoutHashSymbolIsResolved(): void /** * @dataProvider validReferenceObjectInputProvider * - * @param string $reference - * @param array $input - * @param string $typeCheck - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -139,15 +131,14 @@ public function validReferenceObjectInputProvider(): array * @dataProvider invalidInternalReferenceObjectPropertyTypeDataProvider * @dataProvider invalidExternalReferenceObjectPropertyTypeDataProvider * - * @param string $reference - * @param $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ - public function testInvalidReferenceObjectPropertyTypeThrowsAnException(string $reference, $propertyValue): void - { + public function testInvalidReferenceObjectPropertyTypeThrowsAnException( + string $reference, + mixed $propertyValue, + ): void { $this->expectException(ValidationException::class); if ($propertyValue instanceof stdClass) { $this->expectExceptionMessageMatches( @@ -192,9 +183,6 @@ public function invalidObjectPropertyTypeDataProvider(): array /** * @dataProvider validReferenceIntInputProvider * - * @param string $reference - * @param int|null $input - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -232,17 +220,13 @@ public function validReferenceIntInputProvider(): array /** * @dataProvider invalidReferenceIntPropertyTypeDataProvider * - * @param string $reference - * @param $propertyValue - * @param string $message - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ public function testInvalidReferenceIntPropertyTypeThrowsAnException( string $reference, - $propertyValue, + mixed $propertyValue, string $message, ): void { $this->expectException(ValidationException::class); @@ -291,9 +275,6 @@ public function combinedReferenceProvider(): array /** * @dataProvider combinedReferenceProvider * - * @param string $reference1 - * @param string $reference2 - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -312,9 +293,6 @@ public function testNotProvidedOptionalRecursiveReferenceObjectPropertyIsValid( /** * @dataProvider combinedReferenceProvider * - * @param string $reference1 - * @param string $reference2 - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -345,11 +323,11 @@ public function testProvidedRecursiveReferenceObjectPropertyIsValid( ]); $this->assertSame('Hannes', $object->getPerson()->getName()); - $this->assertSame(2, count($object->getPerson()->getChildren())); + $this->assertCount(2, $object->getPerson()->getChildren()); $this->assertSame('Louis', $object->getPerson()->getChildren()[0]->getName()); $this->assertEmpty($object->getPerson()->getChildren()[0]->getChildren()); $this->assertSame('Karl', $object->getPerson()->getChildren()[1]->getName()); - $this->assertSame(1, count($object->getPerson()->getChildren()[1]->getChildren())); + $this->assertCount(1, $object->getPerson()->getChildren()[1]->getChildren()); $this->assertSame('Yoshi', $object->getPerson()->getChildren()[1]->getChildren()[0]->getName()); $this->assertEmpty($object->getPerson()->getChildren()[1]->getChildren()[0]->getChildren()); } @@ -357,10 +335,6 @@ public function testProvidedRecursiveReferenceObjectPropertyIsValid( /** * @dataProvider invalidCombinedReferenceObjectPropertyTypeDataProvider * - * @param string $reference1 - * @param string $reference2 - * @param $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -368,7 +342,7 @@ public function testProvidedRecursiveReferenceObjectPropertyIsValid( public function testInvalidProvidedRecursiveReferenceObjectPropertyValueThrowsAnException( string $reference1, string $reference2, - $propertyValue, + mixed $propertyValue, ): void { $this->expectException(ValidationException::class); @@ -417,8 +391,6 @@ public function invalidCombinedReferenceObjectPropertyTypeDataProvider(): array /** * @dataProvider nestedReferenceProvider * - * @param string $reference - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -443,9 +415,9 @@ public function testNestedExternalReference(string $reference): void ] ]); - $this->assertSame(2, count($object->getFamily()->getMember())); + $this->assertCount(2, $object->getFamily()->getMember()); $this->assertSame('Hannes', $object->getFamily()->getMember()[0]->getName()); - $this->assertSame(1, count($object->getFamily()->getMember()[0]->getChildren())); + $this->assertCount(1, $object->getFamily()->getMember()[0]->getChildren()); $this->assertSame('Louis', $object->getFamily()->getMember()[0]->getChildren()[0]->getName()); $this->assertEmpty($object->getFamily()->getMember()[0]->getChildren()[0]->getChildren()); $this->assertSame('Anette', $object->getFamily()->getMember()[1]->getName()); @@ -527,9 +499,6 @@ public function testMultiplePropertiesWithIdenticalReference(): void /** * @dataProvider invalidValuesForMultiplePropertiesWithIdenticalReferenceDataProvider - * - * @param array $input - * @param string $exceptionMessage */ public function testInvalidValuesForMultiplePropertiesWithIdenticalReferenceThrowsAnException( array $input, diff --git a/tests/Objects/RequiredPropertyTest.php b/tests/Objects/RequiredPropertyTest.php index fed8b83..ceba416 100644 --- a/tests/Objects/RequiredPropertyTest.php +++ b/tests/Objects/RequiredPropertyTest.php @@ -22,8 +22,6 @@ class RequiredPropertyTest extends AbstractPHPModelGeneratorTestCase /** * @dataProvider validStringPropertyValueProvider * - * @param bool $implicitNull - * @param string $propertyValue * * @throws FileSystemException * @throws RenderException @@ -63,7 +61,6 @@ public function validStringPropertyValueProvider(): array /** * @dataProvider requiredDefinitionsDataProvider * - * @param bool $implicitNull * * @throws FileSystemException * @throws RenderException @@ -86,8 +83,6 @@ public function testNotProvidedRequiredPropertyThrowsAnException(bool $implicitN /** * @dataProvider requiredStringPropertyDataProvider - * - * @param bool $implicitNull */ public function testRequiredPropertyType(bool $implicitNull, string $schemaFile): void { @@ -109,8 +104,6 @@ public function testRequiredPropertyType(bool $implicitNull, string $schemaFile) /** * @dataProvider implicitNullDataProvider - * - * @param bool $implicitNull */ public function testUndefinedRequiredPropertyType(bool $implicitNull): void { @@ -131,7 +124,6 @@ public function testUndefinedRequiredPropertyType(bool $implicitNull): void /** * @dataProvider requiredStringPropertyDataProvider * - * @param bool $implicitNull * * @throws FileSystemException * @throws RenderException diff --git a/tests/Objects/StringPropertyTest.php b/tests/Objects/StringPropertyTest.php index b5d4b55..211ea8d 100644 --- a/tests/Objects/StringPropertyTest.php +++ b/tests/Objects/StringPropertyTest.php @@ -23,9 +23,6 @@ class StringPropertyTest extends AbstractPHPModelGeneratorTestCase /** * @dataProvider validStringPropertyValueProvider * - * @param GeneratorConfiguration $configuration - * @param string $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -55,8 +52,6 @@ public function validStringPropertyValueProvider(): array /** * @dataProvider validationMethodDataProvider * - * @param GeneratorConfiguration $configuration - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -72,21 +67,18 @@ public function testNotProvidedOptionalStringPropertyIsValid(GeneratorConfigurat /** * @dataProvider invalidPropertyTypeDataProvider * - * @param GeneratorConfiguration $configuration - * @param $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException */ public function testInvalidPropertyTypeThrowsAnException( GeneratorConfiguration $configuration, - $propertyValue, + mixed $propertyValue, ): void { $this->expectValidationError( $configuration, 'Invalid type for property. Requires string, got ' . - (is_object($propertyValue) ? get_class($propertyValue) : gettype($propertyValue)), + (is_object($propertyValue) ? $propertyValue::class : gettype($propertyValue)), ); $className = $this->generateClassFromFile('StringProperty.json', $configuration); @@ -111,9 +103,6 @@ public function invalidPropertyTypeDataProvider(): array /** * @dataProvider stringInLengthValidationRangePassesDataProvider * - * @param GeneratorConfiguration $configuration - * @param string $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -144,10 +133,6 @@ public function stringInLengthValidationRangePassesDataProvider(): array /** * @dataProvider invalidStringLengthDataProvider * - * @param GeneratorConfiguration $configuration - * @param string $propertyValue - * @param string $exceptionMessage - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -179,10 +164,6 @@ public function invalidStringLengthDataProvider(): array /** * @dataProvider validPatternProvider * - * @param GeneratorConfiguration $configuration - * @param string $pattern - * @param string $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -232,10 +213,6 @@ public function validPatternProvider(): array /** * @dataProvider invalidPatternProvider * - * @param GeneratorConfiguration $configuration - * @param string $pattern - * @param string $propertyValue - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -289,8 +266,6 @@ public function testStringFormatCheckIsValid(): void /** * @dataProvider invalidStringFormatDataProvider - * - * @param string $value */ public function testInvalidStringFormatCheck(string $value): void { diff --git a/tests/Objects/TupleArrayPropertyTest.php b/tests/Objects/TupleArrayPropertyTest.php index f9284a4..7c72c09 100644 --- a/tests/Objects/TupleArrayPropertyTest.php +++ b/tests/Objects/TupleArrayPropertyTest.php @@ -23,9 +23,6 @@ class TupleArrayPropertyTest extends AbstractPHPModelGeneratorTestCase * @dataProvider validIncompleteTupleArrayDataProvider * @dataProvider validTupleArrayDataProvider * @dataProvider validTupleArrayWithAdditionalPropertiesDataProvider - * - * @param GeneratorConfiguration $configuration - * @param array $propertyValue */ public function testValidValuesForTupleArray(GeneratorConfiguration $configuration, array $propertyValue): void { @@ -88,9 +85,6 @@ public function validTupleArrayWithAdditionalPropertiesDataProvider(): array /** * @dataProvider validTupleArrayWithAdditionalPropertiesDataProvider - * - * @param GeneratorConfiguration $configuration - * @param array $propertyValue */ public function testValidValuesForTupleArrayWithDisabledAdditionalItemsThrowsAnException( GeneratorConfiguration $configuration, @@ -108,10 +102,6 @@ public function testValidValuesForTupleArrayWithDisabledAdditionalItemsThrowsAnE /** * @dataProvider invalidTupleArrayDataProvider - * - * @param GeneratorConfiguration $configuration - * @param array $propertyValue - * @param string $message */ public function testInvalidValuesForTupleArrayThrowsAnException( GeneratorConfiguration $configuration, @@ -206,9 +196,6 @@ public function invalidTupleArrayDataProvider(): array /** * @dataProvider validAdditionalItemsDataProvider - * - * @param GeneratorConfiguration $configuration - * @param array $propertyValue */ public function testValidAdditionalItems(GeneratorConfiguration $configuration, array $propertyValue): void { @@ -236,10 +223,6 @@ public function validAdditionalItemsDataProvider(): array /** * @dataProvider invalidAdditionalItemsDataProvider * - * @param GeneratorConfiguration $configuration - * @param array $propertyValue - * @param string $message - * * @throws FileSystemException * @throws RenderException * @throws SchemaException @@ -309,9 +292,6 @@ public function invalidAdditionalItemsDataProvider(): array /** * @dataProvider validObjectAdditionalItemsDataProvider - * - * @param GeneratorConfiguration $configuration - * @param array $propertyValue */ public function testValidObjectAdditionalItems(GeneratorConfiguration $configuration, array $propertyValue): void { @@ -351,10 +331,6 @@ public function validObjectAdditionalItemsDataProvider(): array /** * @dataProvider invalidObjectAdditionalItemsDataProvider * - * @param GeneratorConfiguration $configuration - * @param array $propertyValue - * @param string $message - * * @throws FileSystemException * @throws RenderException * @throws SchemaException diff --git a/tests/PostProcessor/AdditionalPropertiesAccessorPostProcessorTest.php b/tests/PostProcessor/AdditionalPropertiesAccessorPostProcessorTest.php index f18b82d..532e09c 100644 --- a/tests/PostProcessor/AdditionalPropertiesAccessorPostProcessorTest.php +++ b/tests/PostProcessor/AdditionalPropertiesAccessorPostProcessorTest.php @@ -42,8 +42,6 @@ protected function addPostProcessor(bool $addForModelsWithoutAdditionalPropertie /** * @dataProvider additionalPropertiesAccessorPostProcessorConfigurationDataProvider - * - * @param bool $addForModelsWithoutAdditionalPropertiesDefinition */ public function testAdditionalPropertiesAccessorsAreNotGeneratedForAdditionalPropertiesFalse( bool $addForModelsWithoutAdditionalPropertiesDefinition, @@ -62,8 +60,6 @@ public function testAdditionalPropertiesAccessorsAreNotGeneratedForAdditionalPro /** * @dataProvider additionalPropertiesAccessorPostProcessorConfigurationDataProvider - * - * @param bool $addForModelsWithoutAdditionalPropertiesDefinition */ public function testAdditionalPropertiesAccessorsAreNotGeneratedWhenAdditionalPropertiesAreDenied( bool $addForModelsWithoutAdditionalPropertiesDefinition, @@ -85,8 +81,6 @@ public function testAdditionalPropertiesAccessorsAreNotGeneratedWhenAdditionalPr /** * @dataProvider additionalPropertiesAccessorPostProcessorConfigurationDataProvider - * - * @param bool $addForModelsWithoutAdditionalPropertiesDefinition */ public function testAdditionalPropertiesAccessorsDependOnConfigurationForAdditionalPropertiesNotDefined( bool $addForModelsWithoutAdditionalPropertiesDefinition, @@ -149,8 +143,6 @@ public function testAdditionalPropertiesSettersForMutableObjectsWithoutAdditiona /** * @dataProvider additionalPropertiesAccessorPostProcessorConfigurationDataProvider - * - * @param bool $addForModelsWithoutAdditionalPropertiesDefinition */ public function testAdditionalPropertiesAccessorsAreGeneratedForAdditionalProperties( bool $addForModelsWithoutAdditionalPropertiesDefinition, @@ -257,11 +249,6 @@ public function testAdditionalPropertiesModifiersAreGeneratedForMutableObjects() /** * @dataProvider invalidAdditionalPropertyDataProvider - * - * @param string $expectedException - * @param string $expectedExceptionMessage - * @param string $action - * @param array $items */ public function testInvalidAdditionalPropertyThrowsAnException( string $expectedException, @@ -358,8 +345,6 @@ public function getCode(PropertyInterface $property, bool $batchUpdate = false): /** * @dataProvider implicitNullDataProvider - * - * @param bool $implicitNull */ public function testAdditionalPropertiesAreSerialized(bool $implicitNull): void { diff --git a/tests/PostProcessor/EnumPostProcessorTest.php b/tests/PostProcessor/EnumPostProcessorTest.php index 95fdf1f..bef563b 100644 --- a/tests/PostProcessor/EnumPostProcessorTest.php +++ b/tests/PostProcessor/EnumPostProcessorTest.php @@ -77,11 +77,11 @@ public function testStringOnlyEnum(): void $this->assertEqualsCanonicalizing( ['Hans', 'Dieter'], - array_map(function (BackedEnum $value): string { return $value->name; }, $enum::cases()), + array_map(fn(BackedEnum $value): string => $value->name, $enum::cases()), ); $this->assertEqualsCanonicalizing( ['hans', 'dieter'], - array_map(function (BackedEnum $value): string { return $value->value; }, $enum::cases()), + array_map(fn(BackedEnum $value): string => $value->value, $enum::cases()), ); $object->setProperty($enum::Dieter); @@ -169,11 +169,11 @@ public function testMappedStringOnlyEnum(): void $this->assertEqualsCanonicalizing( ['Ceo', 'Cto'], - array_map(function (BackedEnum $value): string { return $value->name; }, $enum::cases()), + array_map(fn(BackedEnum $value): string => $value->name, $enum::cases()), ); $this->assertEqualsCanonicalizing( ['Hans', 'Dieter'], - array_map(function (BackedEnum $value): string { return $value->value; }, $enum::cases()), + array_map(fn(BackedEnum $value): string => $value->value, $enum::cases()), ); $object->setProperty($enum::Ceo); @@ -300,11 +300,11 @@ public function testIntOnlyEnum(): void $this->assertEqualsCanonicalizing( ['A', 'B'], - array_map(function (BackedEnum $value): string { return $value->name; }, $enum::cases()), + array_map(fn(BackedEnum $value): string => $value->name, $enum::cases()), ); $this->assertEqualsCanonicalizing( [10, 100], - array_map(function (BackedEnum $value): int { return $value->value; }, $enum::cases()), + array_map(fn(BackedEnum $value): int => $value->value, $enum::cases()), ); $object->setProperty($enum::A); @@ -366,11 +366,11 @@ public function testMixedEnum(): void $this->assertEqualsCanonicalizing( ['A', 'B', 'C'], - array_map(function (UnitEnum $value): string { return $value->name; }, $enum::cases()), + array_map(fn(UnitEnum $value): string => $value->name, $enum::cases()), ); $object->setProperty($enum::C); - $this->assertSame(true, $object->getProperty()->value()); + $this->assertTrue($object->getProperty()->value()); $this->assertNull($this->getParameterType($object, 'setProperty')); @@ -416,7 +416,7 @@ public function testIdenticalEnumsAreMappedToOneEnum(string $file, array $enums) $this->assertSame('Hans', $object->getProperty1()->value); $this->assertSame('Dieter', $object->getProperty2()->value); - $this->assertSame(get_class($object->getProperty1()), get_class($object->getProperty2())); + $this->assertSame($object->getProperty1()::class, $object->getProperty2()::class); } public function identicalEnumsDataProvider(): array @@ -457,7 +457,7 @@ public function testDifferentEnumsAreNotMappedToOneEnum(string $file, array $enu $this->assertSame('Hans', $object->getProperty1()->value); $this->assertSame('Dieter', $object->getProperty2()->value); - $this->assertNotSame(get_class($object->getProperty1()), get_class($object->getProperty2())); + $this->assertNotSame($object->getProperty1()::class, $object->getProperty2()::class); } public function differentEnumsDataProvider(): array @@ -596,7 +596,7 @@ public function testNameNormalization(string $name, string $expectedNormalizedNa $this->assertSame( [$expectedNormalizedName], - array_map(function (BackedEnum $value): string { return $value->name; }, $enum::cases()), + array_map(fn(BackedEnum $value): string => $value->name, $enum::cases()), ); } diff --git a/tests/PostProcessor/PatternPropertiesAccessorPostProcessorTest.php b/tests/PostProcessor/PatternPropertiesAccessorPostProcessorTest.php index 768bd5a..7bed2f1 100644 --- a/tests/PostProcessor/PatternPropertiesAccessorPostProcessorTest.php +++ b/tests/PostProcessor/PatternPropertiesAccessorPostProcessorTest.php @@ -139,16 +139,11 @@ public function testModifyingPatternPropertiesViaAdditionalPropertiesAccessor(): /** * @dataProvider invalidPatternPropertiesDataProvider - * - * @param GeneratorConfiguration $configuration - * @param string $property - * @param $value - * @param string $exceptionMessage */ public function testInvalidPatternPropertiesViaAdditionalPropertiesAccessorThrowsAnException( GeneratorConfiguration $configuration, string $property, - $value, + mixed $value, string $exceptionMessage, ): void { $this->addPostProcessors( @@ -267,7 +262,7 @@ public function testModifyingPatternPropertiesViaPopulate(): void try { $object->populate(['a0' => 50, 'a1' => 60, 'beta' => false]); $this->fail('Exception not thrown'); - } catch (Exception $exception) { + } catch (Exception) { $this->assertEqualsCanonicalizing($state, $object->toArray()); } } @@ -290,16 +285,11 @@ public function testPatternPropertiesAreSerializedWithoutPatternPropertiesAccess /** * @dataProvider invalidPatternPropertiesDataProvider - * - * @param GeneratorConfiguration $configuration - * @param string $property - * @param $value - * @param string $exceptionMessage */ public function testInvalidPatternPropertiesViaPopulateThrowsAnException( GeneratorConfiguration $configuration, string $property, - $value, + mixed $value, string $exceptionMessage, ): void { $this->addPostProcessors(new PatternPropertiesAccessorPostProcessor(), new PopulatePostProcessor()); @@ -356,14 +346,10 @@ public function testModifyingPatternPropertiesViaSetter(): void /** * @dataProvider invalidPropertiesDataProvider - * - * @param string $property - * @param $value - * @param string $exceptionMessage */ public function testInvalidPatternPropertiesViaSetterThrowsAnException( string $property, - $value, + int $value, string $exceptionMessage, ): void { $this->addPostProcessors(new PatternPropertiesAccessorPostProcessor()); diff --git a/tests/PostProcessor/PopulatePostProcessorTest.php b/tests/PostProcessor/PopulatePostProcessorTest.php index c6e58d2..590decd 100644 --- a/tests/PostProcessor/PopulatePostProcessorTest.php +++ b/tests/PostProcessor/PopulatePostProcessorTest.php @@ -84,8 +84,6 @@ public function testPopulateMethod(): void /** * @dataProvider implicitNullDataProvider - * - * @param bool $implicitNull */ public function testImplicitNullCheckOnPopulateMethodForOptionalProperty(bool $implicitNull): void { @@ -110,8 +108,6 @@ public function testImplicitNullCheckOnPopulateMethodForOptionalProperty(bool $i /** * @dataProvider implicitNullDataProvider - * - * @param bool $implicitNull */ public function testImplicitNullCheckOnPopulateMethodForOptionalRequiredProperty(bool $implicitNull): void { @@ -250,10 +246,6 @@ public function getCode(PropertyInterface $property, bool $batchUpdate = false): /** * @dataProvider setterAfterValidationHookDataProvider - * - * @param string|null $expectedException - * @param string|null $expectedExceptionMessage - * @param array $populateValues */ public function testSetterAfterValidationHookInsidePopulateIsResolved( ?string $expectedException, @@ -325,10 +317,6 @@ public function setterAfterValidationHookDataProvider(): array /** * @dataProvider compositionValidationInPopulateDataProvider - * - * @param GeneratorConfiguration $generatorConfiguration - * @param string $exceptionMessageBothValid - * @param string $exceptionMessageBothInvalid */ public function testPopulateComposition( GeneratorConfiguration $generatorConfiguration, diff --git a/tests/PropertyProcessor/PropertyProcessorFactoryTest.php b/tests/PropertyProcessor/PropertyProcessorFactoryTest.php index 2d1a9ca..bf1e7d1 100644 --- a/tests/PropertyProcessor/PropertyProcessorFactoryTest.php +++ b/tests/PropertyProcessor/PropertyProcessorFactoryTest.php @@ -30,8 +30,6 @@ class PropertyProcessorFactoryTest extends TestCase { /** * @dataProvider validPropertyProvider - * @param string $type - * @param string $expectedClass * * @throws SchemaException */ @@ -51,8 +49,6 @@ public function testGetPropertyProcessor(string $type, string $expectedClass): v /** * Provide valid properties which must result in a PropertyProcessor - * - * @return array */ public function validPropertyProvider(): array { @@ -70,7 +66,7 @@ public function validPropertyProvider(): array /** * @throws SchemaException */ - public function testGetInvalidPropertyProcessorThrowsAnException() + public function testGetInvalidPropertyProcessorThrowsAnException(): void { $this->expectException(SchemaException::class); $this->expectExceptionMessage('Unsupported property type Hello'); diff --git a/tests/manual/schema/person.json b/tests/manual/schema/person.json index 1a94693..0296a97 100644 --- a/tests/manual/schema/person.json +++ b/tests/manual/schema/person.json @@ -1,15 +1,19 @@ { + "$id": "Person", "type": "object", "properties": { - "property": { - "oneOf": [ - { - "const": "1" - }, - { - "const": "2" - } - ] + "name": { + "type": "string", + "description": "The name of the person", + "example": "Lawrence" + }, + "age": { + "type": "integer", + "description": "The age of the person", + "example": 42 } - } + }, + "required": [ + "name" + ] } \ No newline at end of file diff --git a/tests/manual/test.php b/tests/manual/test.php index 87d6c55..6045657 100644 --- a/tests/manual/test.php +++ b/tests/manual/test.php @@ -8,15 +8,9 @@ $generator = new ModelGenerator((new GeneratorConfiguration()) ->setNamespacePrefix('\\ManualSchema') - ->setImmutable(false) - ->setCollectErrors(false) - ->setImplicitNull(false) + ->setImmutable(false), ); $generator ->generateModelDirectory(__DIR__ . '/result') ->generateModels(new RecursiveDirectoryProvider(__DIR__ . '/schema'), __DIR__ . '/result'); - -$p = new \ManualSchema\Person(['property' => 1]); - -var_dump($p->getProperty());