Passed
Push — master ( 5b634b...5acd4d )
by Бабичев
05:11
created

IniLoader::writer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
ccs 0
cts 4
cp 0
rs 9.6666
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Bavix\SDK\FileLoader;
4
5
class IniLoader implements DataInterface
6
{
7
8
    use DataTrait;
9
10
    /**
11
     * @var IniWriter
12
     */
13
    protected $writer;
14
15
    /**
16
     * @return IniWriter
17
     */
18
    protected function writer()
19
    {
20
        if (!$this->writer)
21
        {
22
            $this->writer = new IniWriter();
23
        }
24
25
        return $this->writer;
26
    }
27
28
    /**
29
     * @inheritdoc
30
     */
31
    public function asArray()
32
    {
33
        if (!$this->data)
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->data of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
34
        {
35
            $this->data = \parse_ini_file($this->path, true);
36
        }
37
38
        return $this->data;
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44
    public function save($data)
45
    {
46
        $data = $this->_fromArray($data);
47
48
        return (int)$this->writer()
49
            ->toFile($this->path, $data);
50
    }
51
52
}
53