Test Failed
Push — master ( 5fcf14...625fb6 )
by Adrian Florin
02:41
created

YamlContent::getObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of the NeedleProject\FileIo package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
namespace NeedleProject\FileIo\Content;
9
10
use NeedleProject\FileIo\Exception\ContentException;
11
use Symfony\Component\Yaml\Exception\ParseException;
12
use Symfony\Component\Yaml\Yaml;
13
14
/**
15
 * Class YamlContent
16
 *
17
 * @package NeedleProject\FileIo\Content
18
 */
19
class YamlContent extends Content implements ContentInterface
20
{
21
    /**
22
     * Return the content as an array
23
     *
24
     * @return array
25
     * @throws \NeedleProject\FileIo\Exception\ContentException
26
     */
27
    public function getArray(): array
28
    {
29 1
        try {
30
            return Yaml::parse($this->get(), true);
31 1
        } catch (ParseException $e) {
32 1
            throw new ContentException(
33
                sprintf(
34
                    "YAML could not be parsed: %s",
35
                    $e->getMessage()
36
                )
37
            );
38
        }
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     * @return \stdClass
44
     */
45
    public function getObject()
46
    {
47
        return (object)$this->getArray();
48 1
    }
49
}
50