Test Setup Failed
Push — master ( d8a2c4...22e3b6 )
by Juuso
03:25
created

DataLoaderOptions::validateBatchOption()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php declare(strict_types=1);
2
3
namespace leinonen\DataLoader;
4
5
final class DataLoaderOptions
6
{
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;
21
22
    public function __construct(
23
        ?int $maxBatchSize = null,
24
        bool $shouldBatch = true,
25
        bool $shouldCache = true
26
    ) {
27
        $this->validateMaxBatchSizeOption($maxBatchSize);
28
        $this->shouldBatch = $shouldBatch;
29 37
        $this->maxBatchSize = $maxBatchSize;
30
        $this->shouldCache = $shouldCache;
31
    }
32
33
    public function shouldBatch(): bool
34 37
    {
35 33
        return $this->shouldBatch;
36 33
    }
37 33
38 33
    public function getMaxBatchSize(): ?int
39
    {
40
        return $this->maxBatchSize;
41
    }
42
43 30
    public function shouldCache(): bool
44
    {
45 30
        return $this->shouldCache;
46
    }
47
48
    private function validateMaxBatchSizeOption(?int $maxBatchSize)
49
    {
50
        if ($maxBatchSize !== null && $maxBatchSize < 0) {
51 29
            throw new \InvalidArgumentException('Expected argument $maxBatchSize to be null or a positive integer');
52
        }
53 29
    }
54
}
55