| Conditions | 6 |
| Paths | 8 |
| Total Lines | 23 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 46 | public function toArray() |
||
| 47 | { |
||
| 48 | $array = [ |
||
| 49 | 'jsonapi' => $this->jsonapi, |
||
| 50 | ]; |
||
| 51 | if ($this->meta) { |
||
|
|
|||
| 52 | $array['meta'] = $this->meta; |
||
| 53 | } |
||
| 54 | if (!empty($this->errors)) { |
||
| 55 | foreach ($this->errors as $error) { |
||
| 56 | $array['errors'][] = $error->toArray(); |
||
| 57 | } |
||
| 58 | } else { |
||
| 59 | $dataItems = count($this->data); |
||
| 60 | if (1 < $dataItems) { |
||
| 61 | foreach ($this->data as $item) { |
||
| 62 | $array['data'][] = $item->toArray(); |
||
| 63 | } |
||
| 64 | } else { |
||
| 65 | $array['data'] = $this->data[0]->toArray(); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | return $array; |
||
| 69 | } |
||
| 77 |
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.