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

DataLoaderOptions   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 50
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A shouldBatch() 0 4 1
A getMaxBatchSize() 0 4 1
A shouldCache() 0 4 1
A validateMaxBatchSizeOption() 0 6 3
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