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

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

Labels
Severity
1
<?php
2
3
namespace Bavix\SDK\FileLoader;
4
5
use Bavix\Slice\Slice;
6
7
trait DataTrait
8
{
9
10
    /**
11
     * @var string
12
     */
13
    protected $path;
14
15
    /**
16
     * @var array
17
     */
18
    protected $data;
19
20
    /**
21
     * @param array|Slice $data
22
     *
23
     * @return array
24
     */
25
    protected function _fromArray($data)
26
    {
27
        if ($data instanceof Slice)
28
        {
29
            return $data->asArray();
30
        }
31
32
        return $data;
33
    }
34
35
    /**
36
     * DataTrait constructor.
37
     *
38
     * @param array|Slice|string $data
39
     */
40 4
    public function __construct($data)
41
    {
42 4
        if (\is_string($data))
43
        {
44 4
            $this->path = $data;
45 4
            return;
46
        }
47
48
        $this->data = $this->_fromArray($data);
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54
    public function asSlice($parameters = null)
55
    {
56
        return new Slice($this->asArray(), $parameters);
0 ignored issues
show
It seems like asArray() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        return new Slice($this->/** @scrutinizer ignore-call */ asArray(), $parameters);
Loading history...
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    public function path()
63
    {
64
        return $this->path;
65
    }
66
67
}
68