Total Complexity | 11 |
Total Lines | 69 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
7 | final class Operator |
||
8 | { |
||
9 | private $operator; |
||
10 | |||
11 | 7 | private function __construct(array $params) |
|
12 | { |
||
13 | 7 | $this->operator = $params['operator']; |
|
14 | 7 | } |
|
15 | |||
16 | 3 | public static function getDefault() : Operator |
|
22 | ]); |
||
23 | } |
||
24 | |||
25 | 2 | public function getMeta() : string |
|
26 | { |
||
27 | 2 | return $this->operator['meta']; |
|
28 | } |
||
29 | |||
30 | 4 | public static function fromRawValue(array $operator) : Operator |
|
31 | { |
||
32 | 4 | if (!isset($operator['meta'])) { |
|
33 | 1 | throw new \RuntimeException( |
|
34 | 1 | 'Oops! Raw operator must contain `meta` parameter' |
|
35 | ); |
||
36 | } |
||
37 | |||
38 | 3 | return new self([ |
|
39 | 3 | 'operator' => $operator, |
|
40 | ]); |
||
41 | } |
||
42 | |||
43 | 3 | public static function fromFilteringObject( |
|
44 | FilteringObject $filteringObject |
||
45 | ) : Operator { |
||
46 | 3 | if(true === $filteringObject->hasOperator()){ |
|
47 | 2 | $operatorName = $filteringObject->getOperator(); |
|
48 | 2 | $operator = Operators::get($operatorName); |
|
49 | |||
50 | 2 | return new self([ |
|
51 | 2 | 'operator' => $operator, |
|
52 | ]); |
||
53 | } |
||
54 | |||
55 | 1 | return Operator::getDefault(); |
|
56 | } |
||
57 | |||
58 | 1 | public function getRawValue() : array |
|
59 | { |
||
60 | 1 | return $this->operator; |
|
61 | } |
||
62 | |||
63 | 2 | public function haveSubstitutionPattern() : bool |
|
66 | } |
||
67 | |||
68 | 2 | public function getSubstitutionPattern() : string |
|
76 | ); |
||
77 | } |
||
78 | } |
||
79 |