Matter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 28
ccs 12
cts 12
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 20 2
1
<?php
2
3
namespace Staticka;
4
5
use Symfony\Component\Yaml\Yaml;
6
7
/**
8
 * TODO: Remove this file after v1.0.0.
9
 * Move the code to PageFactory::parse instead.
10
 *
11
 * YAML Front Matter Parser
12
 *
13
 * @package Staticka
14
 * @author  Rougin Gutib <[email protected]>
15
 */
16
class Matter
17
{
18
    /**
19
     * Retrieves the contents from a YAML format.
20
     *
21
     * @param  string $content
22
     * @return array
23
     */
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
    }
45
}
46