| Total Complexity | 9 |
| Total Lines | 63 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | final class Parameter |
||
| 6 | { |
||
| 7 | private $key; |
||
| 8 | |||
| 9 | private $value; |
||
| 10 | |||
| 11 | public static function withKeyAndValue( |
||
| 16 | } |
||
| 17 | |||
| 18 | public static function box(array $params) : Parameter |
||
| 19 | { |
||
| 20 | $fieldName = $params['fieldName']; |
||
| 21 | $explodedQueryStringRawFilter = $params['explodedQueryStringRawFilter']; |
||
| 22 | $salt = $params['salt']; |
||
| 23 | $value = $params['value']; |
||
| 24 | |||
| 25 | $op = Filter::fromQueryStringRawFilterExploded($explodedQueryStringRawFilter); |
||
| 26 | |||
| 27 | $operator = $op->getRawOperator(); |
||
| 28 | |||
| 29 | if (isset($operator['substitution_pattern'])) { |
||
| 30 | $isSingleValue = isset($explodedQueryStringRawFilter[1]) |
||
| 31 | && $op->isListOrNlist(); |
||
| 32 | |||
| 33 | if ($isSingleValue) { |
||
| 34 | $value = str_replace( |
||
| 35 | '{string}', |
||
| 36 | $value, |
||
| 37 | $operator['substitution_pattern'] |
||
| 38 | ); |
||
| 39 | } else { |
||
| 40 | $value = explode(',', $value); |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | return new self( |
||
| 45 | 'field_' . $fieldName . $salt, |
||
| 46 | $value |
||
| 47 | ); |
||
| 48 | } |
||
| 49 | |||
| 50 | private function __construct($key, $value) |
||
| 51 | { |
||
| 52 | $this->key = $key; |
||
| 53 | $this->value = $value; |
||
| 54 | } |
||
| 55 | |||
| 56 | public function getKey() : string |
||
| 57 | { |
||
| 58 | return $this->key; |
||
| 59 | } |
||
| 60 | |||
| 61 | public function getValue() : string |
||
| 68 | } |
||
| 69 | } |
||
| 70 |