| Conditions | 6 |
| Paths | 10 |
| Total Lines | 21 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 7.0487 |
| Changes | 0 | ||
| 1 | <?php |
||
| 37 | 1 | public function convertFrontmatter(string $string, string $type = 'yaml'): array |
|
| 38 | { |
||
| 39 | switch ($type) { |
||
| 40 | 1 | 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 | 1 | case 'yaml': |
|
| 48 | default: |
||
| 49 | try { |
||
| 50 | 1 | $result = Yaml::parse((string) $string); |
|
| 51 | 1 | if (!is_array($result)) { |
|
| 52 | 1 | throw new Exception('Parse result of YAML front matter is not an array'); |
|
| 53 | } |
||
| 54 | |||
| 55 | 1 | return $result; |
|
| 56 | 1 | } catch (ParseException $e) { |
|
| 57 | 1 | throw new Exception($e->getMessage()); |
|
| 58 | } |
||
| 76 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.