Yaml::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 4
1
<?php
2
namespace Balloon\Format;
3
4
use Balloon\Reader\IFileReader;
5
use Symfony\Component\Yaml\Dumper;
6
use Symfony\Component\Yaml\Parser;
7
8
/**
9
 * Class Yaml
10
 * @package Balloon\Format
11
 * @author Raphaël Lefebvre <[email protected]>
12
 */
13
class Yaml implements IFileReader
14
{
15
    /**
16
     * @var IFileReader
17
     */
18
    private $fileReader;
19
20
    /**
21
     * @var Parser
22
     */
23
    private $yamlParser;
24
25
    /**
26
     * @var Dumper
27
     */
28
    private $yamlDumper;
29
    /**
30
     * @var
31
     */
32
    private $dumpLevel;
33
34
    /**
35
     * @param IFileReader $fileReader
36
     * @param Parser $yamlParser
37
     * @param Dumper $yamlDumper
38
     * @param $dumpLevel
39
     */
40
    public function __construct(IFileReader $fileReader, Parser $yamlParser, Dumper $yamlDumper, $dumpLevel = 0)
41
    {
42
        $this->fileReader = $fileReader;
43
        $this->yamlParser = $yamlParser;
44
        $this->yamlDumper = $yamlDumper;
45
        $this->dumpLevel = $dumpLevel;
46
    }
47
48
    /**
49
     * @return array|null
0 ignored issues
show
Documentation introduced by
Should the return type not be array|string|\stdClass? Also, consider making the array more specific, something like array<String>, or String[].

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

If the return type contains the type array, this check recommends the use of a more specific type like String[] or array<String>.

Loading history...
50
     */
51
    public function read()
52
    {
53
        return $this->yamlParser->parse($this->fileReader->read());
54
    }
55
56
    /**
57
     * @param mixed $data
58
     * @param int $mode
59
     * @return int
60
     */
61
    public function write($data, $mode = 0)
62
    {
63
        return $this->fileReader->write($this->yamlDumper->dump($data, $this->dumpLevel), $mode);
64
    }
65
}
66