From fb458e4a1f84ec593dae8f862b75692769f86815 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 13 Jul 2020 13:00:14 +0100 Subject: [PATCH] Support PHP 7.1-8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Márk Sági-Kazár --- .gitattributes | 30 ++++----- .github/workflows/.editorconfig | 2 + .github/workflows/checks.yml | 18 ++++++ .github/workflows/ci.yml | 91 ++++++++++++++++++++++++++++ .github/workflows/static.yml | 34 +++++++++++ .gitignore | 3 +- .php_cs | 13 ---- .php_cs.dist | 16 +++++ composer.json | 30 +++++---- phpstan-baseline.neon | 22 +++++++ phpstan.neon.dist | 7 +++ src/Exception/HttpException.php | 5 +- src/Exception/NetworkException.php | 6 +- src/Exception/RequestException.php | 6 +- src/HttpAsyncClient.php | 2 +- src/Promise/HttpFulfilledPromise.php | 3 - src/Promise/HttpRejectedPromise.php | 3 - 17 files changed, 230 insertions(+), 61 deletions(-) create mode 100644 .github/workflows/.editorconfig create mode 100644 .github/workflows/checks.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/static.yml delete mode 100644 .php_cs create mode 100644 .php_cs.dist create mode 100644 phpstan-baseline.neon create mode 100644 phpstan.neon.dist diff --git a/.gitattributes b/.gitattributes index c47225a..60aab89 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,15 +1,15 @@ -.editorconfig export-ignore -.gitattributes export-ignore -/.github/ export-ignore -.gitignore export-ignore -/.php_cs export-ignore -/.scrutinizer.yml export-ignore -/.styleci.yml export-ignore -/.travis.yml export-ignore -/behat.yml.dist export-ignore -/features/ export-ignore -/phpspec.ci.yml export-ignore -/phpspec.yml.dist export-ignore -/phpunit.xml.dist export-ignore -/spec/ export-ignore -/tests/ export-ignore +.editorconfig export-ignore +.gitattributes export-ignore +/.github/ export-ignore +.gitignore export-ignore +/.php_cs.dist export-ignore +/.scrutinizer.yml export-ignore +/.styleci.yml export-ignore +/.travis.yml export-ignore +/phpspec.ci.yml export-ignore +/phpspec.yml.dist export-ignore +/phpstan-baseline.neon export-ignore +/phpstan.neon.dist export-ignore +/phpunit.xml.dist export-ignore +/spec/ export-ignore +/tests/ export-ignore diff --git a/.github/workflows/.editorconfig b/.github/workflows/.editorconfig new file mode 100644 index 0000000..7bd3346 --- /dev/null +++ b/.github/workflows/.editorconfig @@ -0,0 +1,2 @@ +[*.yml] +indent_size = 2 diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 0000000..85e49bf --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,18 @@ +name: Checks + +on: + push: + branches: + - master + pull_request: + + roave-bc-check: + name: Roave BC Check + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Roave BC Check + uses: docker://nyholm/roave-bc-check-ga diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c4cef58 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,91 @@ +name: CI + +on: + push: + pull_request: + +jobs: + latest: + name: PHP ${{ matrix.php }} Latest + runs-on: ubuntu-latest + strategy: + matrix: + php: ['7.1', '7.2', '7.3', '7.4', '8.0'] + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + coverage: none + + - name: Install PHP 7 dependencies + run: composer update --prefer-dist --no-interaction --no-progress + if: "matrix.php != '8.0'" + + - name: Install PHP 8 dependencies + run: | + composer require "phpdocumentor/reflection-docblock:^5.2@dev" --no-interaction --no-update + composer update --prefer-dist --prefer-stable --no-interaction --no-progress --ignore-platform-req=php + if: "matrix.php == '8.0'" + + - name: Execute tests + run: composer test + + lowest: + name: PHP ${{ matrix.php }} Lowest + runs-on: ubuntu-latest + strategy: + matrix: + php: ['7.1', '7.2', '7.3', '7.4'] + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + coverage: none + + - name: Install dependencies + run: | + composer require "sebastian/comparator:^3.0.2" --no-interaction --no-update + composer update --prefer-dist --prefer-stable --prefer-lowest --no-interaction --no-progress + + - name: Execute tests + run: composer test + + coverage: + name: Code Coverage + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 7.4 + tools: composer:v2 + coverage: xdebug + + - name: Install dependencies + run: | + composer require "friends-of-phpspec/phpspec-code-coverage:^4.3.2" --no-interaction --no-update + composer update --prefer-dist --no-interaction --no-progress + + - name: Execute tests + run: composer test-ci + + - name: Upload coverage + run: | + wget https://scrutinizer-ci.com/ocular.phar + php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 0000000..8257a56 --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,34 @@ +name: Static analysis + +on: + push: + branches: + - master + pull_request: + +jobs: + phpstan: + name: PHPStan + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: PHPStan + uses: docker://oskarstark/phpstan-ga + with: + args: analyze --no-progress + + php-cs-fixer: + name: PHP-CS-Fixer + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: PHP-CS-Fixer + uses: docker://oskarstark/php-cs-fixer-ga + with: + args: --dry-run --diff-format udiff diff --git a/.gitignore b/.gitignore index 16b4a20..1029e28 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -/behat.yml +.php_cs +.php_cs.cache /build/ /composer.lock /phpspec.yml diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 23ba165..0000000 --- a/.php_cs +++ /dev/null @@ -1,13 +0,0 @@ -setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + 'array_syntax' => ['syntax' => 'short'], + ]) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(__DIR__.'/src') + ->name('*.php') + ) +; + +return $config; diff --git a/composer.json b/composer.json index 9adab22..268b27e 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,12 @@ { "name": "php-http/httplug", "description": "HTTPlug, the HTTP client abstraction for PHP", - "license": "MIT", - "keywords": ["http", "client"], + "keywords": [ + "http", + "client" + ], "homepage": "http://httplug.io", + "license": "MIT", "authors": [ { "name": "Eric GELOEN", @@ -11,18 +14,24 @@ }, { "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com" + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" } ], "require": { - "php": "^7.0", - "psr/http-message": "^1.0", + "php": "^7.1 || ^8.0", + "php-http/promise": "^1.1", "psr/http-client": "^1.0", - "php-http/promise": "^1.0" + "psr/http-message": "^1.0" }, "require-dev": { - "phpspec/phpspec": "^4.3.4|^5.0|^6.0", - "friends-of-phpspec/phpspec-code-coverage" : "^4.1" + "friends-of-phpspec/phpspec-code-coverage": "^4.1", + "phpspec/phpspec": "^5.1 || ^6.0" + }, + "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + } }, "autoload": { "psr-4": { @@ -32,10 +41,5 @@ "scripts": { "test": "vendor/bin/phpspec run", "test-ci": "vendor/bin/phpspec run -c phpspec.ci.yml" - }, - "extra": { - "branch-alias": { - "dev-master": "2.x-dev" - } } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..d45d0a4 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,22 @@ +parameters: + ignoreErrors: + - + message: "#^Method Http\\\\Client\\\\Exception\\\\HttpException\\:\\:create\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/Exception/HttpException.php + + - + message: "#^Unsafe usage of new static\\(\\)\\.$#" + count: 1 + path: src/Exception/HttpException.php + + - + message: "#^Method Http\\\\Client\\\\Exception\\\\NetworkException\\:\\:setRequest\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/Exception/NetworkException.php + + - + message: "#^Method Http\\\\Client\\\\Exception\\\\RequestException\\:\\:setRequest\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/Exception/RequestException.php + diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..6f8227f --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,7 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: max + paths: + - src diff --git a/src/Exception/HttpException.php b/src/Exception/HttpException.php index 38337b5..6c2a007 100644 --- a/src/Exception/HttpException.php +++ b/src/Exception/HttpException.php @@ -20,10 +20,7 @@ class HttpException extends RequestException protected $response; /** - * @param string $message - * @param RequestInterface $request - * @param ResponseInterface $response - * @param \Exception|null $previous + * @param string $message */ public function __construct( $message, diff --git a/src/Exception/NetworkException.php b/src/Exception/NetworkException.php index d52a356..9b4f1e8 100644 --- a/src/Exception/NetworkException.php +++ b/src/Exception/NetworkException.php @@ -2,8 +2,8 @@ namespace Http\Client\Exception; -use Psr\Http\Message\RequestInterface; use Psr\Http\Client\NetworkExceptionInterface as PsrNetworkException; +use Psr\Http\Message\RequestInterface; /** * Thrown when the request cannot be completed because of network issues. @@ -17,9 +17,7 @@ class NetworkException extends TransferException implements PsrNetworkException use RequestAwareTrait; /** - * @param string $message - * @param RequestInterface $request - * @param \Exception|null $previous + * @param string $message */ public function __construct($message, RequestInterface $request, \Exception $previous = null) { diff --git a/src/Exception/RequestException.php b/src/Exception/RequestException.php index b548335..f6c60ce 100644 --- a/src/Exception/RequestException.php +++ b/src/Exception/RequestException.php @@ -2,8 +2,8 @@ namespace Http\Client\Exception; -use Psr\Http\Message\RequestInterface; use Psr\Http\Client\RequestExceptionInterface as PsrRequestException; +use Psr\Http\Message\RequestInterface; /** * Exception for when a request failed, providing access to the failed request. @@ -18,9 +18,7 @@ class RequestException extends TransferException implements PsrRequestException use RequestAwareTrait; /** - * @param string $message - * @param RequestInterface $request - * @param \Exception|null $previous + * @param string $message */ public function __construct($message, RequestInterface $request, \Exception $previous = null) { diff --git a/src/HttpAsyncClient.php b/src/HttpAsyncClient.php index bc9d5ee..c3b9d61 100644 --- a/src/HttpAsyncClient.php +++ b/src/HttpAsyncClient.php @@ -17,7 +17,7 @@ interface HttpAsyncClient * * Exceptions related to processing the request are available from the returned Promise. * - * @return Promise Resolves a PSR-7 Response or fails with an Http\Client\Exception. + * @return Promise resolves a PSR-7 Response or fails with an Http\Client\Exception * * @throws \Exception If processing the request is impossible (eg. bad configuration). */ diff --git a/src/Promise/HttpFulfilledPromise.php b/src/Promise/HttpFulfilledPromise.php index 6779e44..1ad32cd 100644 --- a/src/Promise/HttpFulfilledPromise.php +++ b/src/Promise/HttpFulfilledPromise.php @@ -13,9 +13,6 @@ final class HttpFulfilledPromise implements Promise */ private $response; - /** - * @param ResponseInterface $response - */ public function __construct(ResponseInterface $response) { $this->response = $response; diff --git a/src/Promise/HttpRejectedPromise.php b/src/Promise/HttpRejectedPromise.php index bfb0738..8af97de 100644 --- a/src/Promise/HttpRejectedPromise.php +++ b/src/Promise/HttpRejectedPromise.php @@ -12,9 +12,6 @@ final class HttpRejectedPromise implements Promise */ private $exception; - /** - * @param Exception $exception - */ public function __construct(Exception $exception) { $this->exception = $exception;