Total Complexity | 11 |
Total Lines | 62 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
4 | abstract class AbstractResourceObject implements \WebServCo\Api\JsonApi\Interfaces\ResourceObjectInterface |
||
5 | { |
||
6 | protected $type; |
||
7 | protected $id; |
||
8 | protected $attributes; |
||
9 | protected $links; |
||
10 | protected $meta; |
||
11 | |||
12 | public function __construct() |
||
13 | { |
||
14 | $this->attributes = []; |
||
15 | $this->links = []; |
||
16 | $this->meta = []; |
||
17 | } |
||
18 | |||
19 | public function setType($type) |
||
20 | { |
||
21 | $this->type = $type; |
||
22 | } |
||
23 | |||
24 | public function setId($id) |
||
25 | { |
||
26 | $this->id = $id; |
||
27 | } |
||
28 | |||
29 | public function setAttribute($key, $value) |
||
30 | { |
||
31 | $this->attributes[$key] = $value; |
||
32 | } |
||
33 | |||
34 | public function setLink($key, $value) |
||
37 | } |
||
38 | |||
39 | public function setMeta($key, $value) |
||
40 | { |
||
41 | $this->meta[$key] = $value; |
||
42 | } |
||
43 | |||
44 | public function toArray() |
||
45 | { |
||
46 | $array = [ |
||
47 | 'type' => $this->type, |
||
48 | 'id' => $this->id, |
||
49 | ]; |
||
50 | if ($this->attributes) { |
||
|
|||
51 | $array['attributes'] = $this->attributes; |
||
52 | } |
||
53 | if (!empty($this->links)) { |
||
54 | $array['links'] = $this->links; |
||
55 | } |
||
56 | if (!empty($this->meta)) { |
||
57 | $array['meta'] = $this->meta; |
||
58 | } |
||
59 | return $array; |
||
60 | } |
||
61 | |||
62 | public function toJson() |
||
66 | } |
||
67 | } |
||
68 |
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.