| Conditions | 6 |
| Paths | 10 |
| Total Lines | 21 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 37 | public function convertFrontmatter(string $string, string $type = 'yaml'): array |
||
| 38 | { |
||
| 39 | switch ($type) { |
||
| 40 | case 'ini': |
||
| 41 | $result = parse_ini_string($string); |
||
| 42 | if (!$result) { |
||
| 43 | throw new Exception('Can\'t parse INI front matter'); |
||
| 44 | } |
||
| 45 | |||
| 46 | return $result; |
||
| 47 | case 'yaml': |
||
| 48 | default: |
||
| 49 | try { |
||
| 50 | $result = Yaml::parse((string) $string); |
||
| 51 | if (!is_array($result)) { |
||
| 52 | throw new Exception('Parse result of YAML front matter is not an array'); |
||
| 53 | } |
||
| 54 | |||
| 55 | return $result; |
||
| 56 | } catch (ParseException $e) { |
||
| 57 | throw new Exception($e->getMessage()); |
||
| 58 | } |
||
| 72 |