From cd85ef0ab48c161174b80b0a68d6edbe389d3214 Mon Sep 17 00:00:00 2001 From: DjordyKoert Date: Tue, 2 Jan 2024 17:23:14 +0100 Subject: [PATCH] run cs-fix --- Annotation/Model.php | 5 +- Annotation/Security.php | 3 +- ApiDocGenerator.php | 4 +- Controller/YamlDocumentationController.php | 3 +- DependencyInjection/NelmioApiDocExtension.php | 6 -- Describer/OpenApiPhpDescriber.php | 8 +-- Model/Model.php | 2 +- Model/ModelRegistry.php | 2 +- .../Annotations/AnnotationsReader.php | 2 +- .../Annotations/OpenApiAnnotationsReader.php | 4 +- .../BazingaHateoasModelDescriber.php | 6 -- ModelDescriber/EnumModelDescriber.php | 9 +++ ModelDescriber/FormModelDescriber.php | 6 +- ModelDescriber/JMSModelDescriber.php | 8 +-- ModelDescriber/ObjectModelDescriber.php | 4 +- NelmioApiDocBundle.php | 3 - OpenApiPhp/ModelRegister.php | 4 +- OpenApiPhp/Util.php | 32 ++++----- PropertyDescriber/ArrayPropertyDescriber.php | 2 +- .../BooleanPropertyDescriber.php | 2 +- .../CompoundPropertyDescriber.php | 2 +- .../DateTimePropertyDescriber.php | 2 +- PropertyDescriber/FloatPropertyDescriber.php | 2 +- .../IntegerPropertyDescriber.php | 2 +- PropertyDescriber/ObjectPropertyDescriber.php | 2 +- .../PropertyDescriberInterface.php | 2 +- PropertyDescriber/StringPropertyDescriber.php | 2 +- Render/Html/HtmlOpenApiRenderer.php | 3 +- RouteDescriber/PhpDocDescriber.php | 2 +- RouteDescriber/RouteMetadataDescriber.php | 3 +- Tests/Functional/BazingaFunctionalTest.php | 6 +- Tests/Functional/Entity/Article81.php | 9 +++ Tests/Functional/Entity/ArticleInterface.php | 9 +++ Tests/Functional/Entity/ArticleType81.php | 9 +++ .../Entity/ArticleType81IntBacked.php | 9 +++ .../Entity/ArticleType81NotBacked.php | 9 +++ Tests/Functional/Entity/CustomDateTime.php | 3 +- .../Entity/EntityThroughNameConverter.php | 9 +++ .../Entity/EntityWithAlternateType80.php | 8 +-- .../Entity/EntityWithAlternateType81.php | 8 +-- Tests/Functional/Entity/User.php | 4 +- Tests/Functional/Entity/VirtualProperty80.php | 3 +- Tests/Functional/Entity/VirtualProperty81.php | 3 +- Tests/Functional/FunctionalTest.php | 9 ++- .../ModelDescriber/NameConverter.php | 13 +++- Tests/Functional/TestKernel.php | 16 ++--- Tests/Helper.php | 9 +++ Tests/Model/ModelRegistryTest.php | 3 +- .../Annotations/AnnotationReaderTest.php | 8 +-- .../Annotations/Fixture/CompoundStub.php | 9 +++ .../Fixture/CompoundValidationRule.php | 12 +++- .../SymfonyConstraintAnnotationReaderTest.php | 59 ++++++++------- .../SelfDescribingModelDescriberTest.php | 3 +- Tests/Render/RenderOpenApiTest.php | 5 +- Tests/RouteDescriber/FosRestDescriberTest.php | 3 +- .../RouteMetadataDescriberTest.php | 9 ++- .../FilteredRouteCollectionBuilderTest.php | 15 ++-- Tests/SwaggerPhp/UtilTest.php | 72 ++++++++----------- Tests/Util/ControllerReflectorTest.php | 14 +++- Util/SetsContextTrait.php | 9 +++ 60 files changed, 272 insertions(+), 222 deletions(-) diff --git a/Annotation/Model.php b/Annotation/Model.php index 2c24ea20f..7143cdf7b 100644 --- a/Annotation/Model.php +++ b/Annotation/Model.php @@ -21,7 +21,6 @@ #[\Attribute(\Attribute::TARGET_METHOD)] final class Model extends Attachable { - /** {@inheritdoc} */ public static $_types = [ 'type' => 'string', 'groups' => '[string]', @@ -60,8 +59,8 @@ final class Model extends Attachable public function __construct( array $properties = [], string $type = Generator::UNDEFINED, - array $groups = null, - array $options = null, + ?array $groups = null, + ?array $options = null, array $serializationContext = [] ) { parent::__construct($properties + [ diff --git a/Annotation/Security.php b/Annotation/Security.php index c3d34774f..c6a4b8716 100644 --- a/Annotation/Security.php +++ b/Annotation/Security.php @@ -19,7 +19,6 @@ #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] class Security extends AbstractAnnotation { - /** {@inheritdoc} */ public static $_types = [ 'name' => 'string', 'scopes' => '[string]', @@ -36,7 +35,7 @@ class Security extends AbstractAnnotation public function __construct( array $properties = [], - string $name = null, + ?string $name = null, array $scopes = [] ) { parent::__construct($properties + [ diff --git a/ApiDocGenerator.php b/ApiDocGenerator.php index 2c383c90f..bba6a5907 100644 --- a/ApiDocGenerator.php +++ b/ApiDocGenerator.php @@ -51,7 +51,7 @@ final class ApiDocGenerator /** * @var ?string */ - private $openApiVersion = null; + private $openApiVersion; /** @var Generator */ private $generator; @@ -60,7 +60,7 @@ final class ApiDocGenerator * @param DescriberInterface[]|iterable $describers * @param ModelDescriberInterface[]|iterable $modelDescribers */ - public function __construct($describers, $modelDescribers, CacheItemPoolInterface $cacheItemPool = null, string $cacheItemId = null, Generator $generator = null) + public function __construct($describers, $modelDescribers, ?CacheItemPoolInterface $cacheItemPool = null, ?string $cacheItemId = null, ?Generator $generator = null) { $this->describers = $describers; $this->modelDescribers = $modelDescribers; diff --git a/Controller/YamlDocumentationController.php b/Controller/YamlDocumentationController.php index 04f525889..7858b0e6a 100644 --- a/Controller/YamlDocumentationController.php +++ b/Controller/YamlDocumentationController.php @@ -11,7 +11,6 @@ namespace Nelmio\ApiDocBundle\Controller; -use InvalidArgumentException; use Nelmio\ApiDocBundle\Render\RenderOpenApi; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -36,7 +35,7 @@ public function __invoke(Request $request, string $area = 'default') ); return $response->setCharset('UTF-8'); - } catch (InvalidArgumentException $e) { + } catch (\InvalidArgumentException $e) { throw new BadRequestHttpException(sprintf('Area "%s" is not supported as it isn\'t defined in config.', $area)); } } diff --git a/DependencyInjection/NelmioApiDocExtension.php b/DependencyInjection/NelmioApiDocExtension.php index d3a300668..8f41c00db 100644 --- a/DependencyInjection/NelmioApiDocExtension.php +++ b/DependencyInjection/NelmioApiDocExtension.php @@ -37,9 +37,6 @@ final class NelmioApiDocExtension extends Extension implements PrependExtensionInterface { - /** - * {@inheritdoc} - */ public function prepend(ContainerBuilder $container): void { $container->prependExtensionConfig('framework', ['property_info' => ['enabled' => true]]); @@ -52,9 +49,6 @@ public function prepend(ContainerBuilder $container): void } } - /** - * {@inheritdoc} - */ public function load(array $configs, ContainerBuilder $container): void { $config = $this->processConfiguration(new Configuration(), $configs); diff --git a/Describer/OpenApiPhpDescriber.php b/Describer/OpenApiPhpDescriber.php index 08be91b7f..a55356c82 100644 --- a/Describer/OpenApiPhpDescriber.php +++ b/Describer/OpenApiPhpDescriber.php @@ -141,10 +141,10 @@ public function describe(OA\OpenApi $api) } if ( - !$annotation instanceof OA\Response && - !$annotation instanceof OA\RequestBody && - !$annotation instanceof OA\Parameter && - !$annotation instanceof OA\ExternalDocumentation + !$annotation instanceof OA\Response + && !$annotation instanceof OA\RequestBody + && !$annotation instanceof OA\Parameter + && !$annotation instanceof OA\ExternalDocumentation ) { throw new \LogicException(sprintf('Using the annotation "%s" as a root annotation in "%s::%s()" is not allowed.', get_class($annotation), $method->getDeclaringClass()->name, $method->name)); } diff --git a/Model/Model.php b/Model/Model.php index 34d3d460c..c9464640d 100644 --- a/Model/Model.php +++ b/Model/Model.php @@ -24,7 +24,7 @@ final class Model /** * @param string[]|null $groups */ - public function __construct(Type $type, array $groups = null, array $options = null, array $serializationContext = []) + public function __construct(Type $type, ?array $groups = null, ?array $options = null, array $serializationContext = []) { $this->type = $type; $this->options = $options; diff --git a/Model/ModelRegistry.php b/Model/ModelRegistry.php index 3d1fab137..bafc0da19 100644 --- a/Model/ModelRegistry.php +++ b/Model/ModelRegistry.php @@ -56,7 +56,7 @@ final class ModelRegistry private OA\OpenApi $api; /** - * @param ModelDescriberInterface[]|iterable $modelDescribers + * @param ModelDescriberInterface[]|iterable $modelDescribers * @param array $alternativeNames * * @internal diff --git a/ModelDescriber/Annotations/AnnotationsReader.php b/ModelDescriber/Annotations/AnnotationsReader.php index f13177f89..fbf6466bc 100644 --- a/ModelDescriber/Annotations/AnnotationsReader.php +++ b/ModelDescriber/Annotations/AnnotationsReader.php @@ -54,7 +54,7 @@ public function getPropertyName($reflection, string $default): string return $this->openApiAnnotationsReader->getPropertyName($reflection, $default); } - public function updateProperty($reflection, OA\Property $property, array $serializationGroups = null): void + public function updateProperty($reflection, OA\Property $property, ?array $serializationGroups = null): void { $this->openApiAnnotationsReader->updateProperty($reflection, $property, $serializationGroups); $this->phpDocReader->updateProperty($reflection, $property); diff --git a/ModelDescriber/Annotations/OpenApiAnnotationsReader.php b/ModelDescriber/Annotations/OpenApiAnnotationsReader.php index 2511d424e..8c5f1c068 100644 --- a/ModelDescriber/Annotations/OpenApiAnnotationsReader.php +++ b/ModelDescriber/Annotations/OpenApiAnnotationsReader.php @@ -64,7 +64,7 @@ public function getPropertyName($reflection, string $default): string return Generator::UNDEFINED !== $oaProperty->property ? $oaProperty->property : $default; } - public function updateProperty($reflection, OA\Property $property, array $serializationGroups = null): void + public function updateProperty($reflection, OA\Property $property, ?array $serializationGroups = null): void { /** @var OA\Property|null $oaProperty */ if (!$oaProperty = $this->getAnnotation($property->_context, $reflection, OA\Property::class)) { @@ -83,8 +83,6 @@ public function updateProperty($reflection, OA\Property $property, array $serial /** * @param \ReflectionClass|\ReflectionProperty|\ReflectionMethod $reflection - * - * @return mixed */ private function getAnnotation(Context $parentContext, $reflection, string $className) { diff --git a/ModelDescriber/BazingaHateoasModelDescriber.php b/ModelDescriber/BazingaHateoasModelDescriber.php index 27e847150..0d38fe31c 100644 --- a/ModelDescriber/BazingaHateoasModelDescriber.php +++ b/ModelDescriber/BazingaHateoasModelDescriber.php @@ -41,9 +41,6 @@ public function setModelRegistry(ModelRegistry $modelRegistry) $this->JMSModelDescriber->setModelRegistry($modelRegistry); } - /** - * {@inheritdoc} - */ public function describe(Model $model, OA\Schema $schema): void { $this->JMSModelDescriber->describe($model, $schema); @@ -106,9 +103,6 @@ private function getHateoasMetadata(Model $model) return null; } - /** - * {@inheritdoc} - */ public function supports(Model $model): bool { return $this->JMSModelDescriber->supports($model) || null !== $this->getHateoasMetadata($model); diff --git a/ModelDescriber/EnumModelDescriber.php b/ModelDescriber/EnumModelDescriber.php index 93ad24fb1..1aae41ef1 100644 --- a/ModelDescriber/EnumModelDescriber.php +++ b/ModelDescriber/EnumModelDescriber.php @@ -1,5 +1,14 @@ formFactory = $formFactory; diff --git a/ModelDescriber/JMSModelDescriber.php b/ModelDescriber/JMSModelDescriber.php index ec074dafe..fe822965c 100644 --- a/ModelDescriber/JMSModelDescriber.php +++ b/ModelDescriber/JMSModelDescriber.php @@ -83,9 +83,6 @@ public function __construct( $this->contextFactory = $contextFactory; } - /** - * {@inheritdoc} - */ public function describe(Model $model, OA\Schema $schema) { $className = $model->getType()->getClassName(); @@ -211,7 +208,7 @@ public function getSerializationContext(Model $model): SerializationContext return $context; } - private function computeGroups(Context $context, array $type = null) + private function computeGroups(Context $context, ?array $type = null) { if (null === $type || true !== $this->propertyTypeUsesGroups($type)) { return null; @@ -230,9 +227,6 @@ private function computeGroups(Context $context, array $type = null) return $groups; } - /** - * {@inheritdoc} - */ public function supports(Model $model): bool { $className = $model->getType()->getClassName(); diff --git a/ModelDescriber/ObjectModelDescriber.php b/ModelDescriber/ObjectModelDescriber.php index 1c124fb50..c28e6131e 100644 --- a/ModelDescriber/ObjectModelDescriber.php +++ b/ModelDescriber/ObjectModelDescriber.php @@ -49,9 +49,9 @@ public function __construct( ?Reader $reader, iterable $propertyDescribers, array $mediaTypes, - NameConverterInterface $nameConverter = null, + ?NameConverterInterface $nameConverter = null, bool $useValidationGroups = false, - ClassMetadataFactoryInterface $classMetadataFactory = null + ?ClassMetadataFactoryInterface $classMetadataFactory = null ) { $this->propertyInfo = $propertyInfo; $this->doctrineReader = $reader; diff --git a/NelmioApiDocBundle.php b/NelmioApiDocBundle.php index fad44e2c6..67db2a661 100644 --- a/NelmioApiDocBundle.php +++ b/NelmioApiDocBundle.php @@ -20,9 +20,6 @@ final class NelmioApiDocBundle extends Bundle { - /** - * {@inheritdoc} - */ public function build(ContainerBuilder $container): void { $container->addCompilerPass(new ConfigurationPass()); diff --git a/OpenApiPhp/ModelRegister.php b/OpenApiPhp/ModelRegister.php index 6d12eee72..765e1e7b0 100644 --- a/OpenApiPhp/ModelRegister.php +++ b/OpenApiPhp/ModelRegister.php @@ -37,7 +37,7 @@ public function __construct(ModelRegistry $modelRegistry, array $mediaTypes) $this->mediaTypes = $mediaTypes; } - public function __invoke(Analysis $analysis, array $parentGroups = null) + public function __invoke(Analysis $analysis, ?array $parentGroups = null) { foreach ($analysis->annotations as $annotation) { // @Model using the ref field @@ -105,7 +105,7 @@ public function __invoke(Analysis $analysis, array $parentGroups = null) } } - private function getGroups(ModelAnnotation $model, array $parentGroups = null): ?array + private function getGroups(ModelAnnotation $model, ?array $parentGroups = null): ?array { if (null === $model->groups) { return $parentGroups; diff --git a/OpenApiPhp/Util.php b/OpenApiPhp/Util.php index dc0db90e8..ce8e02270 100644 --- a/OpenApiPhp/Util.php +++ b/OpenApiPhp/Util.php @@ -26,26 +26,26 @@ * of swagger Annotation classes with the following convenience methods * to get or create the respective Annotation instances if not found * - * @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::getPath() - * @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::getSchema() - * @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::getProperty() - * @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::getOperation() - * @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::getOperationParameter() + * @see Util::getPath() + * @see Util::getSchema() + * @see Util::getProperty() + * @see Util::getOperation() + * @see Util::getOperationParameter() * * which in turn get or create the Annotation instances through the following more general methods - * @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::getChild() - * @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::getCollectionItem() - * @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::getIndexedCollectionItem() + * @see Util::getChild() + * @see Util::getCollectionItem() + * @see Util::getIndexedCollectionItem() * * which then searches for an existing Annotation through - * @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::searchCollectionItem() - * @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::searchIndexedCollectionItem() + * @see Util::searchCollectionItem() + * @see Util::searchIndexedCollectionItem() * * and if not found the Annotation creates it through - * @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::createCollectionItem() - * @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::createContext() + * @see Util::createCollectionItem() + * @see Util::createContext() * - * The merge method @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::merge() has the main purpose to be able + * The merge method @see Util::merge() has the main purpose to be able * to merge properties from an deeply nested array of Annotation properties in the structure of a * generated swagger json decoded array. */ @@ -214,7 +214,6 @@ public static function getCollectionItem(OA\AbstractAnnotation $parent, $class, * @see OA\AbstractAnnotation::$_nested * * @param string $class - * @param mixed $value */ public static function getIndexedCollectionItem(OA\AbstractAnnotation $parent, $class, $value): OA\AbstractAnnotation { @@ -259,7 +258,6 @@ public static function searchCollectionItem(array $collection, array $properties * Search for an Annotation within the $collection that has its member $index set to $value. * * @param string $member - * @param mixed $value * * @return false|int|string */ @@ -312,7 +310,7 @@ public static function createChild(OA\AbstractAnnotation $parent, $class, array * * @see Context */ - public static function createContext(array $properties = [], Context $parent = null): Context + public static function createContext(array $properties = [], ?Context $parent = null): Context { return new Context($properties, $parent); } @@ -322,7 +320,7 @@ public static function createContext(array $properties = [], Context $parent = n * * @see Context */ - public static function createWeakContext(Context $parent = null, array $additionalProperties = []): Context + public static function createWeakContext(?Context $parent = null, array $additionalProperties = []): Context { $propsToCopy = [ 'version', diff --git a/PropertyDescriber/ArrayPropertyDescriber.php b/PropertyDescriber/ArrayPropertyDescriber.php index 46145f312..f81539cdf 100644 --- a/PropertyDescriber/ArrayPropertyDescriber.php +++ b/PropertyDescriber/ArrayPropertyDescriber.php @@ -30,7 +30,7 @@ public function __construct(iterable $propertyDescribers = []) $this->propertyDescribers = $propertyDescribers; } - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null) { // BC layer for symfony < 5.3 $type = method_exists($types[0], 'getCollectionValueTypes') ? diff --git a/PropertyDescriber/BooleanPropertyDescriber.php b/PropertyDescriber/BooleanPropertyDescriber.php index 9a84ffbc0..300d9da3c 100644 --- a/PropertyDescriber/BooleanPropertyDescriber.php +++ b/PropertyDescriber/BooleanPropertyDescriber.php @@ -18,7 +18,7 @@ class BooleanPropertyDescriber implements PropertyDescriberInterface { use NullablePropertyTrait; - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null) { $property->type = 'boolean'; $this->setNullableProperty($types[0], $property, $schema); diff --git a/PropertyDescriber/CompoundPropertyDescriber.php b/PropertyDescriber/CompoundPropertyDescriber.php index 03b879a08..c5362a76e 100644 --- a/PropertyDescriber/CompoundPropertyDescriber.php +++ b/PropertyDescriber/CompoundPropertyDescriber.php @@ -29,7 +29,7 @@ public function __construct(iterable $propertyDescribers) $this->propertyDescribers = $propertyDescribers; } - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null) { $property->oneOf = Generator::UNDEFINED !== $property->oneOf ? $property->oneOf : []; diff --git a/PropertyDescriber/DateTimePropertyDescriber.php b/PropertyDescriber/DateTimePropertyDescriber.php index 7609c34bc..9d577d65c 100644 --- a/PropertyDescriber/DateTimePropertyDescriber.php +++ b/PropertyDescriber/DateTimePropertyDescriber.php @@ -18,7 +18,7 @@ class DateTimePropertyDescriber implements PropertyDescriberInterface { use NullablePropertyTrait; - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null) { $property->type = 'string'; $property->format = 'date-time'; diff --git a/PropertyDescriber/FloatPropertyDescriber.php b/PropertyDescriber/FloatPropertyDescriber.php index 39fb71e23..441454c74 100644 --- a/PropertyDescriber/FloatPropertyDescriber.php +++ b/PropertyDescriber/FloatPropertyDescriber.php @@ -18,7 +18,7 @@ class FloatPropertyDescriber implements PropertyDescriberInterface { use NullablePropertyTrait; - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null) { $property->type = 'number'; $property->format = 'float'; diff --git a/PropertyDescriber/IntegerPropertyDescriber.php b/PropertyDescriber/IntegerPropertyDescriber.php index 09453bcda..db07a763f 100644 --- a/PropertyDescriber/IntegerPropertyDescriber.php +++ b/PropertyDescriber/IntegerPropertyDescriber.php @@ -18,7 +18,7 @@ class IntegerPropertyDescriber implements PropertyDescriberInterface { use NullablePropertyTrait; - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null) { $property->type = 'integer'; $this->setNullableProperty($types[0], $property, $schema); diff --git a/PropertyDescriber/ObjectPropertyDescriber.php b/PropertyDescriber/ObjectPropertyDescriber.php index db9ea2bb0..079e3aae4 100644 --- a/PropertyDescriber/ObjectPropertyDescriber.php +++ b/PropertyDescriber/ObjectPropertyDescriber.php @@ -23,7 +23,7 @@ class ObjectPropertyDescriber implements PropertyDescriberInterface, ModelRegist { use ModelRegistryAwareTrait; - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null) { $type = new Type( $types[0]->getBuiltinType(), diff --git a/PropertyDescriber/PropertyDescriberInterface.php b/PropertyDescriber/PropertyDescriberInterface.php index b434d24f6..f3c4e8c31 100644 --- a/PropertyDescriber/PropertyDescriberInterface.php +++ b/PropertyDescriber/PropertyDescriberInterface.php @@ -20,7 +20,7 @@ interface PropertyDescriberInterface * @param Type[] $types * @param Schema $schema Allows to make changes inside of the schema (e.g. adding required fields) */ - public function describe(array $types, Schema $property, array $groups = null /* , ?Schema $schema = null */); + public function describe(array $types, Schema $property, ?array $groups = null /* , ?Schema $schema = null */); /** * @param Type[] $types diff --git a/PropertyDescriber/StringPropertyDescriber.php b/PropertyDescriber/StringPropertyDescriber.php index 3f0589d27..6493371cc 100644 --- a/PropertyDescriber/StringPropertyDescriber.php +++ b/PropertyDescriber/StringPropertyDescriber.php @@ -18,7 +18,7 @@ class StringPropertyDescriber implements PropertyDescriberInterface { use NullablePropertyTrait; - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null) { $property->type = 'string'; $this->setNullableProperty($types[0], $property, $schema); diff --git a/Render/Html/HtmlOpenApiRenderer.php b/Render/Html/HtmlOpenApiRenderer.php index 828b48736..b8a067849 100644 --- a/Render/Html/HtmlOpenApiRenderer.php +++ b/Render/Html/HtmlOpenApiRenderer.php @@ -11,7 +11,6 @@ namespace Nelmio\ApiDocBundle\Render\Html; -use InvalidArgumentException; use Nelmio\ApiDocBundle\Render\OpenApiRenderer; use Nelmio\ApiDocBundle\Render\RenderOpenApi; use OpenApi\Annotations\OpenApi; @@ -28,7 +27,7 @@ class HtmlOpenApiRenderer implements OpenApiRenderer public function __construct($twig) { if (!$twig instanceof \Twig_Environment && !$twig instanceof Environment) { - throw new InvalidArgumentException(sprintf('Providing an instance of "%s" as twig is not supported.', get_class($twig))); + throw new \InvalidArgumentException(sprintf('Providing an instance of "%s" as twig is not supported.', get_class($twig))); } $this->twig = $twig; } diff --git a/RouteDescriber/PhpDocDescriber.php b/RouteDescriber/PhpDocDescriber.php index cf0c72aaf..8a578df86 100644 --- a/RouteDescriber/PhpDocDescriber.php +++ b/RouteDescriber/PhpDocDescriber.php @@ -23,7 +23,7 @@ final class PhpDocDescriber implements RouteDescriberInterface private DocBlockFactoryInterface $docBlockFactory; - public function __construct(DocBlockFactoryInterface $docBlockFactory = null) + public function __construct(?DocBlockFactoryInterface $docBlockFactory = null) { if (null === $docBlockFactory) { $docBlockFactory = DocBlockFactory::createInstance(); diff --git a/RouteDescriber/RouteMetadataDescriber.php b/RouteDescriber/RouteMetadataDescriber.php index 83d80685e..632a26aa6 100644 --- a/RouteDescriber/RouteMetadataDescriber.php +++ b/RouteDescriber/RouteMetadataDescriber.php @@ -11,7 +11,6 @@ namespace Nelmio\ApiDocBundle\RouteDescriber; -use LogicException; use Nelmio\ApiDocBundle\OpenApiPhp\Util; use OpenApi\Annotations as OA; use OpenApi\Generator; @@ -44,7 +43,7 @@ public function describe(OA\OpenApi $api, Route $route, \ReflectionMethod $refle $parameter = $existingParams[$paramId] ?? null; if (null !== $parameter) { if (!$parameter->required || Generator::UNDEFINED === $parameter->required) { - throw new LogicException(\sprintf('Global parameter "%s" is used as part of route "%s" and must be set as "required"', $pathVariable, $route->getPath())); + throw new \LogicException(\sprintf('Global parameter "%s" is used as part of route "%s" and must be set as "required"', $pathVariable, $route->getPath())); } continue; diff --git a/Tests/Functional/BazingaFunctionalTest.php b/Tests/Functional/BazingaFunctionalTest.php index e09e08424..92df0d95a 100644 --- a/Tests/Functional/BazingaFunctionalTest.php +++ b/Tests/Functional/BazingaFunctionalTest.php @@ -12,8 +12,6 @@ namespace Nelmio\ApiDocBundle\Tests\Functional; use Hateoas\Configuration\Embedded; -use ReflectionException; -use ReflectionMethod; use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\HttpKernel\KernelInterface; @@ -105,8 +103,8 @@ public function testWithGroup() public function testWithType() { try { - new ReflectionMethod(Embedded::class, 'getType'); - } catch (ReflectionException $e) { + new \ReflectionMethod(Embedded::class, 'getType'); + } catch (\ReflectionException $e) { $this->markTestSkipped('Typed embedded properties require at least willdurand/hateoas 3.0'); } $this->assertEquals([ diff --git a/Tests/Functional/Entity/Article81.php b/Tests/Functional/Entity/Article81.php index 8a483cd79..6c0016459 100644 --- a/Tests/Functional/Entity/Article81.php +++ b/Tests/Functional/Entity/Article81.php @@ -1,5 +1,14 @@ */ -class CustomDateTime extends DateTime +class CustomDateTime extends \DateTime { /** * @Serializer\Type("string") diff --git a/Tests/Functional/Entity/EntityThroughNameConverter.php b/Tests/Functional/Entity/EntityThroughNameConverter.php index baae90202..6fad4d354 100644 --- a/Tests/Functional/Entity/EntityThroughNameConverter.php +++ b/Tests/Functional/Entity/EntityThroughNameConverter.php @@ -1,5 +1,14 @@ ['/api/article/{id}']; } - if (PHP_VERSION_ID >= 80100) { + if (\PHP_VERSION_ID >= 80100) { yield 'Attributes' => ['/api/article_attributes/{id}']; } } @@ -390,7 +389,7 @@ public function provideSecurityRoute(): iterable { yield 'Annotations' => ['/api/security']; - if (PHP_VERSION_ID >= 80100) { + if (\PHP_VERSION_ID >= 80100) { yield 'Attributes' => ['/api/security_attributes']; } } @@ -408,14 +407,14 @@ public function provideSecurityOverrideRoute(): iterable { yield 'Annotations' => ['/api/securityOverride']; - if (PHP_VERSION_ID >= 80100) { + if (\PHP_VERSION_ID >= 80100) { yield 'Attributes' => ['/api/security_override_attributes']; } } public function testInlinePHP81Parameters() { - if (PHP_VERSION_ID < 80100) { + if (\PHP_VERSION_ID < 80100) { $this->markTestSkipped('Attributes require PHP 8.1'); } diff --git a/Tests/Functional/ModelDescriber/NameConverter.php b/Tests/Functional/ModelDescriber/NameConverter.php index cd98652e8..5a397d1c8 100644 --- a/Tests/Functional/ModelDescriber/NameConverter.php +++ b/Tests/Functional/ModelDescriber/NameConverter.php @@ -2,6 +2,15 @@ declare(strict_types=1); +/* + * This file is part of the NelmioApiDocBundle package. + * + * (c) Nelmio + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Nelmio\ApiDocBundle\Tests\Functional\ModelDescriber; use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface; @@ -19,7 +28,7 @@ public function __construct(MetadataAwareNameConverter $inner) $this->inner = $inner; } - public function normalize(string $propertyName, string $class = null, string $format = null, array $context = []): string + public function normalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string { if (!isset($context['secret_name_converter_value'])) { return $this->inner->normalize($propertyName, $class, $format, $context); @@ -28,7 +37,7 @@ public function normalize(string $propertyName, string $class = null, string $fo return 'name_converter_context_'.$propertyName; } - public function denormalize(string $propertyName, string $class = null, string $format = null, array $context = []): string + public function denormalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string { throw new \RuntimeException('Was not expected to be called'); } diff --git a/Tests/Functional/TestKernel.php b/Tests/Functional/TestKernel.php index f90cb8298..1b5754542 100644 --- a/Tests/Functional/TestKernel.php +++ b/Tests/Functional/TestKernel.php @@ -26,8 +26,6 @@ use Nelmio\ApiDocBundle\Tests\Functional\Entity\SymfonyConstraintsWithValidationGroups; use Nelmio\ApiDocBundle\Tests\Functional\ModelDescriber\NameConverter; use Nelmio\ApiDocBundle\Tests\Functional\ModelDescriber\VirtualTypeClassDoesNotExistsHandlerDefinedDescriber; -use ReflectionException; -use ReflectionMethod; use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle; use Symfony\Bundle\FrameworkBundle\Command\CachePoolClearCommand; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; @@ -43,11 +41,11 @@ class TestKernel extends Kernel { use MicroKernelTrait; - const USE_JMS = 1; - const USE_BAZINGA = 2; - const USE_FOSREST = 3; - const ERROR_ARRAY_ITEMS = 4; - const USE_VALIDATION_GROUPS = 8; + public const USE_JMS = 1; + public const USE_BAZINGA = 2; + public const USE_FOSREST = 3; + public const ERROR_ARRAY_ITEMS = 4; + public const USE_VALIDATION_GROUPS = 8; private $flags; @@ -107,9 +105,9 @@ protected function configureRoutes($routes) $this->import($routes, __DIR__.'/Controller/BazingaController.php', '/', self::isAnnotationsAvailable() ? 'annotation' : 'attribute'); try { - new ReflectionMethod(Embedded::class, 'getType'); + new \ReflectionMethod(Embedded::class, 'getType'); $this->import($routes, __DIR__.'/Controller/BazingaTypedController.php', '/', self::isAnnotationsAvailable() ? 'annotation' : 'attribute'); - } catch (ReflectionException $e) { + } catch (\ReflectionException $e) { } } diff --git a/Tests/Helper.php b/Tests/Helper.php index 10f94d032..5c56ca82f 100644 --- a/Tests/Helper.php +++ b/Tests/Helper.php @@ -2,6 +2,15 @@ declare(strict_types=1); +/* + * This file is part of the NelmioApiDocBundle package. + * + * (c) Nelmio + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Nelmio\ApiDocBundle\Tests; use PackageVersions\Versions; diff --git a/Tests/Model/ModelRegistryTest.php b/Tests/Model/ModelRegistryTest.php index ddb2c8115..59f559d7b 100644 --- a/Tests/Model/ModelRegistryTest.php +++ b/Tests/Model/ModelRegistryTest.php @@ -17,7 +17,6 @@ use OpenApi\Context; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; -use ReflectionClass; use Symfony\Component\PropertyInfo\Type; class ModelRegistryTest extends TestCase @@ -104,7 +103,7 @@ public function provideNameCollisionsTypes() public function testNameCollisionsAreLoggedWithAlternativeNames() { - $ref = new ReflectionClass(self::class); + $ref = new \ReflectionClass(self::class); $alternativeNames = [ $ref->getShortName() => [ 'type' => $ref->getName(), diff --git a/Tests/ModelDescriber/Annotations/AnnotationReaderTest.php b/Tests/ModelDescriber/Annotations/AnnotationReaderTest.php index 505d7fe7b..4aedd3798 100644 --- a/Tests/ModelDescriber/Annotations/AnnotationReaderTest.php +++ b/Tests/ModelDescriber/Annotations/AnnotationReaderTest.php @@ -20,8 +20,6 @@ use OpenApi\Context; use OpenApi\Generator; use PHPUnit\Framework\TestCase; -use ReflectionProperty; -use const PHP_VERSION_ID; class AnnotationReaderTest extends TestCase { @@ -46,8 +44,8 @@ class_exists(AnnotationReader::class) ? new AnnotationReader() : null, $registry, ['json'] ); - $symfonyConstraintAnnotationReader->updateProperty(new ReflectionProperty($entity, 'property1'), $schema->properties[0]); - $symfonyConstraintAnnotationReader->updateProperty(new ReflectionProperty($entity, 'property2'), $schema->properties[1]); + $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property2'), $schema->properties[1]); $this->assertEquals($schema->properties[0]->example, 1); $this->assertEquals($schema->properties[0]->description, Generator::UNDEFINED); @@ -69,7 +67,7 @@ public function provideProperty(): iterable private $property2; }]; - if (PHP_VERSION_ID >= 80100) { + if (\PHP_VERSION_ID >= 80100) { yield 'Attributes' => [new class() { #[OAattr\Property(example: 1)] private $property1; diff --git a/Tests/ModelDescriber/Annotations/Fixture/CompoundStub.php b/Tests/ModelDescriber/Annotations/Fixture/CompoundStub.php index 4167da05b..0feb2f24e 100644 --- a/Tests/ModelDescriber/Annotations/Fixture/CompoundStub.php +++ b/Tests/ModelDescriber/Annotations/Fixture/CompoundStub.php @@ -2,6 +2,15 @@ declare(strict_types=1); +/* + * This file is part of the NelmioApiDocBundle package. + * + * (c) Nelmio + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Nelmio\ApiDocBundle\Tests\ModelDescriber\Annotations\Fixture; class CompoundStub diff --git a/Tests/ModelDescriber/Annotations/Fixture/CompoundValidationRule.php b/Tests/ModelDescriber/Annotations/Fixture/CompoundValidationRule.php index cdfdd1802..8d4645154 100644 --- a/Tests/ModelDescriber/Annotations/Fixture/CompoundValidationRule.php +++ b/Tests/ModelDescriber/Annotations/Fixture/CompoundValidationRule.php @@ -2,9 +2,17 @@ declare(strict_types=1); +/* + * This file is part of the NelmioApiDocBundle package. + * + * (c) Nelmio + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Nelmio\ApiDocBundle\Tests\ModelDescriber\Annotations\Fixture; -use Attribute; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints\Compound; @@ -15,7 +23,7 @@ class_alias(CompoundStub::class, Compound::class); /** * @Annotation */ -#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] +#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] final class CompoundValidationRule extends Compound { protected function getConstraints(array $options): array diff --git a/Tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php b/Tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php index 152b13a6e..011001705 100644 --- a/Tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php +++ b/Tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php @@ -20,12 +20,9 @@ use OpenApi\Context; use OpenApi\Generator; use PHPUnit\Framework\TestCase; -use ReflectionProperty; use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraints as Assert; -use function property_exists; -use const PHP_VERSION_ID; class SymfonyConstraintAnnotationReaderTest extends TestCase { @@ -73,8 +70,8 @@ public function testUpdatePropertyFix1283() $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader($this->doctrineAnnotations); $symfonyConstraintAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new ReflectionProperty($entity, 'property1'), $schema->properties[0]); - $symfonyConstraintAnnotationReader->updateProperty(new ReflectionProperty($entity, 'property2'), $schema->properties[1]); + $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property2'), $schema->properties[1]); // expect required to be numeric array with sequential keys (not [0 => ..., 2 => ...]) $this->assertEquals($schema->required, ['property1', 'property2']); @@ -87,7 +84,7 @@ public function testUpdatePropertyFix1283() */ public function testOptionalProperty($entity) { - if (!property_exists(Assert\NotBlank::class, 'allowNull')) { + if (!\property_exists(Assert\NotBlank::class, 'allowNull')) { $this->markTestSkipped('NotBlank::allowNull was added in symfony/validator 4.3.'); } @@ -98,8 +95,8 @@ public function testOptionalProperty($entity) $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader($this->doctrineAnnotations); $symfonyConstraintAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new ReflectionProperty($entity, 'property1'), $schema->properties[0]); - $symfonyConstraintAnnotationReader->updateProperty(new ReflectionProperty($entity, 'property2'), $schema->properties[1]); + $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property2'), $schema->properties[1]); // expect required to be numeric array with sequential keys (not [0 => ..., 2 => ...]) $this->assertEquals($schema->required, ['property2']); @@ -125,7 +122,7 @@ public function provideOptionalProperty(): iterable ]; } - if (PHP_VERSION_ID >= 80000) { + if (\PHP_VERSION_ID >= 80000) { yield 'Attributes' => [new class() { #[Assert\NotBlank(allowNull: true)] #[Assert\Length(min: 1)] @@ -149,7 +146,7 @@ public function testAssertChoiceResultsInNumericArray($entity) $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader($this->doctrineAnnotations); $symfonyConstraintAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); // expect enum to be numeric array with sequential keys (not [1 => "active", 2 => "active"]) $this->assertEquals($schema->properties[0]->enum, ['active', 'blocked']); @@ -175,7 +172,7 @@ public function provideAssertChoiceResultsInNumericArray(): iterable ]; } - if (PHP_VERSION_ID >= 80000) { + if (\PHP_VERSION_ID >= 80000) { yield 'Attributes' => [new class() { #[Assert\Length(min: 1)] #[Assert\Choice(choices: TEST_ASSERT_CHOICE_STATUSES)] @@ -197,7 +194,7 @@ public function testMultipleChoiceConstraintsApplyEnumToItems($entity) $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader($this->doctrineAnnotations); $symfonyConstraintAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); $this->assertInstanceOf(OA\Items::class, $schema->properties[0]->items); $this->assertEquals($schema->properties[0]->items->enum, ['one', 'two']); @@ -214,7 +211,7 @@ public function provideMultipleChoiceConstraintsApplyEnumToItems(): iterable }]; } - if (PHP_VERSION_ID >= 80000) { + if (\PHP_VERSION_ID >= 80000) { yield 'Attributes' => [new class() { #[Assert\Choice(choices: ['one', 'two'], multiple: true)] private $property1; @@ -237,7 +234,7 @@ public function testLengthConstraintDoesNotSetMaxLengthIfMaxIsNotSet($entity) $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader($this->doctrineAnnotations); $symfonyConstraintAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); $this->assertSame(Generator::UNDEFINED, $schema->properties[0]->maxLength); $this->assertSame(1, $schema->properties[0]->minLength); @@ -256,7 +253,7 @@ public function provideLengthConstraintDoesNotSetMaxLengthIfMaxIsNotSet(): itera ]; } - if (PHP_VERSION_ID >= 80000) { + if (\PHP_VERSION_ID >= 80000) { yield 'Attributes' => [new class() { #[Assert\Length(min: 1)] private $property1; @@ -279,7 +276,7 @@ public function testLengthConstraintDoesNotSetMinLengthIfMinIsNotSet($entity) $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader($this->doctrineAnnotations); $symfonyConstraintAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); $this->assertSame(Generator::UNDEFINED, $schema->properties[0]->minLength); $this->assertSame(100, $schema->properties[0]->maxLength); @@ -298,7 +295,7 @@ public function provideLengthConstraintDoesNotSetMinLengthIfMinIsNotSet(): itera ]; } - if (PHP_VERSION_ID >= 80000) { + if (\PHP_VERSION_ID >= 80000) { yield 'Attributes' => [new class() { #[Assert\Length(max: 100)] private $property1; @@ -329,7 +326,7 @@ public function testCompoundValidationRules() $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader($this->doctrineAnnotations); $symfonyConstraintAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new ReflectionProperty($entity, $propertyName), $schema->properties[0]); + $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, $propertyName), $schema->properties[0]); if (Helper::isCompoundValidatorConstraintSupported()) { $this->assertSame([$propertyName], $schema->required); @@ -361,7 +358,7 @@ public function testCountConstraintDoesNotSetMinItemsIfMinIsNotSet($entity) $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader($this->doctrineAnnotations); $symfonyConstraintAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); $this->assertSame(Generator::UNDEFINED, $schema->properties[0]->minItems); $this->assertSame(10, $schema->properties[0]->maxItems); @@ -380,7 +377,7 @@ public function provideCountConstraintDoesNotSetMinItemsIfMinIsNotSet(): iterabl ]; } - if (PHP_VERSION_ID >= 80000) { + if (\PHP_VERSION_ID >= 80000) { yield 'Attributes' => [new class() { #[Assert\Count(max: 10)] private $property1; @@ -403,7 +400,7 @@ public function testCountConstraintDoesNotSetMaxItemsIfMaxIsNotSet($entity) $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader($this->doctrineAnnotations); $symfonyConstraintAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); $this->assertSame(Generator::UNDEFINED, $schema->properties[0]->maxItems); $this->assertSame(10, $schema->properties[0]->minItems); @@ -422,7 +419,7 @@ public function provideCountConstraintDoesNotSetMaxItemsIfMaxIsNotSet(): iterabl ]; } - if (PHP_VERSION_ID >= 80000) { + if (\PHP_VERSION_ID >= 80000) { yield 'Attributes' => [new class() { #[Assert\Count(min: 10)] private $property1; @@ -445,7 +442,7 @@ public function testRangeConstraintDoesNotSetMaximumIfMaxIsNotSet($entity) $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader($this->doctrineAnnotations); $symfonyConstraintAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); $this->assertSame(Generator::UNDEFINED, $schema->properties[0]->maximum); $this->assertSame(10, $schema->properties[0]->minimum); @@ -464,7 +461,7 @@ public function provideRangeConstraintDoesNotSetMaximumIfMaxIsNotSet(): iterable ]; } - if (PHP_VERSION_ID >= 80000) { + if (\PHP_VERSION_ID >= 80000) { yield 'Attributes' => [new class() { #[Assert\Range(min: 10)] private $property1; @@ -487,7 +484,7 @@ public function testRangeConstraintDoesNotSetMinimumIfMinIsNotSet($entity) $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader($this->doctrineAnnotations); $symfonyConstraintAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); $this->assertSame(Generator::UNDEFINED, $schema->properties[0]->minimum); $this->assertSame(10, $schema->properties[0]->maximum); @@ -506,7 +503,7 @@ public function provideRangeConstraintDoesNotSetMinimumIfMinIsNotSet(): iterable ]; } - if (PHP_VERSION_ID >= 80000) { + if (\PHP_VERSION_ID >= 80000) { yield 'Attributes' => [new class() { #[Assert\Range(max: 10)] private $property1; @@ -531,7 +528,7 @@ public function testReaderWithValidationGroupsEnabledChecksForDefaultGroupWhenNo // no serialization groups passed here $reader->updateProperty( - new ReflectionProperty($entity, 'property1'), + new \ReflectionProperty($entity, 'property1'), $schema->properties[0] ); @@ -554,7 +551,7 @@ public function testReaderWithValidationGroupsEnabledDoesNotReadAnnotationsWitho // no serialization groups passed here $reader->updateProperty( - new ReflectionProperty($entity, 'property1'), + new \ReflectionProperty($entity, 'property1'), $schema->properties[0] ); @@ -578,7 +575,7 @@ public function testReaderWithValidationGroupsEnabledReadsOnlyConstraintsWithGro // no serialization groups passed here $reader->updateProperty( - new ReflectionProperty($entity, 'property1'), + new \ReflectionProperty($entity, 'property1'), $schema->properties[0], ['other'] ); @@ -603,7 +600,7 @@ public function testReaderWithValidationGroupsEnabledCanReadFromMultipleValidati // no serialization groups passed here $reader->updateProperty( - new ReflectionProperty($entity, 'property1'), + new \ReflectionProperty($entity, 'property1'), $schema->properties[0], ['other', Constraint::DEFAULT_GROUP] ); @@ -625,7 +622,7 @@ public function provideConstraintsWithGroups(): iterable }]; } - if (PHP_VERSION_ID >= 80000) { + if (\PHP_VERSION_ID >= 80000) { yield 'Attributes' => [new class() { #[Assert\NotBlank()] #[Assert\Range(min: 1, groups: ['other'])] diff --git a/Tests/ModelDescriber/SelfDescribingModelDescriberTest.php b/Tests/ModelDescriber/SelfDescribingModelDescriberTest.php index 66045432b..38decbe68 100644 --- a/Tests/ModelDescriber/SelfDescribingModelDescriberTest.php +++ b/Tests/ModelDescriber/SelfDescribingModelDescriberTest.php @@ -16,7 +16,6 @@ use Nelmio\ApiDocBundle\Tests\ModelDescriber\Fixtures\SelfDescribingModel; use OpenApi\Annotations\Schema; use PHPUnit\Framework\TestCase; -use stdClass; use Symfony\Component\PropertyInfo\Type; class SelfDescribingModelDescriberTest extends TestCase @@ -32,7 +31,7 @@ public function testDoesNotSupport() { $describer = new SelfDescribingModelDescriber(); - $this->assertFalse($describer->supports(new Model(new Type('object', false, stdClass::class)))); + $this->assertFalse($describer->supports(new Model(new Type('object', false, \stdClass::class)))); } public function testDescribe() diff --git a/Tests/Render/RenderOpenApiTest.php b/Tests/Render/RenderOpenApiTest.php index 514b0c822..c8d6cc164 100644 --- a/Tests/Render/RenderOpenApiTest.php +++ b/Tests/Render/RenderOpenApiTest.php @@ -11,7 +11,6 @@ namespace Nelmio\ApiDocBundle\Tests\Render; -use InvalidArgumentException; use Nelmio\ApiDocBundle\Render\OpenApiRenderer; use Nelmio\ApiDocBundle\Render\RenderOpenApi; use OpenApi\Annotations\OpenApi; @@ -35,14 +34,14 @@ public function testRender() public function testUnknownFormat() { $availableOpenApiRenderers = []; - $this->expectExceptionObject(new InvalidArgumentException(sprintf('Format "%s" is not supported.', $this->format))); + $this->expectExceptionObject(new \InvalidArgumentException(sprintf('Format "%s" is not supported.', $this->format))); $this->renderOpenApi(...$availableOpenApiRenderers); } public function testUnknownArea() { $this->hasArea = false; - $this->expectExceptionObject(new InvalidArgumentException(sprintf('Area "%s" is not supported.', $this->area))); + $this->expectExceptionObject(new \InvalidArgumentException(sprintf('Area "%s" is not supported.', $this->area))); $this->renderOpenApi(); } diff --git a/Tests/RouteDescriber/FosRestDescriberTest.php b/Tests/RouteDescriber/FosRestDescriberTest.php index acbd2e699..5d94b7b42 100644 --- a/Tests/RouteDescriber/FosRestDescriberTest.php +++ b/Tests/RouteDescriber/FosRestDescriberTest.php @@ -16,7 +16,6 @@ use Nelmio\ApiDocBundle\RouteDescriber\FosRestDescriber; use OpenApi\Annotations\OpenApi; use PHPUnit\Framework\TestCase; -use ReflectionMethod; use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Routing\Route; use Symfony\Component\Validator\Constraints\Choice; @@ -48,7 +47,7 @@ public function testQueryParamWithChoiceConstraintIsAddedAsEnum() $fosRestDescriber->describe( $api, new Route('/'), - $this->createMock(ReflectionMethod::class) + $this->createMock(\ReflectionMethod::class) ); $this->assertSame($choices, $api->paths[0]->get->parameters[0]->schema->enum); diff --git a/Tests/RouteDescriber/RouteMetadataDescriberTest.php b/Tests/RouteDescriber/RouteMetadataDescriberTest.php index 388720ed5..c8f61b98d 100644 --- a/Tests/RouteDescriber/RouteMetadataDescriberTest.php +++ b/Tests/RouteDescriber/RouteMetadataDescriberTest.php @@ -16,7 +16,6 @@ use OpenApi\Context; use OpenApi\Generator; use PHPUnit\Framework\TestCase; -use ReflectionMethod; use Symfony\Component\Routing\Route; class RouteMetadataDescriberTest extends TestCase @@ -25,7 +24,7 @@ public function testUndefinedCheck() { $routeDescriber = new RouteMetadataDescriber(); - $this->assertNull($routeDescriber->describe(new OpenApi(['_context' => new Context()]), new Route('foo'), new ReflectionMethod(__CLASS__, 'testUndefinedCheck'))); + $this->assertNull($routeDescriber->describe(new OpenApi(['_context' => new Context()]), new Route('foo'), new \ReflectionMethod(__CLASS__, 'testUndefinedCheck'))); } public function testRouteRequirementsWithPattern() @@ -36,7 +35,7 @@ public function testRouteRequirementsWithPattern() $routeDescriber->describe( $api, $route, - new ReflectionMethod(__CLASS__, 'testRouteRequirementsWithPattern') + new \ReflectionMethod(__CLASS__, 'testRouteRequirementsWithPattern') ); $this->assertEquals('/index/{bar}/{foo}.html', $api->paths[0]->path); @@ -60,7 +59,7 @@ public function testSimpleOrRequirementsAreHandledAsEnums($req) $routeDescriber->describe( $api, $route, - new ReflectionMethod(__CLASS__, 'testSimpleOrRequirementsAreHandledAsEnums') + new \ReflectionMethod(__CLASS__, 'testSimpleOrRequirementsAreHandledAsEnums') ); $this->assertEquals('/index/{bar}/{foo}.html', $api->paths[0]->path); @@ -83,7 +82,7 @@ public function testNonEnumPatterns($pattern) $routeDescriber->describe( $api, $route, - new ReflectionMethod(__CLASS__, 'testNonEnumPatterns') + new \ReflectionMethod(__CLASS__, 'testNonEnumPatterns') ); $getPathParameter = $api->paths[0]->get->parameters[0]; diff --git a/Tests/Routing/FilteredRouteCollectionBuilderTest.php b/Tests/Routing/FilteredRouteCollectionBuilderTest.php index 0c351456a..d4f63b593 100644 --- a/Tests/Routing/FilteredRouteCollectionBuilderTest.php +++ b/Tests/Routing/FilteredRouteCollectionBuilderTest.php @@ -20,14 +20,11 @@ use OpenApi\Annotations\Parameter; use OpenApi\Context; use PHPUnit\Framework\TestCase; -use ReflectionMethod; -use stdClass; use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\OptionsResolver\Exception\InvalidArgumentException; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; -use const PHP_VERSION_ID; /** * Tests for FilteredRouteCollectionBuilder class. @@ -124,7 +121,7 @@ public function getInvalidOptions(): array [['invalid_option' => []]], [['path_patterns' => [22]]], [['path_patterns' => [null]]], - [['path_patterns' => [new stdClass()]]], + [['path_patterns' => [new \stdClass()]]], [['path_patterns' => ['^/foo$', 1]]], [['with_annotation' => ['an array']]], [['path_patterns' => 'a string']], @@ -133,7 +130,7 @@ public function getInvalidOptions(): array [['name_patterns' => 'a string']], [['name_patterns' => [22]]], [['name_patterns' => [null]]], - [['name_patterns' => [new stdClass()]]], + [['name_patterns' => [new \stdClass()]]], ]; } @@ -183,7 +180,7 @@ public function getMatchingRoutes(): iterable ['r10', new Route('/api/areas/new'), ['path_patterns' => ['^/api']]], ]; - if (PHP_VERSION_ID < 80000) { + if (\PHP_VERSION_ID < 80000) { yield ['r10', new Route('/api/areas_attributes/new'), ['path_patterns' => ['^/api']]]; } } @@ -199,7 +196,7 @@ public function testMatchingRoutesWithAnnotation(string $name, Route $route, arr $routes->add($name, $route); $area = 'area'; - $reflectionMethodStub = $this->createMock(ReflectionMethod::class); + $reflectionMethodStub = $this->createMock(\ReflectionMethod::class); $controllerReflectorStub = $this->createMock(ControllerReflector::class); $controllerReflectorStub->method('getReflectionMethod')->willReturn($reflectionMethodStub); @@ -239,7 +236,7 @@ public function getMatchingRoutesWithAnnotation(): iterable ], ]; - if (PHP_VERSION_ID < 80000) { + if (\PHP_VERSION_ID < 80000) { yield from [ 'with attribute only' => [ 'r10', @@ -303,7 +300,7 @@ public function testRoutesWithDisabledDefaultRoutes( $routes->add($name, $route); $area = 'area'; - $reflectionMethodStub = $this->createMock(ReflectionMethod::class); + $reflectionMethodStub = $this->createMock(\ReflectionMethod::class); $controllerReflectorStub = $this->createMock(ControllerReflector::class); $controllerReflectorStub->method('getReflectionMethod')->willReturn($reflectionMethodStub); diff --git a/Tests/SwaggerPhp/UtilTest.php b/Tests/SwaggerPhp/UtilTest.php index d1ab8df1c..5063b4daa 100644 --- a/Tests/SwaggerPhp/UtilTest.php +++ b/Tests/SwaggerPhp/UtilTest.php @@ -11,22 +11,12 @@ namespace Nelmio\ApiDocBundle\Tests\SwaggerPhp; -use ArrayObject; use Exception; use Nelmio\ApiDocBundle\OpenApiPhp\Util; use OpenApi\Annotations as OA; use OpenApi\Context; use OpenApi\Generator; use PHPUnit\Framework\TestCase; -use stdClass; -use function array_key_exists; -use function array_slice; -use function count; -use function get_class; -use function get_class_vars; -use function get_object_vars; -use function in_array; -use function strpos; /** * Class UtilTest. @@ -113,8 +103,8 @@ public function testCreateChildWithEmptyProperties() /** @var OA\Info $info */ $info = Util::createChild($this->rootAnnotation, OA\Info::class, $properties); - $properties = array_filter(get_object_vars($info), function ($key) { - return 0 !== strpos($key, '_'); + $properties = array_filter(\get_object_vars($info), function ($key) { + return 0 !== \strpos($key, '_'); }, ARRAY_FILTER_USE_KEY); $this->assertEquals([Generator::UNDEFINED], array_unique(array_values($properties))); @@ -125,7 +115,7 @@ public function testCreateChildWithEmptyProperties() public function testCreateChildWithProperties() { - $properties = ['title' => 'testing', 'version' => '999', 'x' => new stdClass()]; + $properties = ['title' => 'testing', 'version' => '999', 'x' => new \stdClass()]; /** @var OA\Info $info */ $info = Util::createChild($this->rootAnnotation, OA\Info::class, $properties); @@ -185,12 +175,12 @@ public function testCreateCollectionItemDoesNotAddToUnknownProperty() public function testSearchCollectionItem() { - $item1 = new stdClass(); + $item1 = new \stdClass(); $item1->prop1 = 'item 1 prop 1'; $item1->prop2 = 'item 1 prop 2'; $item1->prop3 = 'item 1 prop 3'; - $item2 = new stdClass(); + $item2 = new \stdClass(); $item2->prop1 = 'item 2 prop 1'; $item2->prop2 = 'item 2 prop 2'; $item2->prop3 = 'item 2 prop 3'; @@ -200,25 +190,25 @@ public function testSearchCollectionItem() $item2, ]; - $this->assertSame(0, Util::searchCollectionItem($collection, get_object_vars($item1))); - $this->assertSame(1, Util::searchCollectionItem($collection, get_object_vars($item2))); + $this->assertSame(0, Util::searchCollectionItem($collection, \get_object_vars($item1))); + $this->assertSame(1, Util::searchCollectionItem($collection, \get_object_vars($item2))); $this->assertNull(Util::searchCollectionItem( $collection, - array_merge(get_object_vars($item2), ['prop3' => 'foobar']) + array_merge(\get_object_vars($item2), ['prop3' => 'foobar']) )); $search = ['baz' => 'foobar']; $this->expectOutputString('Undefined property: stdClass::$baz'); try { - Util::searchCollectionItem($collection, array_merge(get_object_vars($item2), $search)); - } catch (Exception $e) { + Util::searchCollectionItem($collection, array_merge(\get_object_vars($item2), $search)); + } catch (\Exception $e) { echo $e->getMessage(); } // no exception on empty collection - $this->assertNull(Util::searchCollectionItem([], get_object_vars($item2))); + $this->assertNull(Util::searchCollectionItem([], \get_object_vars($item2))); } /** @@ -233,7 +223,7 @@ public function testSearchIndexedCollectionItem($setup, $asserts) (Generator::UNDEFINED !== $setup['components']->{$collection} ? $setup['components']->{$collection} : []); // get the indexing correct within haystack preparation - $properties = array_fill(0, count($setupCollection), null); + $properties = array_fill(0, \count($setupCollection), null); // prepare the haystack array foreach ($items as $assertItem) { @@ -284,7 +274,7 @@ public function testGetIndexedCollectionItem($setup, $asserts) $setup['components']->{$collection} ?? []; // the children created within provider are not connected - if (!in_array($child, $setupHaystack, true)) { + if (!\in_array($child, $setupHaystack, true)) { $this->assertIsNested($itemParent, $child); $this->assertIsConnectedToRootContext($child); } @@ -389,7 +379,7 @@ public function testGetChild($setup, $asserts) )); foreach ($asserts as $key => $assert) { - if (array_key_exists('exceptionMessage', $assert)) { + if (\array_key_exists('exceptionMessage', $assert)) { $this->expectExceptionMessage($assert['exceptionMessage']); } $child = Util::getChild($parent, $assert['class'], $assert['props']); @@ -397,7 +387,7 @@ public function testGetChild($setup, $asserts) $this->assertInstanceOf($assert['class'], $child); $this->assertSame($child, $parent->{$key}); - if (array_key_exists($key, $setup)) { + if (\array_key_exists($key, $setup)) { $this->assertSame($setup[$key], $parent->{$key}); } @@ -707,25 +697,25 @@ public function provideMergeData(): array 'assert' => array_merge( $assertDefaults, $merge, - ['tags' => array_slice($merge['tags'], 0, 2, true)] + ['tags' => \array_slice($merge['tags'], 0, 2, true)] ), ], [ // heavy nested merge array object 'setup' => $setupDefaults, - 'merge' => new ArrayObject([ + 'merge' => new \ArrayObject([ 'servers' => [ ['url' => 'http'], ['url' => 'https'], ], 'paths' => [ '/path/to/resource' => [ - 'get' => new ArrayObject([ + 'get' => new \ArrayObject([ 'responses' => [ '200' => [ '$ref' => '#/components/responses/default', ], ], - 'requestBody' => new ArrayObject([ + 'requestBody' => new \ArrayObject([ 'description' => 'request foo', 'content' => [ 'foo-request' => [ @@ -739,22 +729,22 @@ public function provideMergeData(): array ]), ], ], - 'tags' => new ArrayObject([ + 'tags' => new \ArrayObject([ ['name' => 'baz'], ['name' => 'foo'], - new ArrayObject(['name' => 'baz']), + new \ArrayObject(['name' => 'baz']), ['name' => 'foo'], ['name' => 'foo'], ]), - 'components' => new ArrayObject([ + 'components' => new \ArrayObject([ 'responses' => [ 'default' => [ 'description' => 'default response', - 'headers' => new ArrayObject([ - 'foo-header' => new ArrayObject([ - 'schema' => new ArrayObject([ + 'headers' => new \ArrayObject([ + 'foo-header' => new \ArrayObject([ + 'schema' => new \ArrayObject([ 'type' => 'array', - 'items' => new ArrayObject([ + 'items' => new \ArrayObject([ 'type' => 'string', 'enum' => ['foo', 'bar', 'baz'], ]), @@ -768,7 +758,7 @@ public function provideMergeData(): array 'assert' => array_merge( $assertDefaults, $merge, - ['tags' => array_slice($merge['tags'], 0, 2, true)] + ['tags' => \array_slice($merge['tags'], 0, 2, true)] ), ], [ // heavy nested merge swagger instance @@ -834,7 +824,7 @@ public function provideMergeData(): array 'assert' => array_merge( $assertDefaults, $merge, - ['tags' => array_slice($merge['tags'], 0, 2, true)] + ['tags' => \array_slice($merge['tags'], 0, 2, true)] ), ], ]; } @@ -862,11 +852,11 @@ private function getSetupPropertiesWithoutClass(array $setup) private function getNonDefaultProperties($object) { - $objectVars = get_object_vars($object); - $classVars = get_class_vars(get_class($object)); + $objectVars = \get_object_vars($object); + $classVars = \get_class_vars(\get_class($object)); $props = []; foreach ($objectVars as $key => $value) { - if ($value !== $classVars[$key] && 0 !== strpos($key, '_')) { + if ($value !== $classVars[$key] && 0 !== \strpos($key, '_')) { $props[$key] = $value; } } diff --git a/Tests/Util/ControllerReflectorTest.php b/Tests/Util/ControllerReflectorTest.php index d44b0dbde..7abb6b076 100644 --- a/Tests/Util/ControllerReflectorTest.php +++ b/Tests/Util/ControllerReflectorTest.php @@ -1,11 +1,19 @@ assertEquals( - ReflectionMethod::class, + \ReflectionMethod::class, get_class($controllerReflector->getReflectionMethod([BazingaController::class, 'userAction'])) ); $this->assertEquals( - ReflectionMethod::class, + \ReflectionMethod::class, get_class($controllerReflector->getReflectionMethod(BazingaController::class.'::userAction')) ); $this->assertNull( diff --git a/Util/SetsContextTrait.php b/Util/SetsContextTrait.php index fab9b9f9e..1a9166db7 100644 --- a/Util/SetsContextTrait.php +++ b/Util/SetsContextTrait.php @@ -1,5 +1,14 @@