JsonApiErrors   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 22
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A error() 0 10 2
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