Skip to content

Commit d888a3a

Browse files
committed
Bumped dependencies and php version 7.4. Also updated Changelog to reflect changes
1 parent 22e3b64 commit d888a3a

File tree

8 files changed

+43
-83
lines changed

8 files changed

+43
-83
lines changed

.scrutinizer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
build:
22
environment:
33
php:
4-
version: 5.5
4+
version: 7.4
55
dependencies:
66
before:
77
- composer install --dev --prefer-source --no-interaction

.travis.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
language: php
22

33
php:
4-
- "7.2"
5-
- "7.1"
6-
- "7.0"
7-
- "5.6"
8-
- "5.5"
4+
- "7.4"
95

106
sudo: false
117

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Changelog
22

33
## Updating from 1.0.0 to 2.0.0
4-
- Overall php version requirement was bumped from `5.5` to `7.3`
4+
- Overall php version requirement was bumped from `5.5` to `7.4`
5+
- Bumped version requirements for React dependencies and switched DataLoader to return ExtendedPromiseInterfaces instead of PromiseInterfaces.
56
- Fluent interfaces in `Dataloader::prime()`,`DataLoader::clear` and `DataLoader::clearAll()` were removed. So change usages like:
67
```php
78
$dataloader->clear('A')->prime('A', 'Y');

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
"keywords": ["batch loading", "dataloader", "graphql"],
66
"require": {
77
"react/promise": "^2.7.1",
8-
"react/event-loop": "^1.1.0",
9-
"php": "^7.3.0"
8+
"react/event-loop": "^1.1.1",
9+
"php": "^7.4.0"
1010
},
1111
"require-dev" : {
12-
"phpunit/phpunit": "^8.0.2"
12+
"phpunit/phpunit": "^9.1.4"
1313
},
1414
"license": "MIT",
1515
"authors": [

src/CacheMap.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
final class CacheMap implements CacheMapInterface, \Countable
66
{
7-
/**
8-
* @var array
9-
*/
10-
private $cache = [];
7+
private array $cache = [];
118

129
/**
1310
* {@inheritdoc}

src/DataLoader.php

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,13 @@ final class DataLoader implements DataLoaderInterface
1616
*/
1717
private $batchLoadFunction;
1818

19-
/**
20-
* @var array
21-
*/
22-
private $promiseQueue = [];
19+
private array $promiseQueue = [];
2320

24-
/**
25-
* @var CacheMapInterface
26-
*/
27-
private $promiseCache;
21+
private CacheMapInterface $promiseCache;
2822

29-
/**
30-
* @var LoopInterface
31-
*/
32-
private $eventLoop;
23+
private LoopInterface $eventLoop;
3324

34-
/**
35-
* @var DataLoaderOptions
36-
*/
37-
private $options;
25+
private DataLoaderOptions $options;
3826

3927
/**
4028
* Initiates a new DataLoader.
@@ -98,9 +86,7 @@ public function loadMany(array $keys): ExtendedPromiseInterface
9886
{
9987
return all(
10088
\array_map(
101-
function ($key) {
102-
return $this->load($key);
103-
},
89+
fn($key) => $this->load($key),
10490
$keys
10591
)
10692
);
@@ -146,9 +132,7 @@ private function scheduleDispatch(): void
146132
{
147133
if ($this->options->shouldBatch()) {
148134
$this->eventLoop->futureTick(
149-
function () {
150-
$this->dispatchQueue();
151-
}
135+
fn() => $this->dispatchQueue()
152136
);
153137

154138
return;
@@ -168,12 +152,13 @@ private function dispatchQueue(): void
168152
$this->promiseQueue = [];
169153

170154
$maxBatchSize = $this->options->getMaxBatchSize();
155+
$shouldBeDispatchedInMultipleBatches = $maxBatchSize !== null
156+
&& $maxBatchSize > 0
157+
&& $maxBatchSize < count($queue);
171158

172-
if ($maxBatchSize !== null && $maxBatchSize > 0 && $maxBatchSize < count($queue)) {
173-
$this->dispatchQueueInMultipleBatches($queue, $maxBatchSize);
174-
} else {
175-
$this->dispatchQueueBatch($queue);
176-
}
159+
$shouldBeDispatchedInMultipleBatches
160+
? $this->dispatchQueueInMultipleBatches($queue, $maxBatchSize)
161+
: $this->dispatchQueueBatch($queue);
177162
}
178163

179164
/**
@@ -195,14 +180,14 @@ private function dispatchQueueBatch($batch)
195180
return $this->handleFailedDispatch($batch, $exception);
196181
}
197182

198-
$batchPromise->then(
199-
function ($values) use ($batch, $keys) {
200-
$this->validateBatchPromiseOutput($values, $keys);
201-
$this->handleSuccessfulDispatch($batch, $values);
202-
}
203-
)->then(null, function ($error) use ($batch) {
204-
$this->handleFailedDispatch($batch, $error);
205-
});
183+
$batchPromise
184+
->then(
185+
function ($values) use ($batch, $keys) {
186+
$this->validateBatchPromiseOutput($values, $keys);
187+
$this->handleSuccessfulDispatch($batch, $values);
188+
}
189+
)
190+
->then(null, fn($error) => $this->handleFailedDispatch($batch, $error));
206191
}
207192

208193
/**
@@ -234,11 +219,9 @@ private function handleSuccessfulDispatch(array $batch, array $values): void
234219
{
235220
foreach ($batch as $index => $queueItem) {
236221
$value = $values[$index];
237-
if ($value instanceof \Exception) {
238-
$queueItem['reject']($value);
239-
} else {
240-
$queueItem['resolve']($value);
241-
}
222+
$value instanceof \Exception
223+
? $queueItem['reject']($value)
224+
: $queueItem['resolve']($value);
242225
}
243226
}
244227

src/DataLoaderOptions.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,11 @@
44

55
final class DataLoaderOptions
66
{
7-
/**
8-
* @var bool
9-
*/
10-
private $shouldBatch;
11-
12-
/**
13-
* @var null|int
14-
*/
15-
private $maxBatchSize;
16-
17-
/**
18-
* @var bool
19-
*/
20-
private $shouldCache;
7+
private bool $shouldBatch;
8+
9+
private ?int $maxBatchSize;
10+
11+
private bool $shouldCache;
2112

2213
public function __construct(
2314
?int $maxBatchSize = null,

tests/Unit/DataLoaderTest.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public function setUp(): void
3737
public function it_builds_a_really_simple_data_loader()
3838
{
3939
$identityLoader = new DataLoader(
40-
function ($keys) {
41-
return resolve($keys);
42-
}, $this->eventLoop, new CacheMap()
40+
fn($keys) => resolve($keys),
41+
$this->eventLoop,
42+
new CacheMap()
4343
);
4444

4545
/** @var Promise $promise1 */
@@ -888,14 +888,8 @@ function ($keys) {
888888
$this->loadCalls[] = $keys;
889889

890890
return resolve(
891-
array_map(
892-
function ($key) {
893-
if ($key % 2 === 0) {
894-
return $key;
895-
}
896-
897-
return new \Exception("Odd: {$key}");
898-
},
891+
\array_map(
892+
fn($key) => ($key % 2 === 0) ? $key : new \Exception("Odd: {$key}");
899893
$keys
900894
)
901895
);
@@ -917,10 +911,8 @@ function ($keys) {
917911
$this->loadCalls[] = $keys;
918912

919913
return resolve(
920-
array_map(
921-
function ($key) {
922-
return new \Exception("Error: {$key}");
923-
},
914+
\array_map(
915+
fn($key) => new \Exception("Error: {$key}"),
924916
$keys
925917
)
926918
);

0 commit comments

Comments
 (0)