GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 196cc6...8df3b0 )
by Freek
01:52
created

YamlFrontMatterParser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Spatie\YamlFrontMatter;
4
5
use Exception;
6
use Symfony\Component\Yaml\Yaml;
7
8
class YamlFrontMatterParser
9
{
10
    protected $yamlParser;
11
12
    public function __construct()
13
    {
14
        $this->yamlParser = new Yaml();
15
    }
16
17
    public function parse(string $content) : YamlFrontMatterObject
18
    {
19
        // Parser regex borrowed from the `devster/frontmatter` package
20
        // https://github.com/devster/frontmatter/blob/bb5d2c7/src/Parser.php#L123
21
        $pattern = "/^\s*(?:---)[\n\r\s]*(.*?)[\n\r\s]*(?:---)[\s\n\r]*(.*)$/s";
22
23
        $parts = [];
24
25
        $match = preg_match($pattern, $content, $parts);
26
27
        if ($match === false) {
28
            throw new Exception('An error occurred while extracting the front matter from the contents');
29
        }
30
31
        if ($match === 0) {
32
            return new YamlFrontMatterObject([], $content);
33
        }
34
35
        $matter = $this->yamlParser->parse($parts[1]);
36
        $body = $parts[2];
37
38
        return new YamlFrontMatterObject($matter, $body);
39
    }
40
}
41