| Total Complexity | 9 |
| Total Lines | 53 |
| Duplicated Lines | 0 % |
| Coverage | 71.43% |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | class Converter implements ConverterInterface |
||
| 22 | { |
||
| 23 | /** @var Builder */ |
||
| 24 | protected $builder; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param Builder $builder |
||
| 28 | */ |
||
| 29 | 1 | public function __construct(Builder $builder) |
|
| 30 | { |
||
| 31 | 1 | $this->builder = $builder; |
|
| 32 | 1 | } |
|
| 33 | |||
| 34 | /** |
||
| 35 | * {@inheritdoc} |
||
| 36 | */ |
||
| 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 | } |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * {@inheritdoc} |
||
| 64 | */ |
||
| 65 | 1 | public function convertBody(string $string): string |
|
| 74 | } |
||
| 75 | } |
||
| 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.