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.

YamlFrontMatter::parse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\YamlFrontMatter;
4
5
use Symfony\Component\Yaml\Yaml;
6
7
class YamlFrontMatter
8
{
9
    public static function parse(string $content): Document
10
    {
11
        $pattern = '/^[\s\r\n]?---[\s\r\n]?$/sm';
12
13
        $parts = preg_split($pattern, PHP_EOL.ltrim($content));
14
15
        if (count($parts) < 3) {
16
            return new Document([], $content);
17
        }
18
19
        $matter = Yaml::parse(trim($parts[1]));
20
21
        $body = implode(PHP_EOL.'---'.PHP_EOL, array_slice($parts, 2));
22
23
        return new Document($matter, $body);
24
    }
25
26
    public static function parseFile(string $path): Document
27
    {
28
        return static::parse(
29
            file_get_contents($path)
30
        );
31
    }
32
}
33