GermValidator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PanicLabCore\Services\Validators;
6
7
use Webmozart\Assert\Assert;
8
9
class GermValidator implements ValidatorInterface
10
{
11
    /** @var string[] */
12
    private $germColors;
13
14
    /** @var string[] */
15
    private $germStyles;
16
17
    /** @var string[] */
18
    private $germSizes;
19
20
    /**
21
     * @param string[] $germColors
22
     * @param string[] $germStyles
23
     * @param string[] $germSizes
24
     */
25 23
    public function __construct(array $germColors, array $germStyles, array $germSizes)
26
    {
27 23
        $this->germColors = $germColors;
28 23
        $this->germStyles = $germStyles;
29 23
        $this->germSizes = $germSizes;
30 23
    }
31
32 18
    public function validate(array $tile): void
33
    {
34 18
        Assert::keyExists($tile, 'additional');
35
36 17
        $additionalData = $tile['additional'];
37
38 17
        Assert::keyExists($additionalData, 'color');
39 16
        Assert::keyExists($additionalData, 'style');
40 15
        Assert::keyExists($additionalData, 'size');
41
42 14
        Assert::oneOf($additionalData['color'], $this->germColors);
43 13
        Assert::oneOf($additionalData['style'], $this->germStyles);
44 12
        Assert::oneOf($additionalData['size'], $this->germSizes);
45 11
    }
46
}
47