diff --git a/.github/workflows/common/composer-install/action.yaml b/.github/workflows/common/composer-install/action.yaml new file mode 100644 index 000000000..70e64e4f6 --- /dev/null +++ b/.github/workflows/common/composer-install/action.yaml @@ -0,0 +1,51 @@ +name: Composer setup +description: Setup, install and cache Composer dependencies + +inputs: + symfony-version: + description: The required Symfony version that will be installed + required: true + type: string + + install-doctrine-annotations: + description: If the doctrine/annotations package should be additionally installed as a dependency + required: true + type: boolean + + composer-flags: + description: Additional flags that are passed to the `composer update` step + required: false + type: string + +runs: + using: composite + steps: + - name: Get Composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + shell: bash + + - name: Cache Composer dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + ${{ runner.os }}-composer- + + - name: Install doctrine/annotations + if: ${{ inputs.install-doctrine-annotations == 'true' }} + run: composer require --no-update doctrine/annotations + shell: bash + + - name: Remove packages not compatible Symfony 7 + if: ${{ inputs.symfony-version == '7.0.*' }} + run: composer remove --dev --no-update friendsofsymfony/rest-bundle sensio/framework-extra-bundle + shell: bash + + - name: Install dependencies with Composer + env: + SYMFONY_REQUIRE: ${{ inputs.symfony-version }} + run: composer update --no-interaction --no-progress ${{ inputs.composer-flags }} + shell: bash diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 5db759b07..68acaad4b 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -1,7 +1,7 @@ # from doctrine/instantiator: # https://github.com/doctrine/instantiator/blob/97aa11bb71ad6259a8c5a1161b4de2d6cdcc5501/.github/workflows/continuous-integration.yml -name: "CI" +name: CI on: pull_request: @@ -18,8 +18,8 @@ env: jobs: phpunit: - name: "PHPUnit" - runs-on: "ubuntu-22.04" + name: PHPUnit + runs-on: ubuntu-22.04 strategy: fail-fast: false @@ -54,43 +54,50 @@ jobs: doctrine-annotations: false steps: - - name: "Checkout" + - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 2 - - name: "Install PHP without coverage" + - name: Install PHP without coverage uses: shivammathur/setup-php@v2 with: - php-version: "${{ matrix.php-version }}" + php-version: ${{ matrix.php-version }} tools: composer, flex coverage: pcov - - name: "Get composer cache directory" - id: composercache - run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: "Cache dependencies" - uses: actions/cache@v3 + - name: Setup dependencies + uses: ./.github/workflows/common/composer-install with: - path: ${{ steps.composercache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-composer- + symfony-version: ${{ matrix.symfony-require }} + install-doctrine-annotations: ${{ matrix.doctrine-annotations }} + composer-flags: ${{ matrix.composer-flags }} - - name: Install doctrine/annotations - if: matrix.doctrine-annotations == true - run: | - composer require doctrine/annotations --no-update + - name: PHPUnit Tests + run: vendor/bin/phpunit --configuration phpunit.xml.dist --coverage-text - - name: Remove packages not compatible symfony 7 - if: matrix.symfony-require == '7.0.*' - run: | - composer remove friendsofsymfony/rest-bundle sensio/framework-extra-bundle --no-update --dev + php-cs-fixer: + name: PHP-CS-Fixer + runs-on: ubuntu-22.04 - - name: "Install dependencies with composer" - env: - SYMFONY_REQUIRE: "${{ matrix.symfony-require }}" - run: composer update --no-interaction --no-progress ${{ matrix.composer-flags }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 2 - - name: "PHPUnit Tests" - run: vendor/bin/phpunit --configuration phpunit.xml.dist --coverage-text + - name: Install PHP without coverage + uses: shivammathur/setup-php@v2 + with: + php-version: 8.3 + tools: composer, flex + coverage: pcov + + - name: Setup dependencies + uses: ./.github/workflows/common/composer-install + with: + symfony-version: "7.0.*" + install-doctrine-annotations: false + + - name: Run PHP-CS-Fixer + run: vendor/bin/php-cs-fixer check -v --diff diff --git a/.gitignore b/.gitignore index 289c53cc2..152332d20 100644 --- a/.gitignore +++ b/.gitignore @@ -2,11 +2,14 @@ /vendor/ /composer.phar /composer.lock -/.php_cs.cache -/.php_cs /phpunit.xml /.phpunit /.phpunit.result.cache /Tests/Functional/cache /Tests/Functional/logs .idea + +###> friendsofphp/php-cs-fixer ### +/.php-cs-fixer.php +/.php-cs-fixer.cache +###< friendsofphp/php-cs-fixer ### diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 63% rename from .php_cs.dist rename to .php-cs-fixer.dist.php index b7190bbf3..b8e14f420 100644 --- a/.php_cs.dist +++ b/.php-cs-fixer.dist.php @@ -1,16 +1,15 @@ in(__DIR__) ->exclude('var') - ->exclude('Tests/Functional/cache') -; + ->exclude('tests/Functional/cache'); -return PhpCsFixer\Config::create() +return (new PhpCsFixer\Config()) ->setRules([ '@Symfony' => true, - 'ordered_imports' => true, - 'phpdoc_order' => true, 'header_comment' => [ 'header' => <<
setFinder($finder) -; + ->setFinder($finder); diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index dc919d392..000000000 --- a/.styleci.yml +++ /dev/null @@ -1,7 +0,0 @@ -preset: symfony - -enabled: - - ordered_use - -disabled: - - unalign_equals diff --git a/composer.json b/composer.json index 7bd76fbfd..7afb3d3f4 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,8 @@ "composer/package-versions-deprecated": "1.11.99.1", "phpunit/phpunit": "^8.5|^9.6", - "doctrine/annotations": "^2.0" + "doctrine/annotations": "^2.0", + "friendsofphp/php-cs-fixer": "^3.52" }, "conflict": { "zircote/swagger-php": "4.8.7" @@ -91,9 +92,13 @@ } }, "scripts-descriptions": { + "phpcs-check": "Run PHP-CS-Fixer in dry-run mode", + "phpcs-fix": "Run PHP-CS-Fixer", "phpunit": "Run phpunit" }, "scripts": { + "phpcs-check": "vendor/bin/php-cs-fixer check -v --diff", + "phpcs-fix": "vendor/bin/php-cs-fixer fix -v", "phpunit": "phpunit" } } diff --git a/src/Annotation/Model.php b/src/Annotation/Model.php index b06b4f179..dc0e59502 100644 --- a/src/Annotation/Model.php +++ b/src/Annotation/Model.php @@ -21,7 +21,6 @@ #[\Attribute(\Attribute::TARGET_METHOD)] final class Model extends Attachable { - /** {@inheritdoc} */ public static $_types = [ 'type' => 'string', 'groups' => '[string]', @@ -63,8 +62,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/src/Annotation/Security.php b/src/Annotation/Security.php index 8676014cf..9182f3ecd 100644 --- a/src/Annotation/Security.php +++ b/src/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]', @@ -39,7 +38,7 @@ class Security extends AbstractAnnotation public function __construct( array $properties = [], - string $name = null, + ?string $name = null, array $scopes = [] ) { parent::__construct($properties + [ diff --git a/src/ApiDocGenerator.php b/src/ApiDocGenerator.php index cbb4b4afb..e5a5873f6 100644 --- a/src/ApiDocGenerator.php +++ b/src/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/src/Controller/YamlDocumentationController.php b/src/Controller/YamlDocumentationController.php index a935a2d4c..9a320e13a 100644 --- a/src/Controller/YamlDocumentationController.php +++ b/src/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; @@ -39,7 +38,7 @@ public function __invoke(Request $request, $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/src/DependencyInjection/NelmioApiDocExtension.php b/src/DependencyInjection/NelmioApiDocExtension.php index 9857083c5..1994d3982 100644 --- a/src/DependencyInjection/NelmioApiDocExtension.php +++ b/src/DependencyInjection/NelmioApiDocExtension.php @@ -47,9 +47,6 @@ final class NelmioApiDocExtension extends Extension implements PrependExtensionInterface { - /** - * {@inheritdoc} - */ public function prepend(ContainerBuilder $container): void { $container->prependExtensionConfig('framework', ['property_info' => ['enabled' => true]]); @@ -62,9 +59,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/src/Describer/OpenApiPhpDescriber.php b/src/Describer/OpenApiPhpDescriber.php index d6cc5b791..b631787ee 100644 --- a/src/Describer/OpenApiPhpDescriber.php +++ b/src/Describer/OpenApiPhpDescriber.php @@ -144,10 +144,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/src/Exception/UndocumentedArrayItemsException.php b/src/Exception/UndocumentedArrayItemsException.php index 78d6a995f..2ce418741 100644 --- a/src/Exception/UndocumentedArrayItemsException.php +++ b/src/Exception/UndocumentedArrayItemsException.php @@ -19,7 +19,7 @@ class UndocumentedArrayItemsException extends \LogicException private $class; private $path; - public function __construct(string $class = null, string $path = '') + public function __construct(?string $class = null, string $path = '') { $this->class = $class; $this->path = $path; diff --git a/src/Model/Model.php b/src/Model/Model.php index 2cd5893e2..b7c796b68 100644 --- a/src/Model/Model.php +++ b/src/Model/Model.php @@ -23,7 +23,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/src/ModelDescriber/Annotations/AnnotationsReader.php b/src/ModelDescriber/Annotations/AnnotationsReader.php index b483793ce..d8a299268 100644 --- a/src/ModelDescriber/Annotations/AnnotationsReader.php +++ b/src/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/src/ModelDescriber/Annotations/OpenApiAnnotationsReader.php b/src/ModelDescriber/Annotations/OpenApiAnnotationsReader.php index 026178d2a..fa11d1f46 100644 --- a/src/ModelDescriber/Annotations/OpenApiAnnotationsReader.php +++ b/src/ModelDescriber/Annotations/OpenApiAnnotationsReader.php @@ -67,7 +67,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)) { @@ -86,8 +86,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/src/ModelDescriber/BazingaHateoasModelDescriber.php b/src/ModelDescriber/BazingaHateoasModelDescriber.php index 35e0eee32..8fe05a9f7 100644 --- a/src/ModelDescriber/BazingaHateoasModelDescriber.php +++ b/src/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/src/ModelDescriber/EnumModelDescriber.php b/src/ModelDescriber/EnumModelDescriber.php index 93ad24fb1..1aae41ef1 100644 --- a/src/ModelDescriber/EnumModelDescriber.php +++ b/src/ModelDescriber/EnumModelDescriber.php @@ -1,5 +1,14 @@ contextFactory = $contextFactory; } - /** - * {@inheritdoc} - */ public function describe(Model $model, OA\Schema $schema) { $className = $model->getType()->getClassName(); @@ -227,7 +224,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; @@ -246,9 +243,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/src/ModelDescriber/ObjectModelDescriber.php b/src/ModelDescriber/ObjectModelDescriber.php index faac0947e..c20b48a39 100644 --- a/src/ModelDescriber/ObjectModelDescriber.php +++ b/src/ModelDescriber/ObjectModelDescriber.php @@ -53,9 +53,9 @@ public function __construct( ?Reader $reader, $propertyDescribers, array $mediaTypes, - NameConverterInterface $nameConverter = null, + ?NameConverterInterface $nameConverter = null, bool $useValidationGroups = false, - ClassMetadataFactoryInterface $classMetadataFactory = null + ?ClassMetadataFactoryInterface $classMetadataFactory = null ) { if (is_iterable($propertyDescribers)) { trigger_deprecation('nelmio/api-doc-bundle', '4.17', 'Passing an array of PropertyDescriberInterface to %s() is deprecated. Pass a single PropertyDescriberInterface instead.', __METHOD__); diff --git a/src/NelmioApiDocBundle.php b/src/NelmioApiDocBundle.php index f5d040308..94cf95c2f 100644 --- a/src/NelmioApiDocBundle.php +++ b/src/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/src/OpenApiPhp/ModelRegister.php b/src/OpenApiPhp/ModelRegister.php index c277d6ee1..7de7a46c9 100644 --- a/src/OpenApiPhp/ModelRegister.php +++ b/src/OpenApiPhp/ModelRegister.php @@ -38,7 +38,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 @@ -106,7 +106,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/src/OpenApiPhp/Util.php b/src/OpenApiPhp/Util.php index 839426935..116759bbf 100644 --- a/src/OpenApiPhp/Util.php +++ b/src/OpenApiPhp/Util.php @@ -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/src/Processor/MapQueryStringProcessor.php b/src/Processor/MapQueryStringProcessor.php index 1a4a87c66..48446456a 100644 --- a/src/Processor/MapQueryStringProcessor.php +++ b/src/Processor/MapQueryStringProcessor.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\Processor; use Nelmio\ApiDocBundle\OpenApiPhp\Util; diff --git a/src/Processor/MapRequestPayloadProcessor.php b/src/Processor/MapRequestPayloadProcessor.php index 03df9b142..396982e87 100644 --- a/src/Processor/MapRequestPayloadProcessor.php +++ b/src/Processor/MapRequestPayloadProcessor.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\Processor; use Nelmio\ApiDocBundle\OpenApiPhp\Util; diff --git a/src/Processor/NullablePropertyProcessor.php b/src/Processor/NullablePropertyProcessor.php index 6f8c401e1..038393c78 100644 --- a/src/Processor/NullablePropertyProcessor.php +++ b/src/Processor/NullablePropertyProcessor.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\Processor; use OpenApi\Analysis; diff --git a/src/PropertyDescriber/ArrayPropertyDescriber.php b/src/PropertyDescriber/ArrayPropertyDescriber.php index 7f6f76395..201726916 100644 --- a/src/PropertyDescriber/ArrayPropertyDescriber.php +++ b/src/PropertyDescriber/ArrayPropertyDescriber.php @@ -22,7 +22,7 @@ class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistr use ModelRegistryAwareTrait; use PropertyDescriberAwareTrait; - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) { $property->type = 'array'; /** @var OA\Items $property */ diff --git a/src/PropertyDescriber/BooleanPropertyDescriber.php b/src/PropertyDescriber/BooleanPropertyDescriber.php index b5ad5e7ae..b90a37eb8 100644 --- a/src/PropertyDescriber/BooleanPropertyDescriber.php +++ b/src/PropertyDescriber/BooleanPropertyDescriber.php @@ -16,7 +16,7 @@ class BooleanPropertyDescriber implements PropertyDescriberInterface { - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) { $property->type = 'boolean'; } diff --git a/src/PropertyDescriber/CompoundPropertyDescriber.php b/src/PropertyDescriber/CompoundPropertyDescriber.php index 5fe38cd57..29686f2aa 100644 --- a/src/PropertyDescriber/CompoundPropertyDescriber.php +++ b/src/PropertyDescriber/CompoundPropertyDescriber.php @@ -22,7 +22,7 @@ class CompoundPropertyDescriber implements PropertyDescriberInterface, ModelRegi use ModelRegistryAwareTrait; use PropertyDescriberAwareTrait; - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) { $property->oneOf = Generator::UNDEFINED !== $property->oneOf ? $property->oneOf : []; diff --git a/src/PropertyDescriber/DateTimePropertyDescriber.php b/src/PropertyDescriber/DateTimePropertyDescriber.php index 592ca2ab4..1e57292e5 100644 --- a/src/PropertyDescriber/DateTimePropertyDescriber.php +++ b/src/PropertyDescriber/DateTimePropertyDescriber.php @@ -16,7 +16,7 @@ class DateTimePropertyDescriber implements PropertyDescriberInterface { - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) { $property->type = 'string'; $property->format = 'date-time'; diff --git a/src/PropertyDescriber/DictionaryPropertyDescriber.php b/src/PropertyDescriber/DictionaryPropertyDescriber.php index 95777bc10..0c3d31c37 100644 --- a/src/PropertyDescriber/DictionaryPropertyDescriber.php +++ b/src/PropertyDescriber/DictionaryPropertyDescriber.php @@ -22,7 +22,7 @@ final class DictionaryPropertyDescriber implements PropertyDescriberInterface, M use ModelRegistryAwareTrait; use PropertyDescriberAwareTrait; - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) { $property->type = 'object'; /** @var OA\AdditionalProperties $additionalProperties */ @@ -31,7 +31,6 @@ public function describe(array $types, OA\Schema $property, array $groups = null $this->propertyDescriber->describe($types[0]->getCollectionValueTypes(), $additionalProperties, $groups, $schema, $context); } - /** {@inheritDoc} */ public function supports(array $types): bool { return 1 === count($types) diff --git a/src/PropertyDescriber/FloatPropertyDescriber.php b/src/PropertyDescriber/FloatPropertyDescriber.php index bcae34ea8..4dee3ef35 100644 --- a/src/PropertyDescriber/FloatPropertyDescriber.php +++ b/src/PropertyDescriber/FloatPropertyDescriber.php @@ -16,7 +16,7 @@ class FloatPropertyDescriber implements PropertyDescriberInterface { - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) { $property->type = 'number'; $property->format = 'float'; diff --git a/src/PropertyDescriber/IntegerPropertyDescriber.php b/src/PropertyDescriber/IntegerPropertyDescriber.php index 25379ff7b..746fd9116 100644 --- a/src/PropertyDescriber/IntegerPropertyDescriber.php +++ b/src/PropertyDescriber/IntegerPropertyDescriber.php @@ -16,7 +16,7 @@ class IntegerPropertyDescriber implements PropertyDescriberInterface { - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) { $property->type = 'integer'; } diff --git a/src/PropertyDescriber/NullablePropertyDescriber.php b/src/PropertyDescriber/NullablePropertyDescriber.php index 3e9d0894f..d9adad526 100644 --- a/src/PropertyDescriber/NullablePropertyDescriber.php +++ b/src/PropertyDescriber/NullablePropertyDescriber.php @@ -18,7 +18,7 @@ final class NullablePropertyDescriber implements PropertyDescriberInterface, Pro { use PropertyDescriberAwareTrait; - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) { if (Generator::UNDEFINED === $property->nullable) { $property->nullable = true; diff --git a/src/PropertyDescriber/ObjectPropertyDescriber.php b/src/PropertyDescriber/ObjectPropertyDescriber.php index b27d2cfd9..d1ccb2e81 100644 --- a/src/PropertyDescriber/ObjectPropertyDescriber.php +++ b/src/PropertyDescriber/ObjectPropertyDescriber.php @@ -22,7 +22,7 @@ class ObjectPropertyDescriber implements PropertyDescriberInterface, ModelRegist { use ModelRegistryAwareTrait; - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) { $type = new Type( $types[0]->getBuiltinType(), diff --git a/src/PropertyDescriber/PropertyDescriber.php b/src/PropertyDescriber/PropertyDescriber.php index 767bb59d8..76e7ca8e8 100644 --- a/src/PropertyDescriber/PropertyDescriber.php +++ b/src/PropertyDescriber/PropertyDescriber.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\PropertyDescriber; use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface; @@ -24,7 +33,7 @@ public function __construct( $this->propertyDescribers = $propertyDescribers; } - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null, array $context = []): void + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []): void { if (!$propertyDescriber = $this->getPropertyDescriber($types)) { return; diff --git a/src/PropertyDescriber/PropertyDescriberInterface.php b/src/PropertyDescriber/PropertyDescriberInterface.php index a0fb4ad1e..d2ec894a2 100644 --- a/src/PropertyDescriber/PropertyDescriberInterface.php +++ b/src/PropertyDescriber/PropertyDescriberInterface.php @@ -22,7 +22,7 @@ interface PropertyDescriberInterface * @param Schema $schema Allows to make changes inside of the schema (e.g. adding required fields) * @param array $context Context options for describing the property */ - public function describe(array $types, Schema $property, array $groups = null /* , ?Schema $schema = null */ /* , array $context = [] */); + public function describe(array $types, Schema $property, ?array $groups = null /* , ?Schema $schema = null */ /* , array $context = [] */); /** * @param Type[] $types diff --git a/src/PropertyDescriber/RequiredPropertyDescriber.php b/src/PropertyDescriber/RequiredPropertyDescriber.php index 750ee4963..2709ff4df 100644 --- a/src/PropertyDescriber/RequiredPropertyDescriber.php +++ b/src/PropertyDescriber/RequiredPropertyDescriber.php @@ -21,7 +21,7 @@ final class RequiredPropertyDescriber implements PropertyDescriberInterface, Pro { use PropertyDescriberAwareTrait; - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) { $this->propertyDescriber->describe($types, $property, $groups, $schema, $context); diff --git a/src/PropertyDescriber/StringPropertyDescriber.php b/src/PropertyDescriber/StringPropertyDescriber.php index c8de8affb..417992ba3 100644 --- a/src/PropertyDescriber/StringPropertyDescriber.php +++ b/src/PropertyDescriber/StringPropertyDescriber.php @@ -16,7 +16,7 @@ class StringPropertyDescriber implements PropertyDescriberInterface { - public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) { $property->type = 'string'; } diff --git a/src/Render/Html/HtmlOpenApiRenderer.php b/src/Render/Html/HtmlOpenApiRenderer.php index 6f039b411..f5181e47a 100644 --- a/src/Render/Html/HtmlOpenApiRenderer.php +++ b/src/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/src/Render/Html/Renderer.php b/src/Render/Html/Renderer.php index 348f38bcf..ddbfa961d 100644 --- a/src/Render/Html/Renderer.php +++ b/src/Render/Html/Renderer.php @@ -1,5 +1,14 @@ getDefault('_controller'); diff --git a/src/RouteDescriber/RouteArgumentDescriber/RouteArgumentDescriberInterface.php b/src/RouteDescriber/RouteArgumentDescriber/RouteArgumentDescriberInterface.php index 7932addc6..3e1e9b37e 100644 --- a/src/RouteDescriber/RouteArgumentDescriber/RouteArgumentDescriberInterface.php +++ b/src/RouteDescriber/RouteArgumentDescriber/RouteArgumentDescriberInterface.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\RouteDescriber\RouteArgumentDescriber; use OpenApi\Annotations as OA; diff --git a/src/RouteDescriber/RouteArgumentDescriber/SymfonyMapQueryParameterDescriber.php b/src/RouteDescriber/RouteArgumentDescriber/SymfonyMapQueryParameterDescriber.php index 97049eb75..5a22f7493 100644 --- a/src/RouteDescriber/RouteArgumentDescriber/SymfonyMapQueryParameterDescriber.php +++ b/src/RouteDescriber/RouteArgumentDescriber/SymfonyMapQueryParameterDescriber.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\RouteDescriber\RouteArgumentDescriber; use Nelmio\ApiDocBundle\OpenApiPhp\Util; diff --git a/src/RouteDescriber/RouteArgumentDescriber/SymfonyMapQueryStringDescriber.php b/src/RouteDescriber/RouteArgumentDescriber/SymfonyMapQueryStringDescriber.php index d4bfe6b95..e6147e138 100644 --- a/src/RouteDescriber/RouteArgumentDescriber/SymfonyMapQueryStringDescriber.php +++ b/src/RouteDescriber/RouteArgumentDescriber/SymfonyMapQueryStringDescriber.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\RouteDescriber\RouteArgumentDescriber; use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface; @@ -15,12 +24,12 @@ final class SymfonyMapQueryStringDescriber implements RouteArgumentDescriberInterface, ModelRegistryAwareInterface { + use ModelRegistryAwareTrait; + public const CONTEXT_KEY = 'nelmio_api_doc_bundle.map_query_string.'.self::class; public const CONTEXT_ARGUMENT_METADATA = 'nelmio_api_doc_bundle.argument_metadata.'.self::class; public const CONTEXT_MODEL_REF = 'nelmio_api_doc_bundle.model_ref.'.self::class; - use ModelRegistryAwareTrait; - public function describe(ArgumentMetadata $argumentMetadata, OA\Operation $operation): void { /** @var MapQueryString $attribute */ diff --git a/src/RouteDescriber/RouteArgumentDescriber/SymfonyMapRequestPayloadDescriber.php b/src/RouteDescriber/RouteArgumentDescriber/SymfonyMapRequestPayloadDescriber.php index ae098dd16..283222b14 100644 --- a/src/RouteDescriber/RouteArgumentDescriber/SymfonyMapRequestPayloadDescriber.php +++ b/src/RouteDescriber/RouteArgumentDescriber/SymfonyMapRequestPayloadDescriber.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\RouteDescriber\RouteArgumentDescriber; use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface; @@ -15,11 +24,11 @@ final class SymfonyMapRequestPayloadDescriber implements RouteArgumentDescriberInterface, ModelRegistryAwareInterface { + use ModelRegistryAwareTrait; + public const CONTEXT_ARGUMENT_METADATA = 'nelmio_api_doc_bundle.argument_metadata.'.self::class; public const CONTEXT_MODEL_REF = 'nelmio_api_doc_bundle.model_ref.'.self::class; - use ModelRegistryAwareTrait; - public function describe(ArgumentMetadata $argumentMetadata, OA\Operation $operation): void { /** @var MapRequestPayload $attribute */ diff --git a/src/RouteDescriber/RouteMetadataDescriber.php b/src/RouteDescriber/RouteMetadataDescriber.php index 83d80685e..632a26aa6 100644 --- a/src/RouteDescriber/RouteMetadataDescriber.php +++ b/src/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/src/Util/SetsContextTrait.php b/src/Util/SetsContextTrait.php index fab9b9f9e..1a9166db7 100644 --- a/src/Util/SetsContextTrait.php +++ b/src/Util/SetsContextTrait.php @@ -1,5 +1,14 @@ markTestSkipped('Typed embedded properties require at least willdurand/hateoas 3.0'); } $this->assertEquals([ diff --git a/tests/Functional/ConfigurableContainerFactory.php b/tests/Functional/ConfigurableContainerFactory.php index 1b0f19a74..18e34208e 100644 --- a/tests/Functional/ConfigurableContainerFactory.php +++ b/tests/Functional/ConfigurableContainerFactory.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; use Symfony\Component\DependencyInjection\ContainerInterface; diff --git a/tests/Functional/Controller/Controller2209.php b/tests/Functional/Controller/Controller2209.php index 58e7d7b01..7ea767869 100644 --- a/tests/Functional/Controller/Controller2209.php +++ b/tests/Functional/Controller/Controller2209.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\Controller; use Nelmio\ApiDocBundle\Annotation\Model; diff --git a/tests/Functional/Controller/MapQueryStringController.php b/tests/Functional/Controller/MapQueryStringController.php index e7a70ac36..a286cbd23 100644 --- a/tests/Functional/Controller/MapQueryStringController.php +++ b/tests/Functional/Controller/MapQueryStringController.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\Controller; use Nelmio\ApiDocBundle\Tests\Functional\Entity\QueryModel\ArrayQueryModel; diff --git a/tests/Functional/Controller/PromotedPropertiesController80.php b/tests/Functional/Controller/PromotedPropertiesController80.php index be10fce1d..27c35cf4f 100644 --- a/tests/Functional/Controller/PromotedPropertiesController80.php +++ b/tests/Functional/Controller/PromotedPropertiesController80.php @@ -1,5 +1,7 @@ + * @var array */ public $compoundOptions; /** - * @var array> + * @var array> */ public $nestedCompoundOptions; @@ -37,7 +46,7 @@ class Dictionary public $arrayOrDictOptions; /** - * @var array + * @var array */ public $integerOptions; } diff --git a/tests/Functional/Entity/Article81.php b/tests/Functional/Entity/Article81.php index e35a2f47c..ae6cec165 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 4f6f5418a..f8e06e44c 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}']; } } @@ -389,7 +388,7 @@ public function provideSecurityRoute(): iterable { yield 'Annotations' => ['/api/security']; - if (PHP_VERSION_ID >= 80100) { + if (\PHP_VERSION_ID >= 80100) { yield 'Attributes' => ['/api/security_attributes']; } } @@ -407,14 +406,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 465314006..73ba83c6c 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,12 @@ class TestKernel extends Kernel { use MicroKernelTrait; - const USE_JMS = 1; - const USE_BAZINGA = 2; - const USE_FOSREST = 3; - const USE_VALIDATION_GROUPS = 8; - const USE_FORM_CSRF = 16; + + public const USE_JMS = 1; + public const USE_BAZINGA = 2; + public const USE_FOSREST = 3; + public const USE_VALIDATION_GROUPS = 8; + public const USE_FORM_CSRF = 16; private $flags; @@ -103,9 +102,9 @@ protected function configureRoutes(RoutingConfigurator $routes) $routes->withPath('/')->import(__DIR__.'/Controller/BazingaTypedController.php', self::isAnnotationsAvailable() ? 'annotation' : 'attribute'); try { - new ReflectionMethod(Embedded::class, 'getType'); + new \ReflectionMethod(Embedded::class, 'getType'); $routes->withPath('/')->import(__DIR__.'/Controller/BazingaTypedController.php', self::isAnnotationsAvailable() ? 'annotation' : 'attribute'); - } catch (ReflectionException $e) { + } catch (\ReflectionException $e) { } } @@ -246,13 +245,13 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load } elseif (self::isAttributesAvailable()) { $models = array_merge($models, [ [ - 'alias' => 'JMSComplex', - 'type' => JMSComplex81::class, - 'groups' => [ - 'list', - 'details', - 'User' => ['list'], - ], + 'alias' => 'JMSComplex', + 'type' => JMSComplex81::class, + 'groups' => [ + 'list', + 'details', + 'User' => ['list'], + ], ], [ 'alias' => 'JMSComplexDefault', @@ -319,20 +318,20 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load ], ], ], - 'areas' => [ - 'default' => [ - 'path_patterns' => ['^/api(?!/admin)'], - 'host_patterns' => ['^api\.'], - ], - 'test' => [ - 'path_patterns' => ['^/test'], - 'host_patterns' => ['^api-test\.'], - 'documentation' => [ - 'info' => [ - 'title' => 'My Test App', - ], - ], - ], + 'areas' => [ + 'default' => [ + 'path_patterns' => ['^/api(?!/admin)'], + 'host_patterns' => ['^api\.'], + ], + 'test' => [ + 'path_patterns' => ['^/test'], + 'host_patterns' => ['^api-test\.'], + 'documentation' => [ + 'info' => [ + 'title' => 'My Test App', + ], + ], + ], ], 'models' => [ 'names' => $models, 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 6afad37a3..f504e33a0 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 @@ -47,24 +46,24 @@ public function testNameCollisionsAreLogged(Type $type, array $arrayType) ->method('info') ->with( 'Can not assign a name for the model, the name "ModelRegistryTest" has already been taken.', [ - 'model' => [ - 'type' => $arrayType, - 'options' => null, - 'groups' => ['group2'], - 'serialization_context' => [ + 'model' => [ + 'type' => $arrayType, + 'options' => null, 'groups' => ['group2'], + 'serialization_context' => [ + 'groups' => ['group2'], + ], ], - ], - 'taken_by' => [ - 'type' => $arrayType, - 'options' => null, - 'groups' => ['group1'], - 'serialization_context' => [ + 'taken_by' => [ + 'type' => $arrayType, + 'options' => null, 'groups' => ['group1'], - 'extra_context' => true, + 'serialization_context' => [ + 'groups' => ['group1'], + 'extra_context' => true, + ], ], - ], - ]); + ]); $registry = new ModelRegistry([], $this->createOpenApi(), []); $registry->setLogger($logger); @@ -111,7 +110,7 @@ public function provideNameCollisionsTypes() public function testNameCollisionsAreLoggedWithAlternativeNames() { - $ref = new ReflectionClass(self::class); + $ref = new \ReflectionClass(self::class); $alternativeNames = [ $ref->getShortName() => [ 'type' => $ref->getName(), @@ -124,33 +123,33 @@ public function testNameCollisionsAreLoggedWithAlternativeNames() ->method('info') ->with( 'Can not assign a name for the model, the name "ModelRegistryTest" has already been taken.', [ - 'model' => [ - 'type' => [ - 'class' => 'Nelmio\\ApiDocBundle\\Tests\\Model\\ModelRegistryTest', - 'built_in_type' => 'object', - 'nullable' => false, - 'collection' => false, - 'collection_key_types' => null, - 'collection_value_types' => null, + 'model' => [ + 'type' => [ + 'class' => 'Nelmio\\ApiDocBundle\\Tests\\Model\\ModelRegistryTest', + 'built_in_type' => 'object', + 'nullable' => false, + 'collection' => false, + 'collection_key_types' => null, + 'collection_value_types' => null, + ], + 'options' => null, + 'groups' => ['group2'], + 'serialization_context' => ['groups' => ['group2']], ], - 'options' => null, - 'groups' => ['group2'], - 'serialization_context' => ['groups' => ['group2']], - ], - 'taken_by' => [ - 'type' => [ - 'class' => 'Nelmio\\ApiDocBundle\\Tests\\Model\\ModelRegistryTest', - 'built_in_type' => 'object', - 'nullable' => false, - 'collection' => false, - 'collection_key_types' => null, - 'collection_value_types' => null, + 'taken_by' => [ + 'type' => [ + 'class' => 'Nelmio\\ApiDocBundle\\Tests\\Model\\ModelRegistryTest', + 'built_in_type' => 'object', + 'nullable' => false, + 'collection' => false, + 'collection_key_types' => null, + 'collection_value_types' => null, + ], + 'options' => null, + 'groups' => ['group1'], + 'serialization_context' => ['groups' => ['group1']], ], - 'options' => null, - 'groups' => ['group1'], - 'serialization_context' => ['groups' => ['group1']], - ], - ]); + ]); $registry = new ModelRegistry([], $this->createOpenApi(), $alternativeNames); $registry->setLogger($logger); 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/FormModelDescriberTest.php b/tests/ModelDescriber/FormModelDescriberTest.php index 6e62b827f..e0f6e2f32 100644 --- a/tests/ModelDescriber/FormModelDescriberTest.php +++ b/tests/ModelDescriber/FormModelDescriberTest.php @@ -1,5 +1,14 @@ 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..132c4f4fc 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', @@ -290,7 +287,7 @@ public function getNonMatchingRoutes(): array * @dataProvider getRoutesWithDisabledDefaultRoutes * * @param array $annotations - * @param array $options + * @param array $options */ public function testRoutesWithDisabledDefaultRoutes( string $name, @@ -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..6eed5867a 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}); } @@ -577,8 +567,8 @@ public function provideMergeData(): array 'info' => ['title' => $yes, 'version' => $yes], ], 'assert' => [ - 'info' => ['title' => $yes, 'version' => $no], - ] + $assertDefaults, + 'info' => ['title' => $yes, 'version' => $no], + ] + $assertDefaults, ], [ // Parse server url with variables, see https://github.com/nelmio/NelmioApiDocBundle/issues/1691 'setup' => $setupDefaults, @@ -601,12 +591,12 @@ public function provideMergeData(): array ], [ // indexed collection merge 'setup' => [ - 'components' => $this->createObj(OA\Components::class, [ - 'schemas' => [ - $this->createObj(OA\Schema::class, ['schema' => $no, 'title' => $no]), - ], - ]), - ] + $setupDefaults, + 'components' => $this->createObj(OA\Components::class, [ + 'schemas' => [ + $this->createObj(OA\Schema::class, ['schema' => $no, 'title' => $no]), + ], + ]), + ] + $setupDefaults, 'merge' => [ 'components' => [ 'schemas' => [ @@ -615,17 +605,17 @@ public function provideMergeData(): array ], ], 'assert' => [ - 'components' => [ - 'schemas' => [ - $no => ['title' => $no, 'description' => $yes], - ], + 'components' => [ + 'schemas' => [ + $no => ['title' => $no, 'description' => $yes], ], - ] + $assertDefaults, + ], + ] + $assertDefaults, ], [ // collection merge 'setup' => [ - 'tags' => [$this->createObj(OA\Tag::class, ['name' => $no])], - ] + $setupDefaults, + 'tags' => [$this->createObj(OA\Tag::class, ['name' => $no])], + ] + $setupDefaults, 'merge' => [ 'tags' => [ // this is actually appending right now, no clue if this is wanted, @@ -641,12 +631,12 @@ public function provideMergeData(): array ], ], 'assert' => [ - 'tags' => [ - ['name' => $no], - ['name' => $yes], - ['name' => $no, 'description' => $yes], - ], - ] + $assertDefaults, + 'tags' => [ + ['name' => $no], + ['name' => $yes], + ['name' => $no, 'description' => $yes], + ], + ] + $assertDefaults, ], [ // heavy nested merge array @@ -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(