From 9215d3a64b388c99f27a79d8b9e8657cac9e5026 Mon Sep 17 00:00:00 2001 From: Lukasz Falda Date: Wed, 17 Aug 2022 17:32:48 +0200 Subject: [PATCH] Support Symfony6 --- .github/workflows/phpunit.yml | 2 + .github/workflows/static-analysis.yml | 2 + .gitignore | 2 +- .php_cs => .php-cs-fixer.php | 22 ++++- composer.json | 97 +++++++++++---------- grumphp.yaml | 2 +- phpstan-baseline.neon | 26 ++++++ phpstan.neon | 1 + src/Client/Serializer.php | 2 +- src/ConfigProvider.php | 4 +- src/Request/FindOfficeRequest.php | 4 +- src/Response/Struct/OfficeCollection.php | 4 +- src/Response/Struct/WorkingTimeSchedule.php | 4 +- 13 files changed, 110 insertions(+), 62 deletions(-) rename .php_cs => .php-cs-fixer.php (53%) create mode 100644 phpstan-baseline.neon diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index f7b899f..35acac9 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -12,6 +12,8 @@ jobs: matrix: php-version: - "7.4" + - "8.0" + - "8.1" deps: - "normal" include: diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index eb26563..8b0c53e 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -12,6 +12,8 @@ jobs: matrix: php-version: - "7.4" + - "8.0" + - "8.1" steps: - name: "Checkout" diff --git a/.gitignore b/.gitignore index 4d30792..da6a067 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /vendor/ -\.php_cs\.cache +*.cache .phpunit.result.cache composer.lock /.idea diff --git a/.php_cs b/.php-cs-fixer.php similarity index 53% rename from .php_cs rename to .php-cs-fixer.php index 3362983..c51474e 100755 --- a/.php_cs +++ b/.php-cs-fixer.php @@ -1,6 +1,10 @@ getFinder() ->exclude( [ 'vendor', @@ -8,7 +12,8 @@ ) ->in(__DIR__); -return PhpCsFixer\Config::create() +return $config + ->registerCustomFixers([]) ->setRules( [ '@Symfony' => true, @@ -21,6 +26,15 @@ 'phpdoc_var_without_name' => false, 'phpdoc_to_comment' => false, 'single_line_throw' => false, + 'modernize_types_casting' => true, + 'function_declaration' => false, + 'ordered_imports' => [ + 'imports_order' => [ + 'class', + 'function', + 'const', + ], + 'sort_algorithm' => 'alpha', + ], ] - ) - ->setFinder($finder); + ); diff --git a/composer.json b/composer.json index 754466f..7fe5065 100755 --- a/composer.json +++ b/composer.json @@ -1,50 +1,53 @@ { - "name": "answear/speedy-pickup-point-bundle", - "description": "API Client for Speedy.bg.", - "type": "symfony-bundle", - "license": "MIT", - "require": { - "php": ">=7.4", - "ext-json": "*", - "guzzlehttp/guzzle": "^6.0", - "marc-mabe/php-enum": "^3.0|^4.3", - "symfony/http-kernel": "^4.4|^5.0", - "symfony/serializer": "^4.4|^5.0", - "webmozart/assert": "^1.3" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^2.16", - "phpro/grumphp": "^1.3.0", - "phpstan/phpstan": "^0.12.32", - "phpstan/phpstan-webmozart-assert": "^0.12.2", - "phpunit/phpunit": "^8.4", - "roave/security-advisories": "dev-master", - "symfony/phpunit-bridge": "^5.0" - }, - "autoload": { - "psr-4": { - "Answear\\SpeedyBundle\\": "src/" + "name": "answear/speedy-pickup-point-bundle", + "description": "API Client for Speedy.bg.", + "type": "symfony-bundle", + "license": "MIT", + "require": { + "php": ">=7.4|^8.0", + "ext-json": "*", + "guzzlehttp/guzzle": "^6.0|^7.0", + "marc-mabe/php-enum": "^3.0|^4.3", + "symfony/http-kernel": "^5.4|^6.0", + "symfony/serializer": "^5.4|^6.0", + "webmozart/assert": "^1.3" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.4", + "phpro/grumphp": "^1.5.0", + "phpstan/phpstan": "^1.4", + "phpstan/phpstan-webmozart-assert": "^1.0", + "phpunit/phpunit": "^9.5", + "roave/security-advisories": "dev-master", + "symfony/phpunit-bridge": "6.1.*" + }, + "autoload": { + "psr-4": { + "Answear\\SpeedyBundle\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Answear\\SpeedyBundle\\Tests\\": "tests/" + } + }, + "scripts": { + "post-install-cmd": [ + "GrumPHP\\Composer\\DevelopmentIntegrator::integrate" + ], + "post-update-cmd": [ + "GrumPHP\\Composer\\DevelopmentIntegrator::integrate" + ] + }, + "extra": { + "grumphp": { + "config-default-path": "grumphp.yaml" + } + }, + "config": { + "sort-packages": true, + "allow-plugins": { + "phpro/grumphp": true + } } - }, - "autoload-dev": { - "psr-4": { - "Answear\\SpeedyBundle\\Tests\\": "tests/" - } - }, - "scripts": { - "post-install-cmd": [ - "GrumPHP\\Composer\\DevelopmentIntegrator::integrate" - ], - "post-update-cmd": [ - "GrumPHP\\Composer\\DevelopmentIntegrator::integrate" - ] - }, - "extra": { - "grumphp": { - "config-default-path": "grumphp.yaml" - } - }, - "config": { - "sort-packages": true - } } diff --git a/grumphp.yaml b/grumphp.yaml index 759f2b3..3808677 100755 --- a/grumphp.yaml +++ b/grumphp.yaml @@ -18,7 +18,7 @@ grumphp: phpcsfixer: allow_risky: true cache_file: ~ - config: './.php_cs' + config: './.php-cs-fixer.php' using_cache: true verbose: true phpstan: diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..965d96d --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,26 @@ +parameters: + ignoreErrors: + - + message: "#^Property Answear\\\\SpeedyBundle\\\\Client\\\\Client\\:\\:\\$configuration is never read, only written\\.$#" + count: 1 + path: src/Client/Client.php + + - + message: "#^Property Answear\\\\SpeedyBundle\\\\Request\\\\FindOfficeRequest\\:\\:\\$countryId is never read, only written\\.$#" + count: 1 + path: src/Request/FindOfficeRequest.php + + - + message: "#^Property Answear\\\\SpeedyBundle\\\\Request\\\\FindOfficeRequest\\:\\:\\$limit is never read, only written\\.$#" + count: 1 + path: src/Request/FindOfficeRequest.php + + - + message: "#^Property Answear\\\\SpeedyBundle\\\\Request\\\\FindOfficeRequest\\:\\:\\$name is never read, only written\\.$#" + count: 1 + path: src/Request/FindOfficeRequest.php + + - + message: "#^Property Answear\\\\SpeedyBundle\\\\Request\\\\FindOfficeRequest\\:\\:\\$siteId is never read, only written\\.$#" + count: 1 + path: src/Request/FindOfficeRequest.php diff --git a/phpstan.neon b/phpstan.neon index cbdf487..faf1fe2 100755 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,6 @@ includes: - vendor/phpstan/phpstan-webmozart-assert/extension.neon + - phpstan-baseline.neon parameters: level: 5 diff --git a/src/Client/Serializer.php b/src/Client/Serializer.php index 126c828..eabc55f 100644 --- a/src/Client/Serializer.php +++ b/src/Client/Serializer.php @@ -19,7 +19,7 @@ public function serialize(Request $request): string { return $this->getSerializer()->serialize( $request, - static::FORMAT, + self::FORMAT, [Normalizer\AbstractObjectNormalizer::SKIP_NULL_VALUES => true] ); } diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index c6b3855..c302ff8 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -24,12 +24,12 @@ public function __construct(string $username, string $password, string $language public function getUrl(): string { - return static::URL; + return self::URL; } public function getApiVersion(): string { - return static::API_VERSION; + return self::API_VERSION; } public function getUsername(): string diff --git a/src/Request/FindOfficeRequest.php b/src/Request/FindOfficeRequest.php index 10c903e..3c29b4e 100644 --- a/src/Request/FindOfficeRequest.php +++ b/src/Request/FindOfficeRequest.php @@ -24,11 +24,11 @@ public function __construct(?int $countryId = null, ?int $siteId = null, ?string public function getEndpoint(): string { - return static::ENDPOINT; + return self::ENDPOINT; } public function getMethod(): string { - return static::HTTP_METHOD; + return self::HTTP_METHOD; } } diff --git a/src/Response/Struct/OfficeCollection.php b/src/Response/Struct/OfficeCollection.php index 584b736..048f2dd 100644 --- a/src/Response/Struct/OfficeCollection.php +++ b/src/Response/Struct/OfficeCollection.php @@ -26,9 +26,9 @@ public function __construct(array $offices) } /** - * @return Office[] + * @return \Traversable */ - public function getIterator(): iterable + public function getIterator(): \Traversable { foreach ($this->offices as $key => $office) { yield $key => $office; diff --git a/src/Response/Struct/WorkingTimeSchedule.php b/src/Response/Struct/WorkingTimeSchedule.php index b23637c..fb273e2 100644 --- a/src/Response/Struct/WorkingTimeSchedule.php +++ b/src/Response/Struct/WorkingTimeSchedule.php @@ -35,9 +35,9 @@ public static function fromArray(array $data): self } /** - * @return WorkingTime[] + * @return \Traversable */ - public function getIterator(): iterable + public function getIterator(): \Traversable { foreach ($this->workingTimeCollection as $key => $workingTime) { yield $key => $workingTime;