| Conditions | 6 |
| Paths | 8 |
| Total Lines | 23 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 32 | public function toArray() |
||
| 33 | { |
||
| 34 | $array = [ |
||
| 35 | 'jsonapi' => $this->jsonapi, |
||
| 36 | ]; |
||
| 37 | if ($this->meta) { |
||
|
|
|||
| 38 | $array['meta'] = $this->meta; |
||
| 39 | } |
||
| 40 | if (!empty($this->errors)) { |
||
| 41 | foreach ($this->errors as $error) { |
||
| 42 | $array['errors'][] = $error->toArray(); |
||
| 43 | } |
||
| 44 | } else { |
||
| 45 | $dataItems = count($this->data); |
||
| 46 | if (1 < $dataItems) { |
||
| 47 | foreach ($this->data as $item) { |
||
| 48 | $array['data'][] = $item->toArray(); |
||
| 49 | } |
||
| 50 | } else { |
||
| 51 | $array['data'] = $this->data[0]->toArray(); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | return $array; |
||
| 55 | } |
||
| 63 |
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.