Passed
Push — latest ( 2ee702...5d397b )
by Colin
02:38 queued 12s
created

SymfonyYamlFrontMatterParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 15
ccs 5
cts 6
cp 0.8333
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 10 3
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