DiceValidator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 51
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A validate() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PanicLabCore\Services\Validators;
6
7
use Webmozart\Assert\Assert;
8
9
class DiceValidator 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
    /** @var string[] */
21
    private $entryColors;
22
23
    /** @var string[] */
24
    private $entryDirections;
25
26
    /**
27
     * @param string[] $germColors
28
     * @param string[] $germStyles
29
     * @param string[] $germSizes
30
     * @param string[] $entryColors
31
     * @param string[] $entryDirections
32
     */
33 14
    public function __construct(
34
        array $germColors,
35
        array $germStyles,
36
        array $germSizes,
37
        array $entryColors,
38
        array $entryDirections
39
    ) {
40 14
        $this->germColors = $germColors;
41 14
        $this->germStyles = $germStyles;
42 14
        $this->germSizes = $germSizes;
43 14
        $this->entryColors = $entryColors;
44 14
        $this->entryDirections = $entryDirections;
45 14
    }
46
47 11
    public function validate(array $diceData): void
48
    {
49 11
        Assert::keyExists($diceData, 'germColor');
50 10
        Assert::keyExists($diceData, 'germSize');
51 9
        Assert::keyExists($diceData, 'germStyle');
52 8
        Assert::keyExists($diceData, 'entryColor');
53 7
        Assert::keyExists($diceData, 'entryDirection');
54
55 6
        Assert::oneOf($diceData['germColor'], $this->germColors);
56 5
        Assert::oneOf($diceData['germSize'], $this->germSizes);
57 4
        Assert::oneOf($diceData['germStyle'], $this->germStyles);
58 3
        Assert::oneOf($diceData['entryColor'], $this->entryColors);
59 2
        Assert::oneOf($diceData['entryDirection'], $this->entryDirections);
60 1
    }
61
}
62