Completed
Push — master ( 5bd517...c7b86e )
by Tomáš
08:52
created

YamlAndNeonParser::decodeFromFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify
7
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
8
 */
9
10
namespace Symplify\PHP7_Sculpin\Configuration\Parser;
11
12
use Nette\Neon\Neon;
13
use Symfony\Component\Yaml\Yaml;
14
use Throwable;
15
16
final class YamlAndNeonParser
17
{
18 5
    public function decodeFromFile(string $filePath) : array
19
    {
20
        $fileContent = file_get_contents($filePath);
21 5
        return $this->decode($fileContent);
22 2
    }
23 2
24
    public function decode(string $content) : array
25
    {
26
        try {
27
            return Neon::decode($content);
28
        } catch (Throwable $throwable) {
29
            return Yaml::parse($content);
30
        }
31
    }
32
}
33