JsonApiErrors::error()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
rs 9.4285
c 1
b 0
f 0
nc 2
cc 2
eloc 5
nop 3
1
<?php
2
3
namespace Huntie\JsonApi\Support;
4
5
use Huntie\JsonApi\Http\JsonApiResponse;
6
7
/**
8
 * Format JSON API error responses.
9
 * http://jsonapi.org/format/#error-objects
10
 */
11
trait JsonApiErrors
12
{
13
    /**
14
     * Return an error response containing a JSON API errors object.
15
     *
16
     * @param int         $status
17
     * @param string      $title
18
     * @param string|null $detail
19
     *
20
     * @return JsonApiResponse
21
     */
22
    public function error($status, $title, $detail = null)
23
    {
24
        $error = compact('status', 'title');
25
26
        if (!is_null($detail)) {
27
            $error['detail'] = $detail;
28
        }
29
30
        return new JsonApiResponse(['errors' => [$error]], $status);
31
    }
32
}
33