bavix /
sdk
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Bavix\SDK\FileLoader; |
||
| 4 | |||
| 5 | use Bavix\Helpers\JSON; |
||
| 6 | |||
| 7 | class JSONLoader implements DataInterface |
||
| 8 | { |
||
| 9 | |||
| 10 | use DataTrait; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @inheritdoc |
||
| 14 | */ |
||
| 15 | 1 | public function asArray() |
|
| 16 | { |
||
| 17 | 1 | if (!$this->data) |
|
|
0 ignored issues
–
show
|
|||
| 18 | { |
||
| 19 | 1 | $data = \file_get_contents($this->path); |
|
| 20 | 1 | $this->data = JSON::decode($data); |
|
| 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 | JSON::encode($data, JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT) |
||
| 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.