| Total Complexity | 3 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | class GetOperator extends BaseOperator |
||
| 22 | {
|
||
| 23 | /** |
||
| 24 | * Name of the key from which value will be returned. |
||
| 25 | * |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | public $key; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Default value to be returned if that key was not found. |
||
| 32 | * |
||
| 33 | * @var mixed |
||
| 34 | */ |
||
| 35 | public $default; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Passes data from operator configuration. |
||
| 39 | * |
||
| 40 | * Depending on the operator this data can contain other sub-expressions which need to be parsed using |
||
| 41 | * ExpressionParser |
||
| 42 | * |
||
| 43 | * @param array $config Expressions to be processed |
||
| 44 | * @see ExpressionParser |
||
| 45 | */ |
||
| 46 | 17 | public function configure(array $config) |
|
| 47 | {
|
||
| 48 | 17 | $this->setName($config[0] ?? 'unknown'); |
|
| 49 | |||
| 50 | 17 | if (count($config) < 1) {
|
|
| 51 | 1 | throw new \InvalidArgumentException("Minimum format must be satisfied: ['{$this->getName()}']");
|
|
| 52 | } |
||
| 53 | |||
| 54 | 16 | $this->key = $config[1] ?? ''; |
|
| 55 | 16 | $this->default = $config['default'] ?? null; |
|
| 56 | 16 | } |
|
| 57 | |||
| 58 | /** |
||
| 59 | * Evaluates one value. |
||
| 60 | * |
||
| 61 | * @param ValueParser $value Value to be evaluated |
||
| 62 | * @return mixed Evaluation result |
||
| 63 | */ |
||
| 64 | 13 | public function evaluate(ValueParser $value) |
|
| 67 | } |
||
| 68 | |||
| 69 | } |