ApiResponse   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 25
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A errorAccess() 0 3 1
A success() 0 8 1
A error() 0 8 1
1
<?php
2
3
namespace Squadron\Base\Helpers;
4
5
use Illuminate\Http\JsonResponse;
6
7
class ApiResponse
8
{
9
    public static function error(string $message, int $code = 400, array $data = []): JsonResponse
10
    {
11
        $response = array_merge([
12
            'success' => false,
13
            'message' => $message,
14
        ], $data);
15
16
        return response()->json($response, $code, [], JSON_UNESCAPED_SLASHES);
17
    }
18
19
    public static function success(?string $message, array $data = []): JsonResponse
20
    {
21
        $response = array_merge([
22
            'success' => true,
23
            'message' => $message,
24
        ], $data);
25
26
        return response()->json($response, 200, [], JSON_UNESCAPED_SLASHES);
27
    }
28
29
    public static function errorAccess(string $message): JsonResponse
30
    {
31
        return self::error($message, 401);
32
    }
33
}
34