Total Complexity | 6 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
12 | class Count42Rule extends Rule |
||
13 | { |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $operator; |
||
18 | |||
19 | /** |
||
20 | * @var int |
||
21 | */ |
||
22 | protected $count; |
||
23 | |||
24 | public function __construct() |
||
25 | { |
||
26 | $this->operator = self::OPERATOR_EQ; |
||
27 | } |
||
28 | |||
29 | public function match(RuleScope $scope): bool |
||
30 | { |
||
31 | switch ($this->operator) { |
||
32 | case self::OPERATOR_EQ: |
||
33 | return $this->count === 42; |
||
34 | case self::OPERATOR_NEQ: |
||
35 | return $this->count !== 42; |
||
36 | default: |
||
37 | throw new UnsupportedOperatorException($this->operator, __CLASS__); |
||
38 | } |
||
39 | } |
||
40 | |||
41 | public function getConstraints(): array |
||
42 | { |
||
43 | return [ |
||
44 | 'operator' => [new Choice([self::OPERATOR_EQ, self::OPERATOR_NEQ])], |
||
45 | 'count' => [new NotBlank(), new Type('int')], |
||
46 | ]; |
||
47 | } |
||
48 | |||
49 | public function getName(): string |
||
50 | { |
||
51 | return 'swagCount42'; |
||
52 | } |
||
54 |