Conditions | 2 |
Paths | 2 |
Total Lines | 20 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 2 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
24 | 12 | public static function parse($content) |
|
25 | { |
||
26 | 12 | $matter = array(); |
|
27 | |||
28 | 12 | $text = str_replace(PHP_EOL, $id = uniqid(), $content); |
|
29 | |||
30 | 12 | $regex = '/^---' . $id . '(.*?)' . $id . '---/'; |
|
31 | |||
32 | 12 | if (preg_match($regex, $text, $matches) === 1) |
|
33 | 4 | { |
|
34 | 3 | $yaml = str_replace($id, PHP_EOL, $matches[1]); |
|
35 | |||
36 | 3 | $matter = (array) Yaml::parse(trim($yaml)); |
|
37 | |||
38 | 3 | $body = str_replace($matches[0], '', $text); |
|
39 | |||
40 | 3 | $content = str_replace($id, PHP_EOL, $body); |
|
41 | 1 | } |
|
42 | |||
43 | 12 | return array($matter, (string) trim($content)); |
|
44 | } |
||
46 |