| Total Complexity | 8 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | class SetKey extends NodeGeneric |
||
| 16 | { |
||
| 17 | 3 | public function __construct(string $nodeString, int $line) |
|
| 18 | { |
||
| 19 | 3 | parent::__construct($nodeString, $line); |
|
| 20 | 3 | $v = substr(trim($nodeString), 1); |
|
| 21 | 3 | if (!empty($v)) { |
|
| 22 | 3 | $value = NodeFactory::get($v, $line); |
|
| 23 | 3 | $value->indent = null; |
|
| 24 | 3 | $this->add($value); |
|
| 25 | } |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param object $parent The parent |
||
| 30 | * |
||
| 31 | * @throws \Exception if a problem occurs during serialisation (json format) of the key |
||
| 32 | */ |
||
| 33 | 1 | public function build(&$parent = null) |
|
| 34 | { |
||
| 35 | 1 | $built = is_null($this->value) ? null : $this->value->build(); |
|
| 36 | 1 | $stringKey = is_string($built) && Regex::isProperlyQuoted($built) ? trim($built, '\'" ') : $built; |
|
| 37 | 1 | $key = json_encode($stringKey, JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_UNESCAPED_SLASHES); |
|
| 38 | 1 | if (empty($key)) throw new \Exception("Cant serialize complex key: " . var_export($this->value, true)); |
|
| 39 | 1 | $parent->{trim($key, '\'" ')} = null; |
|
| 40 | 1 | return null; |
|
| 41 | } |
||
| 42 | |||
| 43 | 1 | public function isAwaitingChild(NodeGeneric $child): bool |
|
| 46 | } |
||
| 47 | } |
||
| 48 |