Passed
Push — master ( 4d0992...9fab89 )
by Бабичев
01:51
created

src/SDK/FileLoader/IniLoader.php (2 issues)

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);
0 ignored issues
show
Documentation Bug introduced by
It seems like parse_ini_file($this->path, true) can also be of type false. However, the property $data is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
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