Skip to content

Commit d3712e4

Browse files
authored
Merge pull request #141 from jsor-labs/throwable-type-improvements
Throwable type improvements
2 parents cedffca + 8967d23 commit d3712e4

5 files changed

Lines changed: 13 additions & 54 deletions

File tree

src/Deferred.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function resolve($value = null)
3636
\call_user_func($this->resolveCallback, $value);
3737
}
3838

39-
public function reject($reason)
39+
public function reject(\Throwable $reason)
4040
{
4141
$this->promise();
4242

src/Promise.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private function resolve($value = null)
129129
$this->settle(resolve($value));
130130
}
131131

132-
private function reject($reason)
132+
private function reject(\Throwable $reason)
133133
{
134134
if (null !== $this->result) {
135135
return;
@@ -198,7 +198,7 @@ private function call(callable $callback)
198198
function ($value = null) {
199199
$this->resolve($value);
200200
},
201-
function ($reason) {
201+
function (\Throwable $reason) {
202202
$this->reject($reason);
203203
}
204204
);

src/RejectedPromise.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function otherwise(callable $onRejected)
6262

6363
public function always(callable $onFulfilledOrRejected)
6464
{
65-
return $this->then(null, function ($reason) use ($onFulfilledOrRejected) {
65+
return $this->then(null, function (\Throwable $reason) use ($onFulfilledOrRejected) {
6666
return resolve($onFulfilledOrRejected())->then(function () use ($reason) {
6767
return new RejectedPromise($reason);
6868
});

src/functions.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ function resolve($promiseOrValue = null)
4141
}
4242

4343
/**
44-
* Creates a rejected promise for the supplied `$promiseOrValue`.
44+
* Creates a rejected promise for the supplied `$reason`.
4545
*
46-
* If `$promiseOrValue` is a value, it will be the rejection value of the
46+
* If `$reason` is a value, it will be the rejection value of the
4747
* returned promise.
4848
*
49-
* If `$promiseOrValue` is a promise, its completion value will be the rejected
49+
* If `$reason` is a promise, its completion value will be the rejected
5050
* value of the returned promise.
5151
*
5252
* This can be useful in situations where you need to reject a promise without
5353
* throwing an exception. For example, it allows you to propagate a rejection with
5454
* the value of another promise.
5555
*
56-
* @param \Throwable $promiseOrValue
56+
* @param \Throwable $reason
5757
* @return PromiseInterface
5858
*/
5959
function reject(\Throwable $reason)
@@ -188,7 +188,7 @@ function some(array $promisesOrValues, $howMany)
188188
}
189189
};
190190

191-
$rejecter = function ($reason) use ($i, &$reasons, &$toReject, $toResolve, $reject) {
191+
$rejecter = function (\Throwable $reason) use ($i, &$reasons, &$toReject, $toResolve, $reject) {
192192
if ($toResolve < 1 || $toReject < 1) {
193193
return;
194194
}
@@ -324,12 +324,8 @@ function fatalError($error)
324324
/**
325325
* @internal
326326
*/
327-
function _checkTypehint(callable $callback, $object)
327+
function _checkTypehint(callable $callback, \Throwable $reason)
328328
{
329-
if (!\is_object($object)) {
330-
return true;
331-
}
332-
333329
if (\is_array($callback)) {
334330
$callbackReflection = new \ReflectionMethod($callback[0], $callback[1]);
335331
} elseif (\is_object($callback) && !$callback instanceof \Closure) {
@@ -344,11 +340,11 @@ function _checkTypehint(callable $callback, $object)
344340
return true;
345341
}
346342

347-
$expectedException = $parameters[0];
343+
$expectedClass = $parameters[0]->getClass();
348344

349-
if (!$expectedException->getClass()) {
345+
if (!$expectedClass) {
350346
return true;
351347
}
352348

353-
return $expectedException->getClass()->isInstance($object);
349+
return $expectedClass->isInstance($reason);
354350
}

tests/FunctionalRejectTest.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)