diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e0c7558..68636ec 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,7 +11,7 @@ jobs: - 8080:80 strategy: matrix: - php-versions: [ '8.0', '8.1' ] + php-versions: [ '8.0', '8.1', '8.2', '8.3', '8.4' ] composer-options: [ '--prefer-lowest', ''] runs-on: ubuntu-latest steps: diff --git a/Curl/CurlErrorException.php b/Curl/CurlErrorException.php index 540c966..3963a67 100644 --- a/Curl/CurlErrorException.php +++ b/Curl/CurlErrorException.php @@ -9,9 +9,11 @@ namespace evaisse\SimpleHttpBundle\Curl; +use Exception; + class CurlErrorException extends \RuntimeException { - public function __construct($message="", $code=0, \Exception $previous=null) { + public function __construct($message="", $code=0, ?Exception $previous=null) { parent::__construct($message,$code,$previous); } } \ No newline at end of file diff --git a/Curl/MultiManager.php b/Curl/MultiManager.php index 27da64e..45f4cb1 100644 --- a/Curl/MultiManager.php +++ b/Curl/MultiManager.php @@ -57,7 +57,8 @@ class MultiManager implements CurlRequest * @param boolean $blocking Whether the execution should block until finished or wait until * the destructor is called to block */ - public function __construct(EventDispatcherInterface $dispatcher=null,$blocking=true) { + public function __construct(?EventDispatcherInterface $dispatcher = null, $blocking = true) + { $this->dispatcher = $dispatcher; $this->handle = curl_multi_init(); $this->blocking = $blocking; diff --git a/Http/Exception/RequestException.php b/Http/Exception/RequestException.php index af5ddd2..e557d5a 100644 --- a/Http/Exception/RequestException.php +++ b/Http/Exception/RequestException.php @@ -26,7 +26,7 @@ class RequestException extends Exception * @param int $code error code * @param Exception $previous optionnal previous exception */ - public function __construct(Request $request, $message = "", $code = 0, Exception $previous = null) + public function __construct(Request $request, $message = "", $code = 0, ?Exception $previous = null) { parent::__construct($message, $code, $previous); // TODO: Change the autogenerated stub $this->setRequest($request); diff --git a/Http/Statement.php b/Http/Statement.php index ecaf69f..c6b067f 100644 --- a/Http/Statement.php +++ b/Http/Statement.php @@ -427,7 +427,11 @@ public function onProgress(callable $callable) */ public function onFinish(callable $callable) { - $this->getPromise()->always($callable); + if (method_exists(object_or_class: $this->getPromise(), method: 'finally')) { + $this->getPromise()->finally($callable); + } else { + $this->getPromise()->always($callable); + } return $this; } diff --git a/Service/Helper.php b/Service/Helper.php index d352b59..bb6b5fc 100644 --- a/Service/Helper.php +++ b/Service/Helper.php @@ -58,7 +58,7 @@ public function createCookieJar(?SessionInterface $session = null): SessionCooki * @param Kernel|null $client http client proxy to use * @return Helper given service list */ - public function execute(array $servicesList, ?SessionCookieJar $cookieJar = null, Kernel $client = null): static + public function execute(array $servicesList, ?SessionCookieJar $cookieJar = null, ?Kernel $client = null): static { $httpClient = $client ? $client : $this->httpKernel; diff --git a/Tests/Unit/AbstractTests.php b/Tests/Unit/AbstractTests.php index bd6af2f..8f51600 100644 --- a/Tests/Unit/AbstractTests.php +++ b/Tests/Unit/AbstractTests.php @@ -24,6 +24,9 @@ public function __construct(?string $name = null, array $data = [], $dataName = } + /** + * @return array{0: Helper, 1: Kernel} + */ protected function createContext() { $eventDispatcher = new EventDispatcher(); diff --git a/Tests/Unit/PromisesTest.php b/Tests/Unit/PromisesTest.php index 90238ef..71f8083 100644 --- a/Tests/Unit/PromisesTest.php +++ b/Tests/Unit/PromisesTest.php @@ -8,6 +8,7 @@ namespace evaisse\SimpleHttpBundle\Tests\Unit; +use React\Promise\Promise; use Symfony\Component\HttpKernel\Exception\HttpException; class PromisesTest extends AbstractTests @@ -37,11 +38,14 @@ public function testPromises($code, $expectedResults) $events = new \ArrayObject(); + $finallyMethod = method_exists(object_or_class: Promise::class, method: 'always') ? 'always' : 'finally'; + $catchMethod = method_exists(object_or_class: Promise::class, method: 'catch') ? 'catch' : 'otherwise'; + $stmt->getPromise()->then(function () use ($events) { $events[] = 'success'; - })->otherwise(function () use ($events) { + })->$catchMethod(function () use ($events) { $events[] = 'error'; - })->done(function () use ($events) { + })->$finallyMethod(function () use ($events) { $events[] = 'done'; }); diff --git a/composer.json b/composer.json index ebc268c..04aa0f6 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "homepage": "https://github.com/evaisse/SimpleHttpBundle", "require": { "php": "^8.0", - "react/promise": "^2.2", + "react/promise": "^2.2 || ^3.0", "symfony/http-foundation": "^5.4 || ^6.0", "symfony/browser-kit": "^5.4 || ^6.0", "symfony/event-dispatcher": "^5.4 || ^6.0", diff --git a/composer.lock b/composer.lock index a585f36..77c7583 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "8dce778de0f415aa44c7d9a8f5049aa3", + "content-hash": "e7207ed456099c2e8a9b03fc6ec27fc1", "packages": [ { "name": "doctrine/annotations", @@ -430,23 +430,24 @@ }, { "name": "react/promise", - "version": "v2.11.0", + "version": "v3.3.0", "source": { "type": "git", "url": "https://github.com/reactphp/promise.git", - "reference": "1a8460931ea36dc5c76838fec5734d55c88c6831" + "reference": "23444f53a813a3296c1368bb104793ce8d88f04a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/promise/zipball/1a8460931ea36dc5c76838fec5734d55c88c6831", - "reference": "1a8460931ea36dc5c76838fec5734d55c88c6831", + "url": "https://api.github.com/repos/reactphp/promise/zipball/23444f53a813a3296c1368bb104793ce8d88f04a", + "reference": "23444f53a813a3296c1368bb104793ce8d88f04a", "shasum": "" }, "require": { - "php": ">=5.4.0" + "php": ">=7.1.0" }, "require-dev": { - "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36" + "phpstan/phpstan": "1.12.28 || 1.4.10", + "phpunit/phpunit": "^9.6 || ^7.5" }, "type": "library", "autoload": { @@ -490,7 +491,7 @@ ], "support": { "issues": "https://github.com/reactphp/promise/issues", - "source": "https://github.com/reactphp/promise/tree/v2.11.0" + "source": "https://github.com/reactphp/promise/tree/v3.3.0" }, "funding": [ { @@ -498,7 +499,7 @@ "type": "open_collective" } ], - "time": "2023-11-16T16:16:50+00:00" + "time": "2025-08-19T18:57:03+00:00" }, { "name": "sensio/framework-extra-bundle", @@ -6377,6 +6378,6 @@ "ext-json": "*", "ext-curl": "*" }, - "platform-dev": [], + "platform-dev": {}, "plugin-api-version": "2.6.0" }