Issues (23)

src/SDK/FileLoader/YamlLoader.php (1 issue)

1
<?php
2
3
namespace Bavix\SDK\FileLoader;
4
5
use Symfony\Component\Yaml\Yaml;
6
7
class YamlLoader 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
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...
18
        {
19 1
            $yml        = \file_get_contents($this->path);
20 1
            $this->data = Yaml::parse($yml);
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
            Yaml::dump($data)
36
        );
37
    }
38
39
}
40