Skip to content

Commit 3088f39

Browse files
committed
Use strict typing
1 parent bfa65ca commit 3088f39

File tree

6 files changed

+20
-36
lines changed

6 files changed

+20
-36
lines changed

src/CacheMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace leinonen\DataLoader;
44

src/CacheMapInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace leinonen\DataLoader;
44

src/DataLoader.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace leinonen\DataLoader;
44

5+
use function React\Promise\all;
56
use React\Promise\ExtendedPromiseInterface;
67
use React\Promise\Promise;
78
use React\EventLoop\LoopInterface;
9+
use function React\Promise\reject;
10+
use function React\Promise\resolve;
811

912
final class DataLoader implements DataLoaderInterface
1013
{
@@ -51,7 +54,7 @@ public function __construct(
5154
$this->batchLoadFunction = $batchLoadFunction;
5255
$this->eventLoop = $loop;
5356
$this->promiseCache = $cacheMap;
54-
$this->options = $options === null ? new DataLoaderOptions() : $options;
57+
$this->options = $options ?? new DataLoaderOptions();
5558
}
5659

5760
/**
@@ -93,7 +96,7 @@ function (callable $resolve, callable $reject) use ($key) {
9396
*/
9497
public function loadMany(array $keys): ExtendedPromiseInterface
9598
{
96-
return \React\Promise\all(
99+
return all(
97100
\array_map(
98101
function ($key) {
99102
return $this->load($key);
@@ -127,7 +130,7 @@ public function prime($key, $value): void
127130
if (! $this->promiseCache->get($key)) {
128131
// Cache a rejected promise if the value is an Exception, in order to match
129132
// 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);
131134

132135
$this->promiseCache->set($key, $promise);
133136
}

src/DataLoaderException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace leinonen\DataLoader;
44

src/DataLoaderInterface.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace leinonen\DataLoader;
44

@@ -13,7 +13,7 @@ interface DataLoaderInterface
1313
*
1414
* @param mixed $key
1515
*
16-
* @return Promise
16+
* @return ExtendedPromiseInterface
1717
* @throws \InvalidArgumentException
1818
*/
1919
public function load($key): ExtendedPromiseInterface;
@@ -30,7 +30,7 @@ public function load($key): ExtendedPromiseInterface;
3030
*
3131
* @param array $keys
3232
*
33-
* @return Promise
33+
* @return ExtendedPromiseInterface
3434
* @throws \InvalidArgumentException
3535
*/
3636
public function loadMany(array $keys): ExtendedPromiseInterface;
@@ -40,14 +40,14 @@ public function loadMany(array $keys): ExtendedPromiseInterface;
4040
*
4141
* @param int|string $key
4242
*
43-
* @return $this
43+
* @return void
4444
*/
4545
public function clear($key): void;
4646

4747
/**
4848
* Clears the entire cache. Returns itself for method chaining.
4949
*
50-
* @return $this
50+
* @return void
5151
*/
5252
public function clearAll(): void;
5353

@@ -58,7 +58,7 @@ public function clearAll(): void;
5858
* @param int|string $key
5959
* @param int|string $value
6060
*
61-
* @return $this
61+
* @return void
6262
*/
6363
public function prime($key, $value): void;
6464
}

src/DataLoaderOptions.php

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace leinonen\DataLoader;
44

@@ -7,7 +7,7 @@ final class DataLoaderOptions
77
/**
88
* @var bool
99
*/
10-
private $shouldBatch;
10+
private $shouldBatch;
1111

1212
/**
1313
* @var null|int
@@ -19,13 +19,6 @@ final class DataLoaderOptions
1919
*/
2020
private $shouldCache;
2121

22-
/**
23-
* Initiates new DataLoaderOptions.
24-
*
25-
* @param null|int $maxBatchSize
26-
* @param bool $shouldBatch
27-
* @param bool $shouldCache
28-
*/
2922
public function __construct(
3023
?int $maxBatchSize = null,
3124
bool $shouldBatch = true,
@@ -37,36 +30,24 @@ public function __construct(
3730
$this->shouldCache = $shouldCache;
3831
}
3932

40-
/**
41-
* @return bool
42-
*/
4333
public function shouldBatch(): bool
4434
{
4535
return $this->shouldBatch;
4636
}
4737

48-
/**
49-
* @return null|int
50-
*/
5138
public function getMaxBatchSize(): ?int
5239
{
5340
return $this->maxBatchSize;
5441
}
5542

56-
/**
57-
* @return bool
58-
*/
5943
public function shouldCache(): bool
6044
{
6145
return $this->shouldCache;
6246
}
6347

64-
/**
65-
* @param null|int $maxBatchSize
66-
*/
67-
private function validateMaxBatchSizeOption($maxBatchSize)
48+
private function validateMaxBatchSizeOption(?int $maxBatchSize)
6849
{
69-
if (($maxBatchSize !== null && ! \is_int($maxBatchSize)) || (int) $maxBatchSize < 0) {
50+
if ($maxBatchSize !== null && $maxBatchSize < 0) {
7051
throw new \InvalidArgumentException('Expected argument $maxBatchSize to be null or a positive integer');
7152
}
7253
}

0 commit comments

Comments
 (0)