From 921e5ddea2d122b89c1d3713baa01929679d9b57 Mon Sep 17 00:00:00 2001 From: Chris Nizzardini Date: Sun, 7 Jan 2024 12:54:42 -0500 Subject: [PATCH 1/2] update deps and fix static analysis warnings --- composer.json | 14 +++-------- src/Command/BakeCommand.php | 9 ++----- src/Command/InstallCommand.php | 8 ++----- src/Command/ModelCommand.php | 8 ++----- src/Command/RouteCommand.php | 8 ++----- src/Controller/SwaggerController.php | 3 ++- .../Attribute/AbstractOpenApiParameter.php | 2 +- src/Lib/Attribute/AttributeFactory.php | 21 +++++++++------- src/Lib/Attribute/OpenApiHeader.php | 2 +- src/Lib/Attribute/OpenApiOperation.php | 2 +- src/Lib/Attribute/OpenApiPath.php | 2 +- src/Lib/Attribute/OpenApiQueryParam.php | 2 +- src/Lib/Configuration.php | 24 ++++++++++--------- .../Exception/SwaggerBakeRunTimeException.php | 2 +- src/Lib/Extension/CakeSearch/Extension.php | 9 +++---- src/Lib/ExtensionLoader.php | 6 +++-- src/Lib/MediaType/HalJson.php | 2 +- src/Lib/MediaType/JsonLd.php | 2 +- src/Lib/Model/ModelScanner.php | 7 +++--- src/Lib/OpenApi/Operation.php | 16 ++++++------- src/Lib/OpenApi/Parameter.php | 8 +++---- src/Lib/OpenApi/Path.php | 10 ++++---- src/Lib/OpenApi/PathSecurity.php | 7 +++--- src/Lib/OpenApi/RequestBody.php | 4 ++-- src/Lib/OpenApi/Response.php | 6 ++--- src/Lib/OpenApi/Schema.php | 9 +++---- src/Lib/OpenApi/SchemaProperty.php | 6 ++--- src/Lib/OpenApi/SchemaTrait.php | 2 +- src/Lib/OpenApi/Xml.php | 10 ++++---- src/Lib/OpenApiSchemaGenerator.php | 3 ++- src/Lib/Operation/DtoParser.php | 8 +++---- src/Lib/Operation/ExceptionResponse.php | 2 +- .../Operation/OperationFromRouteFactory.php | 6 ++--- src/Lib/Operation/OperationHeader.php | 2 +- src/Lib/Operation/OperationPathParameter.php | 2 +- src/Lib/Operation/OperationQueryParameter.php | 7 +++--- src/Lib/Operation/OperationRequestBody.php | 4 ++-- src/Lib/Operation/OperationResponse.php | 2 +- src/Lib/Route/RouteDecorator.php | 5 ++-- src/Lib/Route/RouteScanner.php | 6 ++--- src/Lib/Schema/SchemaFactory.php | 9 +++---- src/Lib/Schema/SchemaPropertyFactory.php | 2 +- src/Lib/Schema/SchemaPropertyValidation.php | 9 +++---- src/Lib/Service/OpenApiBakerService.php | 2 +- src/Lib/Swagger.php | 6 ++--- src/Lib/Utility/DocBlockUtility.php | 3 ++- src/Lib/Utility/NamespaceUtility.php | 7 +++--- src/Lib/Utility/OpenApiDataType.php | 2 +- 48 files changed, 146 insertions(+), 152 deletions(-) diff --git a/composer.json b/composer.json index 772c4337..1ebbbba3 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "cakephp/cakephp": "^5.0", "symfony/yaml": "^5.0", "phpdocumentor/reflection-docblock": "^5.1", - "mixerapi/core": "dev-cakephp-5" + "mixerapi/core": "^2.0" }, "suggest": { "cakephp/bake": "Used by SwaggerBake bake templates", @@ -27,7 +27,7 @@ "phpunit/phpunit": "^10.0", "friendsofcake/search": "^7.0", "cakephp/authentication": "^3.0", - "cakephp/cakephp-codesniffer": "^4.2", + "cakephp/cakephp-codesniffer": "^5.0", "phpstan/phpstan": "^1.8.5", "phpmd/phpmd": "^2.10", "cakephp/bake": "^3.0", @@ -78,13 +78,5 @@ "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true } - }, - "repositories": [ - { - "type": "vcs", - "url": "git@github.com:cnizzardini/core.git" - } - ], - "minimum-stability": "dev", - "prefer-stable": true + } } diff --git a/src/Command/BakeCommand.php b/src/Command/BakeCommand.php index 1927b0ed..5d827056 100644 --- a/src/Command/BakeCommand.php +++ b/src/Command/BakeCommand.php @@ -47,14 +47,9 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption } /** - * Writes a swagger.json file - * - * @param \Cake\Console\Arguments $args Arguments - * @param \Cake\Console\ConsoleIo $io ConsoleIo - * @return int|void|null - * @throws \ReflectionException + * @inheritDoc */ - public function execute(Arguments $args, ConsoleIo $io) + public function execute(Arguments $args, ConsoleIo $io): void { $this->loadConfig($args); $io->out('Running...'); diff --git a/src/Command/InstallCommand.php b/src/Command/InstallCommand.php index e6eff17c..d0710fd9 100644 --- a/src/Command/InstallCommand.php +++ b/src/Command/InstallCommand.php @@ -31,13 +31,9 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption } /** - * Writes a swagger.json file - * - * @param \Cake\Console\Arguments $args Arguments - * @param \Cake\Console\ConsoleIo $io ConsoleIo - * @return int|void|null + * @inheritDoc */ - public function execute(Arguments $args, ConsoleIo $io) + public function execute(Arguments $args, ConsoleIo $io): void { $io->hr(); $io->out('| SwaggerBake Install'); diff --git a/src/Command/ModelCommand.php b/src/Command/ModelCommand.php index 55c834c0..2e3fd4c7 100644 --- a/src/Command/ModelCommand.php +++ b/src/Command/ModelCommand.php @@ -44,13 +44,9 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption } /** - * List Cake Entities that can be added to Swagger. Prints to console. - * - * @param \Cake\Console\Arguments $args Arguments - * @param \Cake\Console\ConsoleIo $io ConsoleIo - * @return int|void|null + * @inheritDoc */ - public function execute(Arguments $args, ConsoleIo $io) + public function execute(Arguments $args, ConsoleIo $io): void { $this->loadConfig($args); diff --git a/src/Command/RouteCommand.php b/src/Command/RouteCommand.php index 8bc5fb9a..095eb2cb 100644 --- a/src/Command/RouteCommand.php +++ b/src/Command/RouteCommand.php @@ -40,13 +40,9 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption } /** - * List Cake Routes that can be added to Swagger. Prints to console. - * - * @param \Cake\Console\Arguments $args Arguments - * @param \Cake\Console\ConsoleIo $io ConsoleIo - * @return int|void|null + * @inheritDoc */ - public function execute(Arguments $args, ConsoleIo $io) + public function execute(Arguments $args, ConsoleIo $io): void { $this->loadConfig($args); diff --git a/src/Controller/SwaggerController.php b/src/Controller/SwaggerController.php index 35075c85..338cf3f0 100644 --- a/src/Controller/SwaggerController.php +++ b/src/Controller/SwaggerController.php @@ -4,6 +4,7 @@ namespace SwaggerBake\Controller; use Cake\Controller\Controller; +use Cake\Http\Response; use SwaggerBake\Lib\Service\OpenApiControllerService; class SwaggerController extends Controller @@ -14,7 +15,7 @@ class SwaggerController extends Controller * @param \SwaggerBake\Lib\Service\OpenApiControllerService $service Builds OpenAPI JSON and hot reloads if enabled * @return \Cake\Http\Response Renders view */ - public function index(OpenApiControllerService $service) + public function index(OpenApiControllerService $service): Response { /* * Rebuild OpenAPI if hotReload is enabled diff --git a/src/Lib/Attribute/AbstractOpenApiParameter.php b/src/Lib/Attribute/AbstractOpenApiParameter.php index 9329f14b..d110f2d9 100644 --- a/src/Lib/Attribute/AbstractOpenApiParameter.php +++ b/src/Lib/Attribute/AbstractOpenApiParameter.php @@ -23,7 +23,7 @@ abstract class AbstractOpenApiParameter * @param string $type The data scalar type (e.g. string, integer) * @param string $format The data format (e.g. data-time, uuid) * @param string $description A description of the parameter - * @param string|bool|int|float $example An example scalar value of the parameter + * @param string|float|int|bool $example An example scalar value of the parameter * @param bool $isRequired Is the parameter required? * @param array $enum An enumerated list of values. * @param bool $isDeprecated Is the parameter deprecated? diff --git a/src/Lib/Attribute/AttributeFactory.php b/src/Lib/Attribute/AttributeFactory.php index 0b9313fa..3ed70ce0 100644 --- a/src/Lib/Attribute/AttributeFactory.php +++ b/src/Lib/Attribute/AttributeFactory.php @@ -3,22 +3,17 @@ namespace SwaggerBake\Lib\Attribute; -use ReflectionClass; -use ReflectionClassConstant; -use ReflectionFunction; -use ReflectionMethod; -use ReflectionParameter; -use ReflectionProperty; +use Reflector; +use SwaggerBake\Lib\Exception\SwaggerBakeRunTimeException; final class AttributeFactory { /** - * @param \ReflectionClass|\ReflectionClassConstant|\ReflectionFunction|\ReflectionMethod|\ReflectionParameter|\ReflectionProperty $reflection The reflection + * @param \Reflector $reflection The reflection * @param string $attributeClass Your Attribute class */ public function __construct( - private ReflectionClass|ReflectionClassConstant|ReflectionFunction|ReflectionMethod|ReflectionParameter| - ReflectionProperty $reflection, + private Reflector $reflection, private string $attributeClass ) { } @@ -31,6 +26,10 @@ public function __construct( */ public function createOneOrNull(): ?object { + if (!method_exists($this->reflection, 'getAttributes')) { + throw new SwaggerBakeRunTimeException('Reflected instance does not have getAttributes method'); + } + $attributes = $this->reflection->getAttributes($this->attributeClass); if (empty($attributes)) { return null; @@ -52,6 +51,10 @@ public function createOneOrNull(): ?object */ public function createMany(): array { + if (!method_exists($this->reflection, 'getAttributes')) { + throw new SwaggerBakeRunTimeException('Reflected instance does not have getAttributes method'); + } + $attributes = $this->reflection->getAttributes($this->attributeClass); foreach ($attributes as $attr) { diff --git a/src/Lib/Attribute/OpenApiHeader.php b/src/Lib/Attribute/OpenApiHeader.php index 617778e0..48c9a9c4 100644 --- a/src/Lib/Attribute/OpenApiHeader.php +++ b/src/Lib/Attribute/OpenApiHeader.php @@ -26,7 +26,7 @@ class OpenApiHeader * for each value of the array or key-value pair of the map. * @param string $style Describes how the parameter value will be serialized depending on the type of the parameter * value. - * @param string|bool|int $example Example of the parameter’s potential value. The example SHOULD match the specified schema + * @param string|int|bool $example Example of the parameter’s potential value. The example SHOULD match the specified schema * and encoding properties if present. * @param bool $allowEmptyValue Are empty values allowed? * @SuppressWarnings(PHPMD.ExcessiveParameterList) diff --git a/src/Lib/Attribute/OpenApiOperation.php b/src/Lib/Attribute/OpenApiOperation.php index c0c653fb..56d4abe5 100644 --- a/src/Lib/Attribute/OpenApiOperation.php +++ b/src/Lib/Attribute/OpenApiOperation.php @@ -15,7 +15,7 @@ class OpenApiOperation * @param string|null $summary A summary (i.e. title), setting to null prevents summary being set from doc blocks * @param string|null $description A description, setting to null prevents description being set from doc blocks * @param bool $isVisible Is this operation visible - * @param string[] $tagNames An array of OpenAPI tags + * @param array $tagNames An array of OpenAPI tags * @param bool $isDeprecated Is the operation deprecated? * @param array|null $externalDocs An optional external docs array * @param int|null $sortOrder The order the operation appears at in OpenAPI output. Defaults to the order the action diff --git a/src/Lib/Attribute/OpenApiPath.php b/src/Lib/Attribute/OpenApiPath.php index f4c6eb04..3e1f837c 100644 --- a/src/Lib/Attribute/OpenApiPath.php +++ b/src/Lib/Attribute/OpenApiPath.php @@ -15,7 +15,7 @@ class OpenApiPath * @param string|null $ref An OpenAPI ref such as `#/paths/my-path` * @param string|null $summary Overwrites the default summary (if any) * @param string|null $description Overwrites the default description - * @param string[] $tags Sets the tags for all operations in the path. Tags set on individual operations will take + * @param array $tags Sets the tags for all operations in the path. Tags set on individual operations will take * precedence. * @see https://spec.openapis.org/oas/latest.html#path-item-object * @SuppressWarnings(PHPMD.BooleanArgumentFlag) diff --git a/src/Lib/Attribute/OpenApiQueryParam.php b/src/Lib/Attribute/OpenApiQueryParam.php index f416b284..d8a3be65 100644 --- a/src/Lib/Attribute/OpenApiQueryParam.php +++ b/src/Lib/Attribute/OpenApiQueryParam.php @@ -27,7 +27,7 @@ class OpenApiQueryParam * value. * @param string $style Example of the parameter’s potential value. The example SHOULD match the specified schema * and encoding properties if present. - * @param string|bool|int $example The expected format of the type, for instance date-time. + * @param string|int|bool $example The expected format of the type, for instance date-time. * @param bool $allowEmptyValue Are empty values allowed? * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ diff --git a/src/Lib/Configuration.php b/src/Lib/Configuration.php index 3117135a..b8d6a516 100644 --- a/src/Lib/Configuration.php +++ b/src/Lib/Configuration.php @@ -7,6 +7,8 @@ use Cake\Datasource\ConnectionManager; use InvalidArgumentException; use LogicException; +use RuntimeException; +use SwaggerBake\Lib\Exception\SwaggerBakeRunTimeException; use Symfony\Component\Yaml\Yaml; /** @@ -58,12 +60,12 @@ class Configuration protected string $exceptionSchema = 'Exception'; /** - * @var string[] The requested mimetypes accepted by your API. + * @var array The requested mimetypes accepted by your API. */ protected array $requestAccepts = ['application/json']; /** - * @var string[] The mimetypes your API responds with. + * @var array The mimetypes your API responds with. */ protected array $responseContentTypes = ['application/json']; @@ -74,7 +76,7 @@ class Configuration protected int $jsonOptions = JSON_PRETTY_PRINT; /** - * @var string[] The HTTP methods implemented for edit() actions. + * @var array The HTTP methods implemented for edit() actions. */ protected array $editActionMethods = ['PATCH']; @@ -103,8 +105,8 @@ public function __construct(array $config = [], string $root = ROOT) $this->root = $root; try { $config = !empty($config) ? $config : Configure::readOrFail('SwaggerBake'); - } catch (\RuntimeException $e) { - throw new \SwaggerBake\Lib\Exception\SwaggerBakeRunTimeException( + } catch (RuntimeException $e) { + throw new SwaggerBakeRunTimeException( 'SwaggerBake config missing. Have you added it to your `config/bootstrap.php`? ' . $e->getMessage(), 500, $e @@ -125,7 +127,7 @@ public function __construct(array $config = [], string $root = ROOT) } $setter = 'set' . ucfirst($property); if (!method_exists($this, $setter)) { - throw new \LogicException( + throw new LogicException( sprintf( 'Method %s does not exist in class %s but is trying to be called.', $setter, @@ -376,7 +378,7 @@ public function getParsedYml(): array /** * @return mixed|string */ - public function getTitleFromYml() + public function getTitleFromYml(): mixed { $yml = $this->getParsedYml(); @@ -420,7 +422,7 @@ public function getRequestAccepts(): array } /** - * @param string[] $requestAccepts The requested mimetypes accepted by your API. + * @param array $requestAccepts The requested mimetypes accepted by your API. * @return $this */ public function setRequestAccepts(array $requestAccepts) @@ -439,7 +441,7 @@ public function getResponseContentTypes(): array } /** - * @param string[] $responseContentTypes The mimetypes your API responds with. + * @param array $responseContentTypes The mimetypes your API responds with. * @return $this */ public function setResponseContentTypes(array $responseContentTypes) @@ -501,7 +503,7 @@ public function setConnectionName(string $connectionName) } /** - * @return string[] + * @return array */ public function getEditActionMethods(): array { @@ -509,7 +511,7 @@ public function getEditActionMethods(): array } /** - * @param string[] $editActionMethods Valid types are POST, PUT, and PATCH. + * @param array $editActionMethods Valid types are POST, PUT, and PATCH. * @return $this */ public function setEditActionMethods(array $editActionMethods) diff --git a/src/Lib/Exception/SwaggerBakeRunTimeException.php b/src/Lib/Exception/SwaggerBakeRunTimeException.php index 432c40ab..1de27720 100644 --- a/src/Lib/Exception/SwaggerBakeRunTimeException.php +++ b/src/Lib/Exception/SwaggerBakeRunTimeException.php @@ -24,7 +24,7 @@ class SwaggerBakeRunTimeException extends CakeException * @param int|null $code The error code * @param \Throwable|null $previous the previous exception. */ - public function __construct($message = '', ?int $code = null, ?Throwable $previous = null) + public function __construct(array|string $message = '', ?int $code = null, ?Throwable $previous = null) { parent::__construct($message, $code, $previous); } diff --git a/src/Lib/Extension/CakeSearch/Extension.php b/src/Lib/Extension/CakeSearch/Extension.php index ec56216e..ebb960f7 100644 --- a/src/Lib/Extension/CakeSearch/Extension.php +++ b/src/Lib/Extension/CakeSearch/Extension.php @@ -9,6 +9,7 @@ use Cake\ORM\Locator\LocatorAwareTrait; use Cake\ORM\Table; use ReflectionMethod; +use Search\Manager; use SwaggerBake\Lib\Attribute\AttributeFactory; use SwaggerBake\Lib\Exception\SwaggerBakeRunTimeException; use SwaggerBake\Lib\Extension\CakeSearch\Attribute\OpenApiSearch; @@ -41,8 +42,8 @@ public static function create(): object public function registerListeners(): void { EventManager::instance() - ->on('SwaggerBake.Operation.created', function (Event $event) { - $operation = $this->getOperation($event); + ->on('SwaggerBake.Operation.created', function (Event $event): void { + $operation = $this->getOperation($event); // phpcs:ignore }); } @@ -131,7 +132,7 @@ private function createParameter(FilterDecorator $filter): Parameter /** * @param \Cake\ORM\Table $table Table * @param \SwaggerBake\Lib\Extension\CakeSearch\Attribute\OpenApiSearch $openApiSearch OpenApiSearch - * @return \SwaggerBake\Lib\Extension\CakeSearch\FilterDecorator[] + * @return array<\SwaggerBake\Lib\Extension\CakeSearch\FilterDecorator> * @throws \ReflectionException */ private function getFilterDecorators(Table $table, OpenApiSearch $openApiSearch): array @@ -152,7 +153,7 @@ private function getFilterDecorators(Table $table, OpenApiSearch $openApiSearch) * @param \Cake\ORM\Table $table Table * @return \Search\Manager */ - private function getSearchManager(Table $table): \Search\Manager + private function getSearchManager(Table $table): Manager { if (!$table->hasBehavior('Search')) { throw new SwaggerBakeRunTimeException(sprintf( diff --git a/src/Lib/ExtensionLoader.php b/src/Lib/ExtensionLoader.php index d3e0ed08..04cdcfd8 100644 --- a/src/Lib/ExtensionLoader.php +++ b/src/Lib/ExtensionLoader.php @@ -3,17 +3,19 @@ namespace SwaggerBake\Lib; +use SwaggerBake\Lib\Extension\CakeSearch\Extension; + class ExtensionLoader { /** * Returns a list of Extensions * - * @return object[] + * @return array */ private static function extensions(): array { return [ - \SwaggerBake\Lib\Extension\CakeSearch\Extension::create(), + Extension::create(), ]; } diff --git a/src/Lib/MediaType/HalJson.php b/src/Lib/MediaType/HalJson.php index 6c07401f..fe6614fc 100755 --- a/src/Lib/MediaType/HalJson.php +++ b/src/Lib/MediaType/HalJson.php @@ -97,7 +97,7 @@ private function item(Schema|string $schema): Schema /** * @todo this method needs to actually be recursive - * @param \SwaggerBake\Lib\OpenApi\SchemaProperty[] $properties an array of SchemaProperty + * @param array<\SwaggerBake\Lib\OpenApi\SchemaProperty> $properties an array of SchemaProperty * @return array */ private function recursion(array $properties): array diff --git a/src/Lib/MediaType/JsonLd.php b/src/Lib/MediaType/JsonLd.php index 4db8c2c9..44e2f510 100755 --- a/src/Lib/MediaType/JsonLd.php +++ b/src/Lib/MediaType/JsonLd.php @@ -97,7 +97,7 @@ private function item(Schema|string $schema): Schema /** * @todo this method needs to actually be recursive - * @param \SwaggerBake\Lib\OpenApi\SchemaProperty[] $properties an array of SchemaProperty + * @param array<\SwaggerBake\Lib\OpenApi\SchemaProperty> $properties an array of SchemaProperty * @return array */ private function recursion(array $properties): array diff --git a/src/Lib/Model/ModelScanner.php b/src/Lib/Model/ModelScanner.php index 77713c3e..b6970750 100644 --- a/src/Lib/Model/ModelScanner.php +++ b/src/Lib/Model/ModelScanner.php @@ -8,6 +8,7 @@ use Cake\Datasource\ConnectionManager; use Cake\ORM\Locator\LocatorAwareTrait; use Cake\ORM\Table; +use Exception; use MixerApi\Core\Model\Model; use MixerApi\Core\Model\ModelFactory; use MixerApi\Core\Utility\NamespaceUtility; @@ -39,7 +40,7 @@ public function __construct( /** * Gets an array of ModelDecorator instances if the model is associated with a route and that route is visible. * - * @return \SwaggerBake\Lib\Model\ModelDecorator[] + * @return array<\SwaggerBake\Lib\Model\ModelDecorator> * @throws \ReflectionException */ public function getModelDecorators(): array @@ -56,7 +57,7 @@ public function getModelDecorators(): array if (!class_exists($table)) { continue; } - $reflection = new \ReflectionClass($table); + $reflection = new ReflectionClass($table); if (!$reflection->isInstantiable() || !$reflection->isSubclassOf(Table::class)) { continue; } @@ -66,7 +67,7 @@ public function getModelDecorators(): array } $tableInstance = $this->getTableLocator()->get($class); $model = (new ModelFactory($connection, $tableInstance))->create(); - } catch (\Exception $e) { + } catch (Exception $e) { continue; } diff --git a/src/Lib/OpenApi/Operation.php b/src/Lib/OpenApi/Operation.php index 63797fe2..7f36b764 100644 --- a/src/Lib/OpenApi/Operation.php +++ b/src/Lib/OpenApi/Operation.php @@ -26,8 +26,8 @@ class Operation implements JsonSerializable * @param \SwaggerBake\Lib\OpenApi\OperationExternalDoc|null $externalDocs Optional External Documentation * @param \SwaggerBake\Lib\OpenApi\RequestBody|null $requestBody Optional request body * @param array $parameters A mixed array of OpenApi Parameter and/or OpenApi $ref - * @param \SwaggerBake\Lib\OpenApi\Response[] $responses Array of OpenApi Response - * @param \SwaggerBake\Lib\OpenApi\PathSecurity[] $security Array of OpenApi PathSecurity + * @param array<\SwaggerBake\Lib\OpenApi\Response> $responses Array of OpenApi Response + * @param array<\SwaggerBake\Lib\OpenApi\PathSecurity> $security Array of OpenApi PathSecurity * @param bool $isDeprecated Is this operation deprecated? * @param int $sortOrder The sort order, by default uses the order of methods in the controller. * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -150,7 +150,7 @@ public function getTags(): array } /** - * @param string[] $tags An array of operation tags + * @param array $tags An array of operation tags * @return $this */ public function setTags(array $tags) @@ -180,7 +180,7 @@ public function setOperationId(string $operationId) } /** - * @return \SwaggerBake\Lib\OpenApi\Parameter[] + * @return array<\SwaggerBake\Lib\OpenApi\Parameter> */ public function getParameters(): array { @@ -209,7 +209,7 @@ public function getParameterByTypeAndName(string $type, string $name): Parameter } /** - * @param \SwaggerBake\Lib\OpenApi\Parameter[] $parameters Array of Parameter objects + * @param array<\SwaggerBake\Lib\OpenApi\Parameter> $parameters Array of Parameter objects * @return $this */ public function setParameters(array $parameters) @@ -270,7 +270,7 @@ public function setRequestBody(RequestBody $requestBody) } /** - * @return \SwaggerBake\Lib\OpenApi\Response[] + * @return array<\SwaggerBake\Lib\OpenApi\Response> */ public function getResponses(): array { @@ -287,7 +287,7 @@ public function getResponseByCode(string $code): ?Response } /** - * @param \SwaggerBake\Lib\OpenApi\Response[] $array Array of Response objects + * @param array<\SwaggerBake\Lib\OpenApi\Response> $array Array of Response objects * @return $this */ public function setResponses(array $array) @@ -328,7 +328,7 @@ public function getSecurity(): array } /** - * @param \SwaggerBake\Lib\OpenApi\PathSecurity[] $pathSecurities Array of PathSecurity + * @param array<\SwaggerBake\Lib\OpenApi\PathSecurity> $pathSecurities Array of PathSecurity * @return $this */ public function setSecurity(array $pathSecurities) diff --git a/src/Lib/OpenApi/Parameter.php b/src/Lib/OpenApi/Parameter.php index cd116afc..9802b856 100644 --- a/src/Lib/OpenApi/Parameter.php +++ b/src/Lib/OpenApi/Parameter.php @@ -18,7 +18,7 @@ class Parameter implements JsonSerializable /** * The location of the parameter. * - * @var string[] + * @var array */ public const IN = ['query','cookie','header','path']; @@ -230,7 +230,7 @@ public function setAllowEmptyValue(bool $allowEmptyValue) /** * @return mixed */ - public function getSchema() + public function getSchema(): mixed { return $this->schema; } @@ -306,7 +306,7 @@ public function setAllowReserved(bool $allowReserved) /** * @return mixed */ - public function getExample() + public function getExample(): mixed { return $this->example; } @@ -315,7 +315,7 @@ public function getExample() * @param mixed $example Example * @return $this */ - public function setExample($example) + public function setExample(mixed $example) { $this->example = $example; diff --git a/src/Lib/OpenApi/Path.php b/src/Lib/OpenApi/Path.php index 667c0a09..d12577c6 100644 --- a/src/Lib/OpenApi/Path.php +++ b/src/Lib/OpenApi/Path.php @@ -16,11 +16,11 @@ class Path implements JsonSerializable { /** * @param string $resource The resource (base URL), for example: /pets - * @param \SwaggerBake\Lib\OpenApi\Operation[] $operations An array of OpenApi Operations + * @param array<\SwaggerBake\Lib\OpenApi\Operation> $operations An array of OpenApi Operations * @param string|null $ref An optional OpenAPI path $ref * @param string|null $summary An optional short summary * @param string|null $description An optional description - * @param string[] $tags Sets the tag for all operations in the path. Tags set on individual operations will take + * @param array $tags Sets the tag for all operations in the path. Tags set on individual operations will take * precedence. */ public function __construct( @@ -91,7 +91,7 @@ public function setResource(string $resource) } /** - * @return \SwaggerBake\Lib\OpenApi\Operation[] + * @return array<\SwaggerBake\Lib\OpenApi\Operation> */ public function getOperations(): array { @@ -99,7 +99,7 @@ public function getOperations(): array } /** - * @param \SwaggerBake\Lib\OpenApi\Operation[] $operations Array of Operation + * @param array<\SwaggerBake\Lib\OpenApi\Operation> $operations Array of Operation * @return $this */ public function setOperations(array $operations) @@ -190,7 +190,7 @@ public function getTags(): array } /** - * @param string[] $tags A list of OpenApi tags + * @param array $tags A list of OpenApi tags * @return $this */ public function setTags(array $tags) diff --git a/src/Lib/OpenApi/PathSecurity.php b/src/Lib/OpenApi/PathSecurity.php index 5920a480..2af530b8 100644 --- a/src/Lib/OpenApi/PathSecurity.php +++ b/src/Lib/OpenApi/PathSecurity.php @@ -4,6 +4,7 @@ namespace SwaggerBake\Lib\OpenApi; use JsonSerializable; +use ReturnTypeWillChange; /** * Class PathSecurity @@ -35,10 +36,10 @@ public function toArray(): array } /** - * @return array|array[]|mixed + * @return mixed|array|array */ - #[\ReturnTypeWillChange] - public function jsonSerialize() + #[ReturnTypeWillChange] + public function jsonSerialize(): mixed { return $this->toArray(); } diff --git a/src/Lib/OpenApi/RequestBody.php b/src/Lib/OpenApi/RequestBody.php index 19624242..562803bb 100644 --- a/src/Lib/OpenApi/RequestBody.php +++ b/src/Lib/OpenApi/RequestBody.php @@ -15,7 +15,7 @@ class RequestBody implements JsonSerializable { /** * @param string|null $description An optional description - * @param \SwaggerBake\Lib\OpenApi\Content[] $content Array of OpenApi Content + * @param array<\SwaggerBake\Lib\OpenApi\Content> $content Array of OpenApi Content * @param bool $required Is this required? * @param bool $ignoreCakeSchema Should cakephp schema be ignored? */ @@ -72,7 +72,7 @@ public function setDescription(string $description) } /** - * @return array|\SwaggerBake\Lib\OpenApi\Content[] + * @return array|array<\SwaggerBake\Lib\OpenApi\Content> */ public function getContent(): array { diff --git a/src/Lib/OpenApi/Response.php b/src/Lib/OpenApi/Response.php index 8408e1ee..d66f151c 100644 --- a/src/Lib/OpenApi/Response.php +++ b/src/Lib/OpenApi/Response.php @@ -17,7 +17,7 @@ class Response implements JsonSerializable /** * @param string $code HTTP status code * @param string|null $description An optional description - * @param \SwaggerBake\Lib\OpenApi\Content[] $content Array of OpenApi Content + * @param array<\SwaggerBake\Lib\OpenApi\Content> $content Array of OpenApi Content */ public function __construct( private string $code, @@ -85,7 +85,7 @@ public function setDescription(string $description) } /** - * @return \SwaggerBake\Lib\OpenApi\Content[] + * @return array<\SwaggerBake\Lib\OpenApi\Content> */ public function getContent(): array { @@ -104,7 +104,7 @@ public function getContentByMimeType(string $mimeType): ?Content /** * Sets the array of Content[] * - * @param \SwaggerBake\Lib\OpenApi\Content[] $contents Content + * @param array<\SwaggerBake\Lib\OpenApi\Content> $contents Content * @return $this */ public function setContent(array $contents) diff --git a/src/Lib/OpenApi/Schema.php b/src/Lib/OpenApi/Schema.php index 5d83a72e..720d1413 100644 --- a/src/Lib/OpenApi/Schema.php +++ b/src/Lib/OpenApi/Schema.php @@ -3,6 +3,7 @@ namespace SwaggerBake\Lib\OpenApi; +use AllowDynamicProperties; use JsonSerializable; use SwaggerBake\Lib\Attribute\OpenApiSchema; use SwaggerBake\Lib\Utility\ArrayUtility; @@ -14,14 +15,14 @@ * @see https://swagger.io/docs/specification/data-models/ * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) */ -#[\AllowDynamicProperties] +#[AllowDynamicProperties] class Schema implements JsonSerializable, SchemaInterface { use SchemaTrait; /** * @param string|null $title Title of the schema - * @param string[] $required A list of required properties + * @param array $required A list of required properties * @param array $properties A mixed array of Schema and SchemaProperty * @param string|null $refEntity todo: needs documentation * @param array $items A list of items this Schema contains when this schema is an array. @@ -150,7 +151,7 @@ public function getRequired(): array } /** - * @param string[] $required Required + * @param array $required Required * @return $this */ public function setRequired(array $required) @@ -182,7 +183,7 @@ public function getProperties(): array } /** - * @param \SwaggerBake\Lib\OpenApi\Schema[]|\SwaggerBake\Lib\OpenApi\SchemaProperty[] $properties A mixed array of Schema and SchemaProperty + * @param array<\SwaggerBake\Lib\OpenApi\Schema>|array<\SwaggerBake\Lib\OpenApi\SchemaProperty> $properties A mixed array of Schema and SchemaProperty * @return $this */ public function setProperties(array $properties) diff --git a/src/Lib/OpenApi/SchemaProperty.php b/src/Lib/OpenApi/SchemaProperty.php index 8a3e75b9..c1556a8e 100644 --- a/src/Lib/OpenApi/SchemaProperty.php +++ b/src/Lib/OpenApi/SchemaProperty.php @@ -189,7 +189,7 @@ public function setRequired(bool $required) /** * @return mixed */ - public function getExample() + public function getExample(): mixed { return $this->example; } @@ -198,7 +198,7 @@ public function getExample() * @param mixed $example An example value * @return $this */ - public function setExample($example) + public function setExample(mixed $example) { $this->example = $example; @@ -279,7 +279,7 @@ public function getRefEntity(): ?string } /** - * @param null|string $refEntity Reference YAML schema such as #/components/schema/MyEntity + * @param string|null $refEntity Reference YAML schema such as #/components/schema/MyEntity * @return $this */ public function setRefEntity(?string $refEntity) diff --git a/src/Lib/OpenApi/SchemaTrait.php b/src/Lib/OpenApi/SchemaTrait.php index e0bc2277..2ea12444 100644 --- a/src/Lib/OpenApi/SchemaTrait.php +++ b/src/Lib/OpenApi/SchemaTrait.php @@ -68,7 +68,7 @@ public function getFormat(): ?string } /** - * @param null|string $format Format + * @param string|null $format Format * @return $this */ public function setFormat(?string $format) diff --git a/src/Lib/OpenApi/Xml.php b/src/Lib/OpenApi/Xml.php index 6e538385..2b9e0107 100644 --- a/src/Lib/OpenApi/Xml.php +++ b/src/Lib/OpenApi/Xml.php @@ -16,27 +16,27 @@ class Xml implements JsonSerializable /** * @var string */ - private $name; + private string $name; /** * @var string|null */ - private $namespace; + private ?string $namespace = null; /** * @var string|null */ - private $prefix; + private ?string $prefix = null; /** * @var bool|null */ - private $attribute; + private ?bool $attribute = null; /** * @var bool|null */ - private $wrapped; + private ?bool $wrapped = null; /** * @return array diff --git a/src/Lib/OpenApiSchemaGenerator.php b/src/Lib/OpenApiSchemaGenerator.php index 5f5cdfde..75036115 100644 --- a/src/Lib/OpenApiSchemaGenerator.php +++ b/src/Lib/OpenApiSchemaGenerator.php @@ -5,6 +5,7 @@ use Cake\Core\Plugin; use DebugKit\DebugTimer; +use ReflectionClass; use SwaggerBake\Lib\Attribute\OpenApiSchema; use SwaggerBake\Lib\Model\ModelScanner; use SwaggerBake\Lib\OpenApi\Schema; @@ -36,7 +37,7 @@ public function generate(array $openapi = []): array $models = $this->modelScanner->getModelDecorators(); foreach ($models as $model) { - $entityName = (new \ReflectionClass($model->getModel()->getEntity()))->getShortName(); + $entityName = (new ReflectionClass($model->getModel()->getEntity()))->getShortName(); if ($this->getSchemaByName($openapi, $entityName)) { continue; diff --git a/src/Lib/Operation/DtoParser.php b/src/Lib/Operation/DtoParser.php index 8d792147..52a1a633 100644 --- a/src/Lib/Operation/DtoParser.php +++ b/src/Lib/Operation/DtoParser.php @@ -38,7 +38,7 @@ public function __construct(ReflectionClass|string $reflection) /** * Returns an array of Parameter instances for use in Query Parameters * - * @return \SwaggerBake\Lib\OpenApi\Parameter[] + * @return array<\SwaggerBake\Lib\OpenApi\Parameter> * @throws \ReflectionException */ public function getParameters(): array @@ -61,7 +61,7 @@ public function getParameters(): array /** * Returns an array of SchemaProperty instances for use in Body Requests or Responses. * - * @return \SwaggerBake\Lib\OpenApi\SchemaProperty[] + * @return array<\SwaggerBake\Lib\OpenApi\SchemaProperty> * @throws \ReflectionException */ public function getSchemaProperties(): array @@ -83,7 +83,7 @@ public function getSchemaProperties(): array /** * @link https://book.cakephp.org/4/en/core-libraries/form.html - * @return \SwaggerBake\Lib\OpenApi\SchemaProperty[] + * @return array<\SwaggerBake\Lib\OpenApi\SchemaProperty> * @throws \ReflectionException */ private function getModellessFormSchemaProperties(): array @@ -113,7 +113,7 @@ private function getModellessFormSchemaProperties(): array /** * @link https://book.cakephp.org/4/en/core-libraries/form.html - * @return \SwaggerBake\Lib\OpenApi\Parameter[] + * @return array<\SwaggerBake\Lib\OpenApi\Parameter> * @throws \ReflectionException */ private function getModellessFormQueryParams(): array diff --git a/src/Lib/Operation/ExceptionResponse.php b/src/Lib/Operation/ExceptionResponse.php index f0ffde03..a76ce142 100644 --- a/src/Lib/Operation/ExceptionResponse.php +++ b/src/Lib/Operation/ExceptionResponse.php @@ -97,7 +97,7 @@ public function build(Throws $throw) * @param string $exceptionFqn The FQN of the exception class. * @return string|null */ - private function fallback(string $exceptionFqn): string|null + private function fallback(string $exceptionFqn): ?string { if (empty($this->config->getExceptionSchema())) { return null; diff --git a/src/Lib/Operation/OperationFromRouteFactory.php b/src/Lib/Operation/OperationFromRouteFactory.php index 4c784907..ed2c9eb3 100644 --- a/src/Lib/Operation/OperationFromRouteFactory.php +++ b/src/Lib/Operation/OperationFromRouteFactory.php @@ -44,7 +44,7 @@ public function __construct(private Swagger $swagger, private Path $path) * * @param \SwaggerBake\Lib\Route\RouteDecorator $route RouteDecorator * @param string $httpMethod Http method such i.e. PUT, POST, PATCH, GET, and DELETE - * @param null|\SwaggerBake\Lib\OpenApi\Schema $schema Schema + * @param \SwaggerBake\Lib\OpenApi\Schema|null $schema Schema * @return \SwaggerBake\Lib\OpenApi\Operation|null * @throws \ReflectionException */ @@ -70,7 +70,6 @@ public function create(RouteDecorator $route, string $httpMethod, ?Schema $schem })->toArray(); $openApiOperation = (new AttributeFactory($refMethod, OpenApiOperation::class))->createOneOrNull(); } catch (Exception) { - $refClass = null; $refMethod = null; $openApiOperation = null; } @@ -137,6 +136,7 @@ public function create(RouteDecorator $route, string $httpMethod, ?Schema $schem * * @param \SwaggerBake\Lib\Route\RouteDecorator $route RouteDecorator * @return \phpDocumentor\Reflection\DocBlock + * @throws \ReflectionException */ private function getDocBlock(RouteDecorator $route): DocBlock { @@ -160,7 +160,7 @@ private function getDocBlock(RouteDecorator $route): DocBlock * * @param \SwaggerBake\Lib\OpenApi\Operation $operation Operation * @param \SwaggerBake\Lib\Route\RouteDecorator $route RouteDecorator - * @param null $openApiOperation A reflection of the Controller method (i.e. action) + * @param \SwaggerBake\Lib\Attribute\OpenApiOperation|null $openApiOperation A reflection of the Controller method (i.e. action) * @return \SwaggerBake\Lib\OpenApi\Operation */ private function createOperation( diff --git a/src/Lib/Operation/OperationHeader.php b/src/Lib/Operation/OperationHeader.php index 3dad6ade..f1087cfc 100644 --- a/src/Lib/Operation/OperationHeader.php +++ b/src/Lib/Operation/OperationHeader.php @@ -22,7 +22,7 @@ public function getOperationWithHeaders(Operation $operation, ?ReflectionMethod return $operation; } - /** @var \SwaggerBake\Lib\Attribute\OpenApiHeader[] $headers */ + /** @var array<\SwaggerBake\Lib\Attribute\OpenApiHeader> $headers */ $headers = (new AttributeFactory($refMethod, OpenApiHeader::class))->createMany(); if (!count($headers)) { return $operation; diff --git a/src/Lib/Operation/OperationPathParameter.php b/src/Lib/Operation/OperationPathParameter.php index 2ac06251..c14acbb3 100644 --- a/src/Lib/Operation/OperationPathParameter.php +++ b/src/Lib/Operation/OperationPathParameter.php @@ -92,7 +92,7 @@ private function updatePathParametersUsingAnnotations(): void return; } - /** @var \SwaggerBake\Lib\Attribute\OpenApiPathParam[] $openApiPathParams */ + /** @var array<\SwaggerBake\Lib\Attribute\OpenApiPathParam> $openApiPathParams */ $openApiPathParams = (new AttributeFactory( $this->reflectionMethod, OpenApiPathParam::class diff --git a/src/Lib/Operation/OperationQueryParameter.php b/src/Lib/Operation/OperationQueryParameter.php index fdd4ebc6..ed75a311 100644 --- a/src/Lib/Operation/OperationQueryParameter.php +++ b/src/Lib/Operation/OperationQueryParameter.php @@ -5,6 +5,7 @@ use Cake\Controller\Controller; use ReflectionClass; +use ReflectionException; use ReflectionMethod; use SwaggerBake\Lib\Attribute\AttributeFactory; use SwaggerBake\Lib\Attribute\OpenApiDto; @@ -113,7 +114,7 @@ private function pushSortParameter(OpenApiPaginator $paginator): void return; } - } catch (\ReflectionException) { + } catch (ReflectionException) { } if ($this->schema != null && is_array($this->schema->getProperties())) { @@ -138,7 +139,7 @@ private function pushSortParameter(OpenApiPaginator $paginator): void */ private function defineQueryParams(): void { - /** @var \SwaggerBake\Lib\Attribute\OpenApiQueryParam[] $params */ + /** @var array<\SwaggerBake\Lib\Attribute\OpenApiQueryParam> $params */ $params = (new AttributeFactory($this->refMethod, OpenApiQueryParam::class))->createMany(); if (!count($params)) { return; @@ -173,7 +174,7 @@ private function defineDataTransferObject(): void new ReflectionClass($dto->class), OpenApiQueryParam::class ))->createMany(); - /** @var \SwaggerBake\Lib\Attribute\OpenApiQueryParam[] $queryParams */ + /** @var array<\SwaggerBake\Lib\Attribute\OpenApiQueryParam> $queryParams */ $parameters = array_map(function ($param) { return $param->createParameter(); }, $queryParams); diff --git a/src/Lib/Operation/OperationRequestBody.php b/src/Lib/Operation/OperationRequestBody.php index 1a3f7d32..77d69965 100644 --- a/src/Lib/Operation/OperationRequestBody.php +++ b/src/Lib/Operation/OperationRequestBody.php @@ -112,7 +112,7 @@ private function applyRequestBody(): void */ private function applyForm(): void { - /** @var \SwaggerBake\Lib\Attribute\OpenApiForm[] $openApiForms */ + /** @var array<\SwaggerBake\Lib\Attribute\OpenApiForm> $openApiForms */ $openApiForms = (new AttributeFactory( $this->refMethod, OpenApiForm::class @@ -180,7 +180,7 @@ private function applyDataTransferObject(): void $dtoReflection, OpenApiSchemaProperty::class ))->createMany(); - /** @var \SwaggerBake\Lib\Attribute\OpenApiSchemaProperty[] $schemaProperties */ + /** @var array<\SwaggerBake\Lib\Attribute\OpenApiSchemaProperty> $schemaProperties */ $properties = array_map(function ($prop) { return $prop->create(); }, $schemaProperties); diff --git a/src/Lib/Operation/OperationResponse.php b/src/Lib/Operation/OperationResponse.php index ffd36212..26c925e1 100644 --- a/src/Lib/Operation/OperationResponse.php +++ b/src/Lib/Operation/OperationResponse.php @@ -71,7 +71,7 @@ private function assignFromAttributes(): void return; } - /** @var \SwaggerBake\Lib\Attribute\OpenApiResponse[] $openApiResponses */ + /** @var array<\SwaggerBake\Lib\Attribute\OpenApiResponse> $openApiResponses */ $openApiResponses = (new AttributeFactory($this->refMethod, OpenApiResponse::class))->createMany(); foreach ($openApiResponses as $openApiResponse) { diff --git a/src/Lib/Route/RouteDecorator.php b/src/Lib/Route/RouteDecorator.php index 098a88a0..98b10212 100644 --- a/src/Lib/Route/RouteDecorator.php +++ b/src/Lib/Route/RouteDecorator.php @@ -8,6 +8,7 @@ use Cake\Routing\Route\Route; use Cake\Utility\Inflector; use MixerApi\Core\Model\Model; +use ReflectionClass; /** * Decorates \Cake\Routing\Route\Route @@ -216,7 +217,7 @@ public function getAction(): ?string * @param string|null $action The controller method * @return $this */ - public function setAction($action) + public function setAction(?string $action) { $this->action = $action; @@ -329,7 +330,7 @@ function ($piece) { public function getControllerInstance(): ?Controller { if ($this->controllerFqn && class_exists($this->controllerFqn)) { - $controller = (new \ReflectionClass($this->controllerFqn))->newInstanceWithoutConstructor(); + $controller = (new ReflectionClass($this->controllerFqn))->newInstanceWithoutConstructor(); return $controller instanceof Controller ? $controller : null; } diff --git a/src/Lib/Route/RouteScanner.php b/src/Lib/Route/RouteScanner.php index b200e0f2..e457f434 100644 --- a/src/Lib/Route/RouteScanner.php +++ b/src/Lib/Route/RouteScanner.php @@ -13,7 +13,7 @@ */ class RouteScanner { - /** @var string[] */ + /** @var array */ private const EXCLUDED_PLUGINS = [ 'DebugKit', ]; @@ -23,7 +23,7 @@ class RouteScanner /** * Array of RouteDecorator instances * - * @var \SwaggerBake\Lib\Route\RouteDecorator[] + * @var array<\SwaggerBake\Lib\Route\RouteDecorator> */ private array $routes; @@ -38,7 +38,7 @@ public function __construct(private Router $router, Configuration $config) } /** - * @return \SwaggerBake\Lib\Route\RouteDecorator[] + * @return array<\SwaggerBake\Lib\Route\RouteDecorator> */ public function getRoutes(): array { diff --git a/src/Lib/Schema/SchemaFactory.php b/src/Lib/Schema/SchemaFactory.php index 270592a5..f53ec576 100644 --- a/src/Lib/Schema/SchemaFactory.php +++ b/src/Lib/Schema/SchemaFactory.php @@ -7,6 +7,7 @@ use Cake\Event\Event; use Cake\Event\EventManager; use Cake\Validation\Validator; +use Exception; use MixerApi\Core\Model\Model; use phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\DocBlockFactory; @@ -174,7 +175,7 @@ private function getDocBlock(EntityInterface $entity): ?DocBlock { try { $reflectionClass = new ReflectionClass($entity); - } catch (\Exception $e) { + } catch (Exception $e) { return null; } @@ -193,12 +194,12 @@ private function getDocBlock(EntityInterface $entity): ?DocBlock * Returns key-value pair of property name => SchemaProperty * * @param \MixerApi\Core\Model\Model $model Model - * @return \SwaggerBake\Lib\OpenApi\SchemaProperty[] + * @return array<\SwaggerBake\Lib\OpenApi\SchemaProperty> * @throws \ReflectionException */ private function getPropertyAnnotations(Model $model): array { - /** @var \SwaggerBake\Lib\Attribute\OpenApiSchemaProperty[] $attributes */ + /** @var array<\SwaggerBake\Lib\Attribute\OpenApiSchemaProperty> $attributes */ $attributes = (new AttributeFactory( new ReflectionClass($model->getEntity()), OpenApiSchemaProperty::class @@ -222,7 +223,7 @@ private function getValidator(Model $model): Validator { try { $validator = $model->getTable()->validationDefault(new Validator()); - } catch (\Exception $e) { + } catch (Exception $e) { return new Validator(); } diff --git a/src/Lib/Schema/SchemaPropertyFactory.php b/src/Lib/Schema/SchemaPropertyFactory.php index 7aa4879d..a24e7182 100644 --- a/src/Lib/Schema/SchemaPropertyFactory.php +++ b/src/Lib/Schema/SchemaPropertyFactory.php @@ -88,7 +88,7 @@ private function findPropertyTag(ModelProperty $property): ?PropertyTag return null; } - /** @var \phpDocumentor\Reflection\DocBlock\Tags\Property[] $results */ + /** @var array<\phpDocumentor\Reflection\DocBlock\Tags\Property> $results */ $results = array_filter( $this->docBlock->getTagsByName('property'), function ($tag) use ($property) { diff --git a/src/Lib/Schema/SchemaPropertyValidation.php b/src/Lib/Schema/SchemaPropertyValidation.php index 6cca320d..edc34992 100644 --- a/src/Lib/Schema/SchemaPropertyValidation.php +++ b/src/Lib/Schema/SchemaPropertyValidation.php @@ -5,6 +5,7 @@ use Cake\Validation\ValidationRule; use Cake\Validation\Validator; +use Exception; use MixerApi\Core\Model\ModelProperty; use ReflectionFunction; use SwaggerBake\Lib\OpenApi\SchemaProperty; @@ -60,10 +61,10 @@ public function withValidations(): SchemaProperty * only rules a rule value of the validation is applied to both creates and update. * * @param string $rule Rule name - * @return array|mixed|null + * @return mixed|array|null * @codeCoverageIgnore */ - private function getValidationRuleValue(string $rule) + private function getValidationRuleValue(string $rule): mixed { $validationRule = $this->validator->field($this->propertyName)->rule($rule); if (!$validationRule instanceof ValidationRule) { @@ -91,7 +92,7 @@ private function getValidationRuleValue(string $rule) * @return mixed * @codeCoverageIgnore */ - private function getValidationRuleValueFromClosure(string $rule) + private function getValidationRuleValueFromClosure(string $rule): mixed { $validationRule = $this->validator->field($this->propertyName)->rule($rule); if (!$validationRule instanceof ValidationRule) { @@ -101,7 +102,7 @@ private function getValidationRuleValueFromClosure(string $rule) $result = $validationRule->get('rule'); try { $vars = (new ReflectionFunction($result))->getStaticVariables(); - } catch (\Exception $e) { + } catch (Exception $e) { return null; } diff --git a/src/Lib/Service/OpenApiBakerService.php b/src/Lib/Service/OpenApiBakerService.php index 4b820641..5d738d1a 100644 --- a/src/Lib/Service/OpenApiBakerService.php +++ b/src/Lib/Service/OpenApiBakerService.php @@ -29,7 +29,7 @@ public function bake(Swagger $swagger, string $filePath): string } /** - * @return string[] + * @return array */ public function getWarnings(): array { diff --git a/src/Lib/Swagger.php b/src/Lib/Swagger.php index 57d927e2..8a6ca2ae 100644 --- a/src/Lib/Swagger.php +++ b/src/Lib/Swagger.php @@ -52,10 +52,10 @@ public function __construct( /** * Builds an OpenAPI array that can be converted to JSON. * - * @return \SwaggerBake\Lib\Swagger + * @return self * @throws \ReflectionException */ - public function build() + public function build(): Swagger { $this->array = (new OpenApiFromYaml())->build(Yaml::parseFile($this->config->getYml())); @@ -196,7 +196,7 @@ public function getConfig(): Configuration /** * Returns an array of Operation objects that do not have a 200-299 HTTP status code * - * @return \SwaggerBake\Lib\OpenApi\Operation[] + * @return array<\SwaggerBake\Lib\OpenApi\Operation> */ public function getOperationsWithNoHttp20x(): array { diff --git a/src/Lib/Utility/DocBlockUtility.php b/src/Lib/Utility/DocBlockUtility.php index df8f91c9..69b6a8e4 100644 --- a/src/Lib/Utility/DocBlockUtility.php +++ b/src/Lib/Utility/DocBlockUtility.php @@ -5,6 +5,7 @@ use phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\DocBlockFactory; +use ReflectionException; use ReflectionMethod; /** @@ -25,7 +26,7 @@ public static function getMethodDocBlock(object $instance, string $methodName): { try { $reflectionMethod = new ReflectionMethod(get_class($instance), $methodName); - } catch (\ReflectionException $e) { + } catch (ReflectionException $e) { return null; } diff --git a/src/Lib/Utility/NamespaceUtility.php b/src/Lib/Utility/NamespaceUtility.php index c5be5c30..5a567274 100644 --- a/src/Lib/Utility/NamespaceUtility.php +++ b/src/Lib/Utility/NamespaceUtility.php @@ -3,6 +3,7 @@ namespace SwaggerBake\Lib\Utility; +use MixerApi\Core\Utility\NamespaceUtility as MixerApiNsUtil; use SwaggerBake\Lib\Configuration; /** @@ -59,10 +60,10 @@ public static function getTableFullyQualifiedNameSpace(string $className, Config /** * Performs a recursive check for the given namespaces and returns an array of classes * - * @param string[] $namespaces array of namespaces strings (e.g. ['\App\\']) + * @param array $namespaces array of namespaces strings (e.g. ['\App\\']) * @param string $ns an additional name to append to each namespace as part of the search (e.g. Controller) * @example getClasses(['\App\\'], 'Controller') to search for \App\Controller classes - * @return string[] + * @return array * @throws \Exception */ public static function getClasses(array $namespaces, string $ns = ''): array @@ -83,7 +84,7 @@ public static function getClasses(array $namespaces, string $ns = ''): array $classes = array_merge( $classes, - \MixerApi\Core\Utility\NamespaceUtility::findClasses($namespace) + MixerApiNsUtil::findClasses($namespace) ); } diff --git a/src/Lib/Utility/OpenApiDataType.php b/src/Lib/Utility/OpenApiDataType.php index fc077482..3427a0b6 100644 --- a/src/Lib/Utility/OpenApiDataType.php +++ b/src/Lib/Utility/OpenApiDataType.php @@ -20,7 +20,7 @@ class OpenApiDataType public const EMPTY = ''; /** - * @var string[] + * @var array */ public const TYPES = [ self::ARRAY, From b1de4555fd333343b39f339659b5536951689ea3 Mon Sep 17 00:00:00 2001 From: Chris Nizzardini Date: Sun, 7 Jan 2024 12:57:28 -0500 Subject: [PATCH 2/2] update github actions --- .github/workflows/pull-request.yml | 10 +++------- .github/workflows/push.yml | 9 ++------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 4ac69fb5..a0d77c68 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -5,12 +5,8 @@ on: jobs: build: - name: PHP ${{ matrix.php-versions }} Test + name: PHP 8.3 Test / Analysis runs-on: ubuntu-latest - strategy: - matrix: - operating-system: [ ubuntu-22.04 ] - php-versions: ['8.1', '8.2'] steps: - name: Checkout uses: actions/checkout@v2 @@ -18,7 +14,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php-versions }} + php-version: 8.3 extensions: mbstring, intl, xdebug - name: PHP Version @@ -37,7 +33,7 @@ jobs: echo ${{ matrix.php-versions }} coverage: - name: Code Coverage + name: PHP 8.1 Coverage runs-on: ubuntu-latest steps: - name: Checkout diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index b74441d2..cc3dd31f 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -6,13 +6,8 @@ on: jobs: build: - runs-on: ubuntu-latest - strategy: - matrix: - operating-system: [ ubuntu-22.04 ] - php-versions: ['8.2'] - name: Upload coverage report + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 @@ -20,7 +15,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php-versions }} + php-version: 8.1 extensions: mbstring, intl, xdebug - name: Install dependencies