Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update deps and fix static analysis warnings #535

Merged
merged 2 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@ 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

- 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
Expand All @@ -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
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,16 @@ 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

- 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
Expand Down
14 changes: 3 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -78,13 +78,5 @@
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"repositories": [
{
"type": "vcs",
"url": "[email protected]:cnizzardini/core.git"
}
],
"minimum-stability": "dev",
"prefer-stable": true
}
}
9 changes: 2 additions & 7 deletions src/Command/BakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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...');
Expand Down
8 changes: 2 additions & 6 deletions src/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 2 additions & 6 deletions src/Command/ModelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 2 additions & 6 deletions src/Command/RouteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/Controller/SwaggerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace SwaggerBake\Controller;

use Cake\Controller\Controller;
use Cake\Http\Response;
use SwaggerBake\Lib\Service\OpenApiControllerService;

class SwaggerController extends Controller
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Lib/Attribute/AbstractOpenApiParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
21 changes: 12 additions & 9 deletions src/Lib/Attribute/AttributeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Lib/Attribute/OpenApiHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Lib/Attribute/OpenApiOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> $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
Expand Down
2 changes: 1 addition & 1 deletion src/Lib/Attribute/OpenApiPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> $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)
Expand Down
2 changes: 1 addition & 1 deletion src/Lib/Attribute/OpenApiQueryParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down
24 changes: 13 additions & 11 deletions src/Lib/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Cake\Datasource\ConnectionManager;
use InvalidArgumentException;
use LogicException;
use RuntimeException;
use SwaggerBake\Lib\Exception\SwaggerBakeRunTimeException;
use Symfony\Component\Yaml\Yaml;

/**
Expand Down Expand Up @@ -58,12 +60,12 @@ class Configuration
protected string $exceptionSchema = 'Exception';

/**
* @var string[] The requested mimetypes accepted by your API.
* @var array<string> The requested mimetypes accepted by your API.
*/
protected array $requestAccepts = ['application/json'];

/**
* @var string[] The mimetypes your API responds with.
* @var array<string> The mimetypes your API responds with.
*/
protected array $responseContentTypes = ['application/json'];

Expand All @@ -74,7 +76,7 @@ class Configuration
protected int $jsonOptions = JSON_PRETTY_PRINT;

/**
* @var string[] The HTTP methods implemented for edit() actions.
* @var array<string> The HTTP methods implemented for edit() actions.
*/
protected array $editActionMethods = ['PATCH'];

Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -376,7 +378,7 @@ public function getParsedYml(): array
/**
* @return mixed|string
*/
public function getTitleFromYml()
public function getTitleFromYml(): mixed
{
$yml = $this->getParsedYml();

Expand Down Expand Up @@ -420,7 +422,7 @@ public function getRequestAccepts(): array
}

/**
* @param string[] $requestAccepts The requested mimetypes accepted by your API.
* @param array<string> $requestAccepts The requested mimetypes accepted by your API.
* @return $this
*/
public function setRequestAccepts(array $requestAccepts)
Expand All @@ -439,7 +441,7 @@ public function getResponseContentTypes(): array
}

/**
* @param string[] $responseContentTypes The mimetypes your API responds with.
* @param array<string> $responseContentTypes The mimetypes your API responds with.
* @return $this
*/
public function setResponseContentTypes(array $responseContentTypes)
Expand Down Expand Up @@ -501,15 +503,15 @@ public function setConnectionName(string $connectionName)
}

/**
* @return string[]
* @return array<string>
*/
public function getEditActionMethods(): array
{
return $this->editActionMethods;
}

/**
* @param string[] $editActionMethods Valid types are POST, PUT, and PATCH.
* @param array<string> $editActionMethods Valid types are POST, PUT, and PATCH.
* @return $this
*/
public function setEditActionMethods(array $editActionMethods)
Expand Down
2 changes: 1 addition & 1 deletion src/Lib/Exception/SwaggerBakeRunTimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading
Loading