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
|
|||
34 | { |
||
35 | $this->data = \parse_ini_file($this->path, true); |
||
0 ignored issues
–
show
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 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 |
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.