From d1046347faaf76baedd88881594de87751e380c5 Mon Sep 17 00:00:00 2001 From: Julian Finkler Date: Tue, 22 Mar 2022 09:19:50 +0100 Subject: [PATCH] Improving code quality (#10) - Added full PHP 8 support - Removed support for pre PHP 7.4 - Improved the code style and added SCA - Added type hints - Copyright updated --- .github/workflows/php.yml | 3 + .gitignore | 7 +- CHANGELOG.md | 9 + composer.json | 22 +- phpstan.neon | 5 + phpunit.xml | 4 +- src/Exception/NotImplementedException.php | 5 +- src/Exception/OrderNotFoundException.php | 2 +- src/Exception/ProductNotFoundException.php | 2 +- src/Http/Message.php | 58 +++- src/Http/Request.php | 28 +- src/Http/RequestHandlerInterface.php | 12 +- src/Http/RequestHandlerPool.php | 21 +- src/Http/Response.php | 123 +++++--- src/Http/Uri.php | 55 ++-- src/Model/Address.php | 132 ++------ src/Model/Order.php | 294 +++++------------- src/Model/OrderComment.php | 55 +--- src/Model/OrderProduct.php | 107 ++----- src/Model/OrderProductOption.php | 30 +- src/Model/PagedData.php | 25 +- src/Model/Pagination.php | 45 +-- src/Model/Product.php | 279 +++++------------ src/Model/ProductImage.php | 44 +-- src/Model/Response/GetOrdersResponse.php | 17 +- src/Model/Response/GetProductsResponse.php | 22 +- src/Model/ShippingProfile.php | 32 +- src/Repository/OrdersRepositoryInterface.php | 14 +- .../ProductsRepositoryInterface.php | 8 +- src/Repository/RepositoryInterface.php | 2 +- .../ShippingProfileRepositoryInterface.php | 5 +- .../StockSyncRepositoryInterface.php | 4 +- src/RequestHandler/OrderRequestHandler.php | 43 ++- src/RequestHandler/ProductRequestHandler.php | 41 ++- src/RequestHandler/RequestHandlerBase.php | 10 +- .../ShippingProfileRequestHandler.php | 11 +- src/RequestHandler/StockRequestHandler.php | 12 +- src/Security/AuthenticatorInterface.php | 4 +- src/Security/KeyAuthenticator.php | 12 +- .../Exception/NotImplementedExceptionTest.php | 4 +- tests/Http/MessageTraitTest.php | 17 +- tests/Http/RequestHandlerPoolTest.php | 24 +- tests/Http/RequestTest.php | 12 +- tests/Http/ResponseTest.php | 50 +-- tests/Http/UriTest.php | 25 +- tests/Model/AddressTest.php | 24 +- tests/Model/OrderCommentTest.php | 4 +- tests/Model/OrderProductOptionTest.php | 6 +- tests/Model/OrderProductTest.php | 4 +- tests/Model/OrderTest.php | 44 +-- tests/Model/PagedDataTest.php | 6 +- tests/Model/PaginationTest.php | 6 +- tests/Model/ProductImageTest.php | 6 +- tests/Model/ProductTest.php | 4 +- .../Model/Response/GetOrdersResponseTest.php | 4 +- .../Response/GetProductsResponseTest.php | 4 +- tests/Model/ShippingProfileTest.php | 10 +- .../OrderRequestHandlerTest.php | 88 +++--- .../ProductRequestHandlerTest.php | 32 +- .../ShippingProfileRequestHandlerTest.php | 23 +- .../StockSyncRequestHandlerTest.php | 26 +- tests/Security/KeyAuthenticatorTest.php | 30 +- tests/autoload.php | 2 +- 63 files changed, 871 insertions(+), 1188 deletions(-) create mode 100644 phpstan.neon diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 406615b..8ab7a4f 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -37,3 +37,6 @@ jobs: - name: Run SCA run: composer run-script phpstan + + - name: Run CS + run: composer run-script fix-cs:dry-run diff --git a/.gitignore b/.gitignore index c3fbeb4..0b78b7e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ vendor/ composer.lock client.php -/.phpunit.result.cache -/.idea/ -/.php_cs.cache +.phpunit.result.cache +.idea/ +.php_cs.cache +.php-cs-fixer.cache diff --git a/CHANGELOG.md b/CHANGELOG.md index ad42bf2..178b84c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## v3.0.0 (22. Mar 2022) + +Changes: +- Added full PHP 8 support +- Removed support for pre PHP 7.4 +- Improved the code style and added SCA + - Added type hints +- Copyright updated + ## v2.1.1 (21. Mar 2022) Bug Fixes: diff --git a/composer.json b/composer.json index 6858dd8..98744d6 100644 --- a/composer.json +++ b/composer.json @@ -3,16 +3,20 @@ "description": "Implementation of the Billbee custom shop API in PHP", "type": "library", "require": { - "php": "5.6.* || ^7.0 || ^8.0", + "php": "^7.4 || ^8.0", "psr/http-message": "^1.0", "jms/serializer": "^1.14.0 || ^3.14.0", "ralouphie/getallheaders": "~3.0", - "mintware-de/streams": "^1.0", + "mintware-de/streams": "^2.0.0", "ext-json": "*" }, "require-dev": { - "phpunit/phpunit": "^5.7 || ^7.0 || ^8.0 || ^9.0", - "friendsofphp/php-cs-fixer": "^2.15" + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", + "friendsofphp/php-cs-fixer": "^v3.8.0", + "phpstan/phpstan": "^1.4" + }, + "suggest": { + "ext-xdebug": "*" }, "license": "MIT", "authors": [ @@ -32,6 +36,16 @@ "fix-cs": [ "./vendor/bin/php-cs-fixer fix ./src/ --using-cache=no --rules=@PSR2", "./vendor/bin/php-cs-fixer fix ./tests/ --using-cache=no --rules=@PSR2" + ], + "fix-cs:dry-run": [ + "./vendor/bin/php-cs-fixer fix ./src/ --using-cache=no --rules=@PSR2 --dry-run", + "./vendor/bin/php-cs-fixer fix ./tests/ --using-cache=no --rules=@PSR2 --dry-run" + ], + "phpstan": [ + "./vendor/bin/phpstan" + ], + "test": [ + "./vendor/bin/phpunit" ] }, "archive": { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..a4c8812 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + level: max + paths: + - src + - tests diff --git a/phpunit.xml b/phpunit.xml index 28f7a6a..d45b2c6 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,7 +2,7 @@