From 24d3b326021e7cb1d236e6760dc4049099e74d39 Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 15 Nov 2024 15:12:20 +0100 Subject: [PATCH] refactor: add void return types --- UPGRADE-5.0.md | 27 +++++++++++++------ src/Describer/DescriberInterface.php | 5 +--- src/Describer/ExternalDocDescriber.php | 7 ++--- src/Describer/ModelRegistryAwareInterface.php | 5 +--- src/Describer/ModelRegistryAwareTrait.php | 5 +--- .../BazingaHateoasModelDescriber.php | 2 +- src/ModelDescriber/EnumModelDescriber.php | 2 +- .../FallbackObjectModelDescriber.php | 5 +--- src/ModelDescriber/JMSModelDescriber.php | 5 +--- .../ModelDescriberInterface.php | 5 +--- src/ModelDescriber/ObjectModelDescriber.php | 2 +- .../ArrayPropertyDescriber.php | 2 +- .../BooleanPropertyDescriber.php | 2 +- .../CompoundPropertyDescriber.php | 2 +- .../DateTimePropertyDescriber.php | 2 +- .../DictionaryPropertyDescriber.php | 2 +- .../FloatPropertyDescriber.php | 2 +- .../IntegerPropertyDescriber.php | 2 +- .../NullablePropertyDescriber.php | 2 +- .../ObjectPropertyDescriber.php | 2 +- .../PropertyDescriberInterface.php | 4 +-- .../StringPropertyDescriber.php | 2 +- .../UuidPropertyDescriber.php | 2 +- .../RouteDescriberInterface.php | 5 +--- ...ssDoesNotExistsHandlerDefinedDescriber.php | 2 +- 25 files changed, 44 insertions(+), 59 deletions(-) diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index b3a7de8af..d415d978d 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -76,11 +76,22 @@ Future proofing for potential future changes and keeping it consistent with `des ## BC BREAK: `Nelmio\ApiDocBundle\Command` has been made final ## BC BREAK: Made classes implementing `Nelmio\ApiDocBundle\PropertyDescriber\PropertyDescriberInterface` final -`Nelmio\ApiDocBundle\PropertyDescriber\ArrayPropertyDescriber` -`Nelmio\ApiDocBundle\PropertyDescriber\BooleanPropertyDescriber` -`Nelmio\ApiDocBundle\PropertyDescriber\DateTimePropertyDescriber` -`Nelmio\ApiDocBundle\PropertyDescriber\CompoundPropertyDescriber` -`Nelmio\ApiDocBundle\PropertyDescriber\FloatPropertyDescriber` -`Nelmio\ApiDocBundle\PropertyDescriber\IntegerPropertyDescriber` -`Nelmio\ApiDocBundle\PropertyDescriber\ObjectPropertyDescriber` -`Nelmio\ApiDocBundle\PropertyDescriber\StringPropertyDescriber` +- `Nelmio\ApiDocBundle\PropertyDescriber\ArrayPropertyDescriber` +- `Nelmio\ApiDocBundle\PropertyDescriber\BooleanPropertyDescriber` +- `Nelmio\ApiDocBundle\PropertyDescriber\DateTimePropertyDescriber` +- `Nelmio\ApiDocBundle\PropertyDescriber\CompoundPropertyDescriber` +- `Nelmio\ApiDocBundle\PropertyDescriber\FloatPropertyDescriber` +- `Nelmio\ApiDocBundle\PropertyDescriber\IntegerPropertyDescriber` +- `Nelmio\ApiDocBundle\PropertyDescriber\ObjectPropertyDescriber` +- `Nelmio\ApiDocBundle\PropertyDescriber\StringPropertyDescriber` + +## BC BREAK: Added `void` return type to: +- `Nelmio\ApiDocBundle\Describer\DescriberInterface::describe()` +- `Nelmio\ApiDocBundle\Describer\ExternalDocDescriber::describe()` +- `Nelmio\ApiDocBundle\ModelDescriber\ModelDescriberInterface::describe()` +- `Nelmio\ApiDocBundle\ModelDescriber\FallbackObjectModelDescriber::describe()` +- `Nelmio\ApiDocBundle\ModelDescriber\JMSModelDescriber::describe()` +- `Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface::setModelRegistry()` +- `Nelmio\ApiDocBundle\Describer\ModelRegistryAwareTrait::setModelRegistry()` +- `Nelmio\ApiDocBundle\PropertyDescriber\PropertyDescriberInterface::describe()` +- `Nelmio\ApiDocBundle\RouteDescriber\RouteDescriberInterface::describe()` diff --git a/src/Describer/DescriberInterface.php b/src/Describer/DescriberInterface.php index bcd7c73ea..5bab805d0 100644 --- a/src/Describer/DescriberInterface.php +++ b/src/Describer/DescriberInterface.php @@ -15,8 +15,5 @@ interface DescriberInterface { - /** - * @return void - */ - public function describe(OpenApi $api); + public function describe(OpenApi $api): void; } diff --git a/src/Describer/ExternalDocDescriber.php b/src/Describer/ExternalDocDescriber.php index cf827187a..9d0d004a5 100644 --- a/src/Describer/ExternalDocDescriber.php +++ b/src/Describer/ExternalDocDescriber.php @@ -32,10 +32,7 @@ public function __construct($externalDoc, bool $overwrite = false) $this->overwrite = $overwrite; } - /** - * @return void - */ - public function describe(OA\OpenApi $api) + public function describe(OA\OpenApi $api): void { $externalDoc = $this->getExternalDoc(); @@ -47,7 +44,7 @@ public function describe(OA\OpenApi $api) /** * @return mixed The external doc */ - private function getExternalDoc() + private function getExternalDoc(): mixed { if (is_callable($this->externalDoc)) { return call_user_func($this->externalDoc); diff --git a/src/Describer/ModelRegistryAwareInterface.php b/src/Describer/ModelRegistryAwareInterface.php index d4dd050af..2dc3b6ee5 100644 --- a/src/Describer/ModelRegistryAwareInterface.php +++ b/src/Describer/ModelRegistryAwareInterface.php @@ -15,8 +15,5 @@ interface ModelRegistryAwareInterface { - /** - * @return void - */ - public function setModelRegistry(ModelRegistry $modelRegistry); + public function setModelRegistry(ModelRegistry $modelRegistry): void; } diff --git a/src/Describer/ModelRegistryAwareTrait.php b/src/Describer/ModelRegistryAwareTrait.php index e88f18a0c..1c88bf8f3 100644 --- a/src/Describer/ModelRegistryAwareTrait.php +++ b/src/Describer/ModelRegistryAwareTrait.php @@ -17,10 +17,7 @@ trait ModelRegistryAwareTrait { private ModelRegistry $modelRegistry; - /** - * @return void - */ - public function setModelRegistry(ModelRegistry $modelRegistry) + public function setModelRegistry(ModelRegistry $modelRegistry): void { $this->modelRegistry = $modelRegistry; } diff --git a/src/ModelDescriber/BazingaHateoasModelDescriber.php b/src/ModelDescriber/BazingaHateoasModelDescriber.php index 078f1ee18..10a54067e 100644 --- a/src/ModelDescriber/BazingaHateoasModelDescriber.php +++ b/src/ModelDescriber/BazingaHateoasModelDescriber.php @@ -35,7 +35,7 @@ public function __construct(MetadataFactoryInterface $factory, JMSModelDescriber $this->JMSModelDescriber = $JMSModelDescriber; } - public function setModelRegistry(ModelRegistry $modelRegistry) + public function setModelRegistry(ModelRegistry $modelRegistry): void { $this->modelRegistry = $modelRegistry; $this->JMSModelDescriber->setModelRegistry($modelRegistry); diff --git a/src/ModelDescriber/EnumModelDescriber.php b/src/ModelDescriber/EnumModelDescriber.php index c75935bfe..f7b8c7781 100644 --- a/src/ModelDescriber/EnumModelDescriber.php +++ b/src/ModelDescriber/EnumModelDescriber.php @@ -19,7 +19,7 @@ class EnumModelDescriber implements ModelDescriberInterface { public const FORCE_NAMES = '_nelmio_enum_force_names'; - public function describe(Model $model, Schema $schema) + public function describe(Model $model, Schema $schema): void { $enumClass = $model->getType()->getClassName(); $forceName = isset($model->getSerializationContext()[self::FORCE_NAMES]) && true === $model->getSerializationContext()[self::FORCE_NAMES]; diff --git a/src/ModelDescriber/FallbackObjectModelDescriber.php b/src/ModelDescriber/FallbackObjectModelDescriber.php index 696bd15fc..ac937a2b5 100644 --- a/src/ModelDescriber/FallbackObjectModelDescriber.php +++ b/src/ModelDescriber/FallbackObjectModelDescriber.php @@ -17,10 +17,7 @@ class FallbackObjectModelDescriber implements ModelDescriberInterface { - /** - * @return void - */ - public function describe(Model $model, OA\Schema $schema) + public function describe(Model $model, OA\Schema $schema): void { } diff --git a/src/ModelDescriber/JMSModelDescriber.php b/src/ModelDescriber/JMSModelDescriber.php index 55c7a0fbf..26363450f 100644 --- a/src/ModelDescriber/JMSModelDescriber.php +++ b/src/ModelDescriber/JMSModelDescriber.php @@ -80,10 +80,7 @@ public function __construct( $this->contextFactory = $contextFactory; } - /** - * @return void - */ - public function describe(Model $model, OA\Schema $schema) + public function describe(Model $model, OA\Schema $schema): void { $className = $model->getType()->getClassName(); $metadata = $this->factory->getMetadataForClass($className); diff --git a/src/ModelDescriber/ModelDescriberInterface.php b/src/ModelDescriber/ModelDescriberInterface.php index 4d6415332..ac1d170da 100644 --- a/src/ModelDescriber/ModelDescriberInterface.php +++ b/src/ModelDescriber/ModelDescriberInterface.php @@ -16,10 +16,7 @@ interface ModelDescriberInterface { - /** - * @return void - */ - public function describe(Model $model, Schema $schema); + public function describe(Model $model, Schema $schema): void; public function supports(Model $model): bool; } diff --git a/src/ModelDescriber/ObjectModelDescriber.php b/src/ModelDescriber/ObjectModelDescriber.php index 6a33149b2..a29fdffbb 100644 --- a/src/ModelDescriber/ObjectModelDescriber.php +++ b/src/ModelDescriber/ObjectModelDescriber.php @@ -59,7 +59,7 @@ public function __construct( $this->classMetadataFactory = $classMetadataFactory; } - public function describe(Model $model, OA\Schema $schema) + public function describe(Model $model, OA\Schema $schema): void { $class = $model->getType()->getClassName(); $schema->_context->class = $class; diff --git a/src/PropertyDescriber/ArrayPropertyDescriber.php b/src/PropertyDescriber/ArrayPropertyDescriber.php index 6dd5b5edc..ae853b66f 100644 --- a/src/PropertyDescriber/ArrayPropertyDescriber.php +++ b/src/PropertyDescriber/ArrayPropertyDescriber.php @@ -25,7 +25,7 @@ final class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelR /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []): void { $property->type = 'array'; /** @var OA\Items $property */ diff --git a/src/PropertyDescriber/BooleanPropertyDescriber.php b/src/PropertyDescriber/BooleanPropertyDescriber.php index 4ce2d96b5..1f6ee0daa 100644 --- a/src/PropertyDescriber/BooleanPropertyDescriber.php +++ b/src/PropertyDescriber/BooleanPropertyDescriber.php @@ -19,7 +19,7 @@ final class BooleanPropertyDescriber implements PropertyDescriberInterface /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []): void { $property->type = 'boolean'; } diff --git a/src/PropertyDescriber/CompoundPropertyDescriber.php b/src/PropertyDescriber/CompoundPropertyDescriber.php index 1457f95bc..b538c2f95 100644 --- a/src/PropertyDescriber/CompoundPropertyDescriber.php +++ b/src/PropertyDescriber/CompoundPropertyDescriber.php @@ -25,7 +25,7 @@ final class CompoundPropertyDescriber implements PropertyDescriberInterface, Mod /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []): void { $property->oneOf = Generator::UNDEFINED !== $property->oneOf ? $property->oneOf : []; diff --git a/src/PropertyDescriber/DateTimePropertyDescriber.php b/src/PropertyDescriber/DateTimePropertyDescriber.php index d50ae84dd..81c063ed0 100644 --- a/src/PropertyDescriber/DateTimePropertyDescriber.php +++ b/src/PropertyDescriber/DateTimePropertyDescriber.php @@ -19,7 +19,7 @@ final class DateTimePropertyDescriber implements PropertyDescriberInterface /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []): void { $property->type = 'string'; $property->format = 'date-time'; diff --git a/src/PropertyDescriber/DictionaryPropertyDescriber.php b/src/PropertyDescriber/DictionaryPropertyDescriber.php index 18785d174..454469c6f 100644 --- a/src/PropertyDescriber/DictionaryPropertyDescriber.php +++ b/src/PropertyDescriber/DictionaryPropertyDescriber.php @@ -25,7 +25,7 @@ final class DictionaryPropertyDescriber implements PropertyDescriberInterface, M /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []): void { $property->type = 'object'; /** @var OA\AdditionalProperties $additionalProperties */ diff --git a/src/PropertyDescriber/FloatPropertyDescriber.php b/src/PropertyDescriber/FloatPropertyDescriber.php index 0ce1fbf39..ad08aeaa0 100644 --- a/src/PropertyDescriber/FloatPropertyDescriber.php +++ b/src/PropertyDescriber/FloatPropertyDescriber.php @@ -19,7 +19,7 @@ final class FloatPropertyDescriber implements PropertyDescriberInterface /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []): void { $property->type = 'number'; $property->format = 'float'; diff --git a/src/PropertyDescriber/IntegerPropertyDescriber.php b/src/PropertyDescriber/IntegerPropertyDescriber.php index 1a57482d8..cd1a5b03f 100644 --- a/src/PropertyDescriber/IntegerPropertyDescriber.php +++ b/src/PropertyDescriber/IntegerPropertyDescriber.php @@ -19,7 +19,7 @@ final class IntegerPropertyDescriber implements PropertyDescriberInterface /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []): void { $property->type = 'integer'; } diff --git a/src/PropertyDescriber/NullablePropertyDescriber.php b/src/PropertyDescriber/NullablePropertyDescriber.php index 332983b8e..1732e8138 100644 --- a/src/PropertyDescriber/NullablePropertyDescriber.php +++ b/src/PropertyDescriber/NullablePropertyDescriber.php @@ -21,7 +21,7 @@ final class NullablePropertyDescriber implements PropertyDescriberInterface, Pro /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []): void { if (Generator::UNDEFINED === $property->nullable) { $property->nullable = true; diff --git a/src/PropertyDescriber/ObjectPropertyDescriber.php b/src/PropertyDescriber/ObjectPropertyDescriber.php index 1c3a3ad8b..5ece1385e 100644 --- a/src/PropertyDescriber/ObjectPropertyDescriber.php +++ b/src/PropertyDescriber/ObjectPropertyDescriber.php @@ -25,7 +25,7 @@ final class ObjectPropertyDescriber implements PropertyDescriberInterface, Model /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []): void { $type = new Type( $types[0]->getBuiltinType(), diff --git a/src/PropertyDescriber/PropertyDescriberInterface.php b/src/PropertyDescriber/PropertyDescriberInterface.php index 2a3c3ff4a..676f2c995 100644 --- a/src/PropertyDescriber/PropertyDescriberInterface.php +++ b/src/PropertyDescriber/PropertyDescriberInterface.php @@ -19,10 +19,8 @@ interface PropertyDescriberInterface /** * @param Type[] $types * @param array $context Context options for describing the property - * - * @return void */ - public function describe(array $types, Schema $property, array $context = []); + public function describe(array $types, Schema $property, array $context = []): void; /** * @param Type[] $types diff --git a/src/PropertyDescriber/StringPropertyDescriber.php b/src/PropertyDescriber/StringPropertyDescriber.php index 0ac285392..ea82f0f9d 100644 --- a/src/PropertyDescriber/StringPropertyDescriber.php +++ b/src/PropertyDescriber/StringPropertyDescriber.php @@ -19,7 +19,7 @@ final class StringPropertyDescriber implements PropertyDescriberInterface /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []): void { $property->type = 'string'; } diff --git a/src/PropertyDescriber/UuidPropertyDescriber.php b/src/PropertyDescriber/UuidPropertyDescriber.php index e57f69f3e..f8294be95 100644 --- a/src/PropertyDescriber/UuidPropertyDescriber.php +++ b/src/PropertyDescriber/UuidPropertyDescriber.php @@ -20,7 +20,7 @@ final class UuidPropertyDescriber implements PropertyDescriberInterface /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []): void { $property->type = 'string'; $property->format = 'uuid'; diff --git a/src/RouteDescriber/RouteDescriberInterface.php b/src/RouteDescriber/RouteDescriberInterface.php index 19ad2e036..baf136b77 100644 --- a/src/RouteDescriber/RouteDescriberInterface.php +++ b/src/RouteDescriber/RouteDescriberInterface.php @@ -16,8 +16,5 @@ interface RouteDescriberInterface { - /** - * @return void - */ - public function describe(OpenApi $api, Route $route, \ReflectionMethod $reflectionMethod); + public function describe(OpenApi $api, Route $route, \ReflectionMethod $reflectionMethod): void; } diff --git a/tests/Functional/ModelDescriber/VirtualTypeClassDoesNotExistsHandlerDefinedDescriber.php b/tests/Functional/ModelDescriber/VirtualTypeClassDoesNotExistsHandlerDefinedDescriber.php index d2c40f757..dcbc34989 100644 --- a/tests/Functional/ModelDescriber/VirtualTypeClassDoesNotExistsHandlerDefinedDescriber.php +++ b/tests/Functional/ModelDescriber/VirtualTypeClassDoesNotExistsHandlerDefinedDescriber.php @@ -19,7 +19,7 @@ class VirtualTypeClassDoesNotExistsHandlerDefinedDescriber implements ModelDescriberInterface { - public function describe(Model $model, OA\Schema $schema) + public function describe(Model $model, OA\Schema $schema): void { $schema->type = 'object'; $property = Util::getProperty($schema, 'custom_prop');