|
1 | | -<?php |
| 1 | +<?php declare(strict_types=1); |
2 | 2 |
|
3 | 3 | namespace leinonen\DataLoader; |
4 | 4 |
|
| 5 | +use function React\Promise\all; |
5 | 6 | use React\Promise\ExtendedPromiseInterface; |
6 | 7 | use React\Promise\Promise; |
7 | 8 | use React\EventLoop\LoopInterface; |
| 9 | +use function React\Promise\reject; |
| 10 | +use function React\Promise\resolve; |
8 | 11 |
|
9 | 12 | final class DataLoader implements DataLoaderInterface |
10 | 13 | { |
@@ -51,7 +54,7 @@ public function __construct( |
51 | 54 | $this->batchLoadFunction = $batchLoadFunction; |
52 | 55 | $this->eventLoop = $loop; |
53 | 56 | $this->promiseCache = $cacheMap; |
54 | | - $this->options = $options === null ? new DataLoaderOptions() : $options; |
| 57 | + $this->options = $options ?? new DataLoaderOptions(); |
55 | 58 | } |
56 | 59 |
|
57 | 60 | /** |
@@ -93,7 +96,7 @@ function (callable $resolve, callable $reject) use ($key) { |
93 | 96 | */ |
94 | 97 | public function loadMany(array $keys): ExtendedPromiseInterface |
95 | 98 | { |
96 | | - return \React\Promise\all( |
| 99 | + return all( |
97 | 100 | \array_map( |
98 | 101 | function ($key) { |
99 | 102 | return $this->load($key); |
@@ -127,7 +130,7 @@ public function prime($key, $value): void |
127 | 130 | if (! $this->promiseCache->get($key)) { |
128 | 131 | // Cache a rejected promise if the value is an Exception, in order to match |
129 | 132 | // the behavior of load($key). |
130 | | - $promise = $value instanceof \Exception ? \React\Promise\reject($value) : \React\Promise\resolve($value); |
| 133 | + $promise = $value instanceof \Exception ? reject($value) : resolve($value); |
131 | 134 |
|
132 | 135 | $this->promiseCache->set($key, $promise); |
133 | 136 | } |
|
0 commit comments