ApiException::getErrors()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
namespace Javis\JsonApi\Exceptions;
3
4
class ApiException extends \Exception
5
{
6
    protected $errors = [];
7
8
     public function __construct($errors = [], $status = 0 )
9
     {
10
         $message = "";
11
12
         $this->errors = $errors;
13
14
         if (!empty($errors)){
15
             $error = array_shift($errors);
16
17
             if (isset($error->title)){
18
                 $message = $error->title;
19
             }
20
21
             if (isset($error->detail)){
22
                 $message .= (empty($message)) ? $error->detail : ": $error->detail";
23
             }
24
         }
25
26
         if (empty($message)){
27
             $message = "API Server Responded with error";
28
29
             if ($status){
30
                 $message .= " $status";
31
             }
32
         }
33
34
         // make sure everything is assigned properly
35
        parent::__construct($message, $status);
36
     }
37
38
     public function getErrors()
39
     {
40
         return $this->errors;
41
     }
42
43
}
44