diff --git a/composer.json b/composer.json index df3eb4bf..79921091 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ ], "require": { "php": ">=7.0.0", - "react/promise": "~2.2" + "react/promise": "^3 || ~2.2" }, "require-dev": { "satooshi/php-coveralls": "~1.0", diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 00000000..18ad3d5e --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,8 @@ +parameters: + level: max + + paths: + - test/types/ + + fileExtensions: + - php \ No newline at end of file diff --git a/src/React/Promise.php b/src/React/Promise.php index c8efacfc..bd384191 100644 --- a/src/React/Promise.php +++ b/src/React/Promise.php @@ -2,7 +2,6 @@ namespace Rx\React; -use React\Promise\CancellablePromiseInterface; use React\Promise\Promise as ReactPromise; use React\Promise\PromiseInterface; use Rx\Disposable\CallbackDisposable; @@ -11,6 +10,7 @@ use Rx\Observable\AnonymousObservable; use Rx\Subject\AsyncSubject; use React\Promise\Deferred; +use Throwable; final class Promise { @@ -32,7 +32,7 @@ public static function resolved($value): ReactPromise public static function rejected($exception): ReactPromise { $d = new Deferred(); - $d->reject($exception); + $d->reject($exception instanceof Throwable ? $exception : new RejectedPromiseException($exception)); return $d->promise(); } @@ -94,7 +94,7 @@ function ($error) use ($subject) { $disp = $subject->subscribe($observer); return new CallbackDisposable(function () use ($p, $disp) { $disp->dispose(); - if ($p instanceof CancellablePromiseInterface) { + if (\method_exists($p, 'cancel')) { $p->cancel(); } }); diff --git a/test/Rx/Functional/Promise/FromPromiseTest.php b/test/Rx/Functional/Promise/FromPromiseTest.php index a3be98da..16483c8e 100644 --- a/test/Rx/Functional/Promise/FromPromiseTest.php +++ b/test/Rx/Functional/Promise/FromPromiseTest.php @@ -40,7 +40,7 @@ function () { */ public function from_promise_failure() { - $p = \React\Promise\reject('error'); + $p = \React\Promise\reject(new RejectedPromiseException('error')); $source = Observable::fromPromise($p);