From 31f9b25e4cf372b43918761cb4362d0bb5b9757a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=93=AD=E6=98=95?= <715557344@qq.com> Date: Sat, 23 Mar 2024 19:28:51 +0800 Subject: [PATCH] Format code by the latest `cs-fixer`. (#6617) --- src/Annotation/AdditionalProperties.php | 1 + src/Annotation/AnnotationTrait.php | 1 + src/Annotation/Attachable.php | 1 + src/Annotation/Components.php | 1 + src/Annotation/Contact.php | 1 + src/Annotation/CookieParameter.php | 1 + src/Annotation/Delete.php | 1 + src/Annotation/Discriminator.php | 1 + src/Annotation/Examples.php | 1 + src/Annotation/ExternalDocumentation.php | 1 + src/Annotation/Flow.php | 1 + src/Annotation/Get.php | 1 + src/Annotation/Head.php | 1 + src/Annotation/Header.php | 1 + src/Annotation/HeaderParameter.php | 1 + src/Annotation/HyperfServer.php | 1 + src/Annotation/Info.php | 1 + src/Annotation/Items.php | 1 + src/Annotation/JsonContent.php | 1 + src/Annotation/License.php | 1 + src/Annotation/Link.php | 1 + src/Annotation/MediaType.php | 1 + src/Annotation/MultipleAnnotationTrait.php | 1 + src/Annotation/OpenApi.php | 1 + src/Annotation/Options.php | 1 + src/Annotation/Parameter.php | 1 + src/Annotation/Patch.php | 1 + src/Annotation/PathItem.php | 1 + src/Annotation/PathParameter.php | 1 + src/Annotation/Post.php | 1 + src/Annotation/Property.php | 7 +++--- src/Annotation/Put.php | 1 + src/Annotation/QueryParameter.php | 5 ++-- src/Annotation/RequestBody.php | 5 ++-- src/Annotation/Response.php | 1 + src/Annotation/Schema.php | 1 + src/Annotation/SecurityScheme.php | 1 + src/Annotation/Server.php | 1 + src/Annotation/ServerVariable.php | 1 + src/Annotation/Tag.php | 1 + src/Annotation/Trace.php | 1 + src/Annotation/Xml.php | 1 + src/Annotation/XmlContent.php | 1 + src/Command/Ast/ModelSchemaVisitor.php | 8 ++++--- src/Command/GenCommand.php | 1 + src/Command/GenSchemaCommand.php | 1 + src/ConfigProvider.php | 1 + src/Exception/RuntimeException.php | 1 + src/Generator.php | 1 + src/HttpServer.php | 1 + src/Listener/BootSwaggerListener.php | 1 + src/Processor/BuildPathsProcessor.php | 27 +++++++++++----------- src/Request/RuleCollector.php | 1 + src/Request/SwaggerRequest.php | 3 ++- src/Request/ValidationCollector.php | 7 ++++-- src/Util.php | 1 + tests/Stub/ExampleController.php | 1 + tests/SwaggerRequestTest.php | 1 + 58 files changed, 86 insertions(+), 27 deletions(-) diff --git a/src/Annotation/AdditionalProperties.php b/src/Annotation/AdditionalProperties.php index 0da9996..096824c 100644 --- a/src/Annotation/AdditionalProperties.php +++ b/src/Annotation/AdditionalProperties.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/AnnotationTrait.php b/src/Annotation/AnnotationTrait.php index 3c99a09..da4aef5 100644 --- a/src/Annotation/AnnotationTrait.php +++ b/src/Annotation/AnnotationTrait.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Hyperf\Di\Annotation\AnnotationCollector; diff --git a/src/Annotation/Attachable.php b/src/Annotation/Attachable.php index b850cb0..d827b1e 100644 --- a/src/Annotation/Attachable.php +++ b/src/Annotation/Attachable.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Components.php b/src/Annotation/Components.php index db8c885..b70612f 100644 --- a/src/Annotation/Components.php +++ b/src/Annotation/Components.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Contact.php b/src/Annotation/Contact.php index fbe8fca..a022e2d 100644 --- a/src/Annotation/Contact.php +++ b/src/Annotation/Contact.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/CookieParameter.php b/src/Annotation/CookieParameter.php index 2bf7614..207ebac 100644 --- a/src/Annotation/CookieParameter.php +++ b/src/Annotation/CookieParameter.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Delete.php b/src/Annotation/Delete.php index d885c4e..72c1ec3 100644 --- a/src/Annotation/Delete.php +++ b/src/Annotation/Delete.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Discriminator.php b/src/Annotation/Discriminator.php index 7aa30b8..cb8ce2d 100644 --- a/src/Annotation/Discriminator.php +++ b/src/Annotation/Discriminator.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Examples.php b/src/Annotation/Examples.php index cc8b7f6..bbc7bba 100644 --- a/src/Annotation/Examples.php +++ b/src/Annotation/Examples.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/ExternalDocumentation.php b/src/Annotation/ExternalDocumentation.php index 3db1a63..5f1e712 100644 --- a/src/Annotation/ExternalDocumentation.php +++ b/src/Annotation/ExternalDocumentation.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Flow.php b/src/Annotation/Flow.php index 113a804..b3cb675 100644 --- a/src/Annotation/Flow.php +++ b/src/Annotation/Flow.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Get.php b/src/Annotation/Get.php index 74fe4bb..09f3a1b 100644 --- a/src/Annotation/Get.php +++ b/src/Annotation/Get.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Head.php b/src/Annotation/Head.php index ac5f605..23bfbc1 100644 --- a/src/Annotation/Head.php +++ b/src/Annotation/Head.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Header.php b/src/Annotation/Header.php index 6c69850..ffa72c7 100644 --- a/src/Annotation/Header.php +++ b/src/Annotation/Header.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/HeaderParameter.php b/src/Annotation/HeaderParameter.php index b249e63..8a1d34d 100644 --- a/src/Annotation/HeaderParameter.php +++ b/src/Annotation/HeaderParameter.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/HyperfServer.php b/src/Annotation/HyperfServer.php index 4022621..09ecf48 100644 --- a/src/Annotation/HyperfServer.php +++ b/src/Annotation/HyperfServer.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Info.php b/src/Annotation/Info.php index aeaa08e..ed5429e 100644 --- a/src/Annotation/Info.php +++ b/src/Annotation/Info.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Items.php b/src/Annotation/Items.php index 742c94f..aba116e 100644 --- a/src/Annotation/Items.php +++ b/src/Annotation/Items.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/JsonContent.php b/src/Annotation/JsonContent.php index 7073a75..e70f7ec 100644 --- a/src/Annotation/JsonContent.php +++ b/src/Annotation/JsonContent.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/License.php b/src/Annotation/License.php index 9e8ac9e..5064b1f 100644 --- a/src/Annotation/License.php +++ b/src/Annotation/License.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Link.php b/src/Annotation/Link.php index 5bf3006..3305fdb 100644 --- a/src/Annotation/Link.php +++ b/src/Annotation/Link.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/MediaType.php b/src/Annotation/MediaType.php index 7e00e2c..0f907ba 100644 --- a/src/Annotation/MediaType.php +++ b/src/Annotation/MediaType.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/MultipleAnnotationTrait.php b/src/Annotation/MultipleAnnotationTrait.php index adc9534..204649e 100644 --- a/src/Annotation/MultipleAnnotationTrait.php +++ b/src/Annotation/MultipleAnnotationTrait.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Hyperf\Di\Annotation\AnnotationCollector; diff --git a/src/Annotation/OpenApi.php b/src/Annotation/OpenApi.php index 09cb018..5e73f8b 100644 --- a/src/Annotation/OpenApi.php +++ b/src/Annotation/OpenApi.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Options.php b/src/Annotation/Options.php index cabe9ae..58f9276 100644 --- a/src/Annotation/Options.php +++ b/src/Annotation/Options.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Parameter.php b/src/Annotation/Parameter.php index da5917b..4e121bd 100644 --- a/src/Annotation/Parameter.php +++ b/src/Annotation/Parameter.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Patch.php b/src/Annotation/Patch.php index bca2446..5e51aa7 100644 --- a/src/Annotation/Patch.php +++ b/src/Annotation/Patch.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/PathItem.php b/src/Annotation/PathItem.php index 4d772c1..2feff9b 100644 --- a/src/Annotation/PathItem.php +++ b/src/Annotation/PathItem.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/PathParameter.php b/src/Annotation/PathParameter.php index aa83af6..7529211 100644 --- a/src/Annotation/PathParameter.php +++ b/src/Annotation/PathParameter.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Post.php b/src/Annotation/Post.php index 7b476a8..6712d15 100644 --- a/src/Annotation/Post.php +++ b/src/Annotation/Post.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Property.php b/src/Annotation/Property.php index 446c8b7..55ffeec 100644 --- a/src/Annotation/Property.php +++ b/src/Annotation/Property.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; @@ -24,7 +25,7 @@ class Property extends \OpenApi\Attributes\Property { public function __construct( ?string $property = null, - object|string|null $ref = null, + null|object|string $ref = null, ?string $schema = null, ?string $title = null, ?string $description = null, @@ -47,7 +48,7 @@ public function __construct( ?int $minItems = null, ?bool $uniqueItems = null, ?string $pattern = null, - array|string|null $enum = null, + null|array|string $enum = null, ?Discriminator $discriminator = null, ?bool $readOnly = null, ?bool $writeOnly = null, @@ -59,7 +60,7 @@ public function __construct( ?array $allOf = null, ?array $anyOf = null, ?array $oneOf = null, - AdditionalProperties|bool|null $additionalProperties = null, + null|AdditionalProperties|bool $additionalProperties = null, ?array $x = null, ?array $attachables = null, public mixed $rules = null, diff --git a/src/Annotation/Put.php b/src/Annotation/Put.php index bfa50fd..1fd4e94 100644 --- a/src/Annotation/Put.php +++ b/src/Annotation/Put.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/QueryParameter.php b/src/Annotation/QueryParameter.php index 92cc582..cab465b 100644 --- a/src/Annotation/QueryParameter.php +++ b/src/Annotation/QueryParameter.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; @@ -32,11 +33,11 @@ public function __construct( ?bool $required = null, ?bool $deprecated = null, ?bool $allowEmptyValue = null, - object|string|null $ref = null, + null|object|string $ref = null, ?Schema $schema = null, mixed $example = Generator::UNDEFINED, ?array $examples = null, - JsonContent|array|Attachable|XmlContent|null $content = null, + null|array|Attachable|JsonContent|XmlContent $content = null, ?string $style = null, ?bool $explode = null, ?bool $allowReserved = null, diff --git a/src/Annotation/RequestBody.php b/src/Annotation/RequestBody.php index 85bdb19..e2e7ec3 100644 --- a/src/Annotation/RequestBody.php +++ b/src/Annotation/RequestBody.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; @@ -25,11 +26,11 @@ class RequestBody extends \OpenApi\Attributes\RequestBody implements AnnotationI public mixed $_content = null; public function __construct( - object|string|null $ref = null, + null|object|string $ref = null, ?string $request = null, ?string $description = null, ?bool $required = null, - JsonContent|array|Attachable|XmlContent|null $content = null, + null|array|Attachable|JsonContent|XmlContent $content = null, ?array $x = null, ?array $attachables = null ) { diff --git a/src/Annotation/Response.php b/src/Annotation/Response.php index 7e9d6e4..3f189bf 100644 --- a/src/Annotation/Response.php +++ b/src/Annotation/Response.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Schema.php b/src/Annotation/Schema.php index 64bab52..1242fe9 100644 --- a/src/Annotation/Schema.php +++ b/src/Annotation/Schema.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/SecurityScheme.php b/src/Annotation/SecurityScheme.php index ab5cfba..cae2021 100644 --- a/src/Annotation/SecurityScheme.php +++ b/src/Annotation/SecurityScheme.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Server.php b/src/Annotation/Server.php index 58803bb..aa5d362 100644 --- a/src/Annotation/Server.php +++ b/src/Annotation/Server.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/ServerVariable.php b/src/Annotation/ServerVariable.php index c224025..a4880c9 100644 --- a/src/Annotation/ServerVariable.php +++ b/src/Annotation/ServerVariable.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Tag.php b/src/Annotation/Tag.php index 993b0ba..93b56de 100644 --- a/src/Annotation/Tag.php +++ b/src/Annotation/Tag.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Trace.php b/src/Annotation/Trace.php index 1e5d87c..d4f6baf 100644 --- a/src/Annotation/Trace.php +++ b/src/Annotation/Trace.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/Xml.php b/src/Annotation/Xml.php index 9580768..2608add 100644 --- a/src/Annotation/Xml.php +++ b/src/Annotation/Xml.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Annotation/XmlContent.php b/src/Annotation/XmlContent.php index 19893c6..bff6b4d 100644 --- a/src/Annotation/XmlContent.php +++ b/src/Annotation/XmlContent.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Annotation; use Attribute; diff --git a/src/Command/Ast/ModelSchemaVisitor.php b/src/Command/Ast/ModelSchemaVisitor.php index 52a5f64..722ab6f 100644 --- a/src/Command/Ast/ModelSchemaVisitor.php +++ b/src/Command/Ast/ModelSchemaVisitor.php @@ -9,10 +9,11 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Command\Ast; +use Hyperf\Database\Connection; use Hyperf\Database\Model\Model; -use Hyperf\Database\Schema\Builder; use Hyperf\Database\Schema\Column; use Hyperf\Stringable\Str; use PhpParser\Node; @@ -28,8 +29,9 @@ class ModelSchemaVisitor extends NodeVisitorAbstract public function __construct(public ReflectionClass $ref, public Model $model) { - /** @var Builder $builder */ - $builder = $this->model->getConnection()->getSchemaBuilder(); + /** @var Connection $connection */ + $connection = $this->model->getConnection(); + $builder = $connection->getSchemaBuilder(); $this->columns = array_filter($builder->getColumns(), function (Column $column) { return $column->getTable() === $this->model->getTable(); diff --git a/src/Command/GenCommand.php b/src/Command/GenCommand.php index 5b39b96..7eb39d0 100644 --- a/src/Command/GenCommand.php +++ b/src/Command/GenCommand.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Command; use Hyperf\Command\Command as HyperfCommand; diff --git a/src/Command/GenSchemaCommand.php b/src/Command/GenSchemaCommand.php index ebb80d1..c613eda 100644 --- a/src/Command/GenSchemaCommand.php +++ b/src/Command/GenSchemaCommand.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Command; use Hyperf\Command\Command as HyperfCommand; diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 33aca99..f8a3834 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger; use Hyperf\Swagger\Command\GenCommand; diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php index c3d1dee..9911658 100644 --- a/src/Exception/RuntimeException.php +++ b/src/Exception/RuntimeException.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Exception; class RuntimeException extends \RuntimeException diff --git a/src/Generator.php b/src/Generator.php index b9be3f7..d7a59d8 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger; use Hyperf\Codec\Json; diff --git a/src/HttpServer.php b/src/HttpServer.php index 234eb2d..c721deb 100644 --- a/src/HttpServer.php +++ b/src/HttpServer.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger; use Hyperf\Codec\Json; diff --git a/src/Listener/BootSwaggerListener.php b/src/Listener/BootSwaggerListener.php index e7e3bea..8c71462 100644 --- a/src/Listener/BootSwaggerListener.php +++ b/src/Listener/BootSwaggerListener.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Listener; use Hyperf\Contract\ConfigInterface; diff --git a/src/Processor/BuildPathsProcessor.php b/src/Processor/BuildPathsProcessor.php index af7e467..fad0708 100644 --- a/src/Processor/BuildPathsProcessor.php +++ b/src/Processor/BuildPathsProcessor.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Processor; use Hyperf\Di\Annotation\AnnotationCollector; @@ -44,7 +45,7 @@ public function __invoke(Analysis $analysis) // Merge @OA\Operations into existing @OA\PathItems or create a new one. foreach ($operations as $operation) { $class = $operation->_context->namespace . '\\' . $operation->_context->class; - /** @var HyperfServer $serverAnnotation */ + /** @var null|HyperfServer $serverAnnotation */ $serverAnnotation = AnnotationCollector::getClassAnnotation($class, HyperfServer::class); if (! $serverAnnotation) { continue; @@ -52,19 +53,17 @@ public function __invoke(Analysis $analysis) $path = $serverAnnotation->name . '|' . $operation->path; - if ($path) { - if (empty($paths[$path])) { - $paths[$path] = $pathItem = new OA\PathItem( - [ - 'path' => $path, - '_context' => new Context(['generated' => true], $operation->_context), - ] - ); - $analysis->addAnnotation($pathItem, $pathItem->_context); - } - if ($paths[$path]->merge([$operation])) { - $operation->_context->logger->warning('Unable to merge ' . $operation->identity() . ' in ' . $operation->_context); - } + if (empty($paths[$path])) { + $paths[$path] = $pathItem = new OA\PathItem( + [ + 'path' => $path, + '_context' => new Context(['generated' => true], $operation->_context), + ] + ); + $analysis->addAnnotation($pathItem, $pathItem->_context); + } + if ($paths[$path]->merge([$operation])) { + $operation->_context->logger->warning('Unable to merge ' . $operation->identity() . ' in ' . $operation->_context); } } if ($paths) { diff --git a/src/Request/RuleCollector.php b/src/Request/RuleCollector.php index afe885d..1f04588 100644 --- a/src/Request/RuleCollector.php +++ b/src/Request/RuleCollector.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Request; /** diff --git a/src/Request/SwaggerRequest.php b/src/Request/SwaggerRequest.php index cc46b67..1c56f49 100644 --- a/src/Request/SwaggerRequest.php +++ b/src/Request/SwaggerRequest.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Request; use Hyperf\Context\RequestContext; @@ -45,7 +46,7 @@ public function attributes(): array protected function getCallbackByContext(): array { - /** @var Dispatched $dispatched */ + /** @var null|Dispatched $dispatched */ $dispatched = RequestContext::getOrNull()?->getAttribute(Dispatched::class); if (! $dispatched) { throw new RuntimeException('The request is invalid.'); diff --git a/src/Request/ValidationCollector.php b/src/Request/ValidationCollector.php index 73407af..49acf68 100644 --- a/src/Request/ValidationCollector.php +++ b/src/Request/ValidationCollector.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger\Request; use Hyperf\Di\Annotation\AnnotationCollector; @@ -57,7 +58,7 @@ protected static function collectQueryParameter($methodAnnotations, array $data, protected static function collectJsonContentRequestBody($methodAnnotations, array $data, string $field): array { - /** @var RequestBody $body */ + /** @var null|RequestBody $body */ $body = Util::findAnnotations($methodAnnotations, RequestBody::class)[0] ?? null; if (! $body) { return $data; @@ -84,7 +85,7 @@ protected static function collectJsonContentRequestBody($methodAnnotations, arra protected static function collectMediaTypeRequestBody($methodAnnotations, array $data, string $field): array { - /** @var RequestBody $body */ + /** @var null|RequestBody $body */ $body = Util::findAnnotations($methodAnnotations, RequestBody::class)[0] ?? null; if (! $body || ! is_array($body->content)) { return $data; @@ -94,6 +95,8 @@ protected static function collectMediaTypeRequestBody($methodAnnotations, array if (! $content instanceof MediaType) { continue; } + + /* @phpstan-ignore-next-line */ if (! $content->schema || ! is_array($content->schema->properties)) { continue; } diff --git a/src/Util.php b/src/Util.php index 820d2ee..25b7b90 100644 --- a/src/Util.php +++ b/src/Util.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace Hyperf\Swagger; use Hyperf\Di\Annotation\MultipleAnnotation; diff --git a/tests/Stub/ExampleController.php b/tests/Stub/ExampleController.php index 17caed9..ff9dccd 100644 --- a/tests/Stub/ExampleController.php +++ b/tests/Stub/ExampleController.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace HyperfTest\Swagger\Stub; use Hyperf\Swagger\Annotation as SA; diff --git a/tests/SwaggerRequestTest.php b/tests/SwaggerRequestTest.php index 077ad32..51a562b 100644 --- a/tests/SwaggerRequestTest.php +++ b/tests/SwaggerRequestTest.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + namespace HyperfTest\Swagger; /*