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   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 16 2
A parseFile() 0 6 1
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