Passed
Push — front-matter-extension ( afbb21...5d397b )
by Colin
04:43 queued 02:41
created

SymfonyYamlFrontMatterParser::parse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 10
ccs 5
cts 6
cp 0.8333
rs 10
cc 3
nc 3
nop 1
crap 3.0416
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the league/commonmark package.
7
 *
8
 * (c) Colin O'Dell <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace League\CommonMark\Extension\FrontMatter\Data;
15
16
use League\CommonMark\Extension\FrontMatter\Exception\InvalidFrontMatterException;
17
use Symfony\Component\Yaml\Exception\ParseException;
18
use Symfony\Component\Yaml\Yaml;
19
20
final class SymfonyYamlFrontMatterParser implements FrontMatterDataParserInterface
21
{
22
    /**
23
     * {@inheritDoc}
24
     */
25 27
    public function parse(string $frontMatter)
26
    {
27 27
        if (! \class_exists(Yaml::class)) {
28
            throw new \RuntimeException('Failed to parse yaml: "symfony/yaml" library is missing');
29
        }
30
31
        try {
32 27
            return Yaml::parse($frontMatter);
33 9
        } catch (ParseException $ex) {
34 9
            throw InvalidFrontMatterException::wrap($ex);
35
        }
36
    }
37
}
38