These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Bavix\SDK\FileLoader; |
||
4 | |||
5 | use Bavix\Slice\Slice; |
||
6 | use Bavix\XMLReader\XMLReader; |
||
7 | |||
8 | class XmlLoader implements DataInterface |
||
9 | { |
||
10 | |||
11 | use DataTrait; |
||
12 | |||
13 | /** |
||
14 | * @inheritdoc |
||
15 | */ |
||
16 | 1 | public function asArray() |
|
17 | { |
||
18 | 1 | if (!$this->data) |
|
0 ignored issues
–
show
|
|||
19 | { |
||
20 | 1 | $this->data = XMLReader::sharedInstance()->asArray($this->path); |
|
0 ignored issues
–
show
It seems like
\Bavix\XMLReader\XMLRead...)->asArray($this->path) can also be of type string or null . 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...
|
|||
21 | } |
||
22 | |||
23 | 1 | return $this->data; |
|
24 | } |
||
25 | |||
26 | /** |
||
27 | * @inheritdoc |
||
28 | */ |
||
29 | public function save($data) |
||
30 | { |
||
31 | $data = $this->_fromArray($data); |
||
32 | |||
33 | return (bool)\file_put_contents( |
||
34 | $this->path, |
||
35 | XMLReader::sharedInstance()->asXML($data) |
||
36 | ); |
||
37 | } |
||
38 | |||
39 | } |
||
40 |
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.