ApiException   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 37
rs 10
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 28 7
A getErrors() 0 3 1
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