| Total Complexity | 11 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Coverage | 57.14% |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class YamlParser implements Parser, ArrayAccess |
||
| 9 | { |
||
| 10 | private $parsed = []; |
||
| 11 | |||
| 12 | 10 | public function parse(string $rawYaml): void |
|
| 13 | { |
||
| 14 | 10 | foreach ($this->yamlToArray($rawYaml) as $className => $yamlArray) { |
|
| 15 | 10 | foreach ($yamlArray as $id => $mockArray) { |
|
| 16 | 10 | $this->parsed[$id] = [$className => $mockArray]; |
|
| 17 | } |
||
| 18 | } |
||
| 19 | 10 | } |
|
| 20 | |||
| 21 | 10 | protected function yamlToArray(string $rawYaml): array |
|
| 22 | { |
||
| 23 | 10 | if (function_exists('yaml_parse')) { |
|
| 24 | return yaml_parse($rawYaml); |
||
| 25 | } |
||
| 26 | |||
| 27 | 10 | return Yaml::parse($rawYaml); |
|
| 28 | } |
||
| 29 | |||
| 30 | public function offsetSet($offset, $value) |
||
| 31 | { |
||
| 32 | if (is_null($offset)) { |
||
| 33 | $this->parsed[] = $value; |
||
| 34 | } else { |
||
| 35 | $this->parsed[$offset] = $value; |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | 1 | public function offsetExists($offset) |
|
| 40 | { |
||
| 41 | 1 | return isset($this->parsed[$offset]); |
|
| 42 | } |
||
| 43 | |||
| 44 | public function offsetUnset($offset) |
||
| 47 | } |
||
| 48 | |||
| 49 | 10 | public function offsetGet($offset) |
|
| 52 | } |
||
| 53 | } |
||
| 54 |