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