innoflash /
larastart
| 1 | <?php |
||
| 2 | |||
| 3 | namespace InnoFlash\LaraStart\Traits; |
||
| 4 | |||
| 5 | use Illuminate\Routing\ResponseFactory; |
||
| 6 | |||
| 7 | trait APIResponses |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * The json response for success responses. |
||
| 11 | * |
||
| 12 | * @param $message |
||
| 13 | * @param array $data |
||
| 14 | * @param int $statusCode |
||
| 15 | * |
||
| 16 | * @return mixed |
||
| 17 | */ |
||
| 18 | public function successResponse($message, $data = [], int $statusCode = 200) |
||
| 19 | { |
||
| 20 | $responseData = [ |
||
| 21 | 'success' => true, |
||
| 22 | 'message' => $message, |
||
| 23 | ]; |
||
| 24 | |||
| 25 | if ($data) { |
||
|
0 ignored issues
–
show
|
|||
| 26 | $responseData['data'] = $data; |
||
| 27 | } |
||
| 28 | |||
| 29 | return ResponseFactory::successResponse($message, $responseData, $statusCode); |
||
| 30 | } |
||
| 31 | } |
||
| 32 |
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.