Passed
Push — master ( 0c0f23...09d191 )
by Juuso
02:11
created

DataLoaderOptions::shouldBatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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