RepositoryException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A APIFormat() 0 4 1
A jsonResponse() 0 6 2
1
<?php namespace App\Exceptions;
2
3
use Exception;
4
use Response;
5
6
class RepositoryException extends Exception
7
{
8
    // Server Side
9
    const DATABASE_ERROR = 11;
10
11
    // Client side
12
    const INCORRECT_PARAMETER = 21;
13
    const VALIDATION_FAILED = 22;
14
    const RESOURCE_NOT_FOUND = 23;
15
    const RESOURCE_DENIED = 24;
16
17
    // Matching HTTP status
18
    private static $httpStatus = [self::DATABASE_ERROR => 503,
19
        self::INCORRECT_PARAMETER => 400,
20
        self::VALIDATION_FAILED => 400,
21
        self::RESOURCE_NOT_FOUND => 404,
22
        self::RESOURCE_DENIED => 403];
23
24
    public function APIFormat()
25
    {
26
        return ['code' => $this->code, 'message' => $this->message];
27
    }
28
29
    public function jsonResponse()
30
    {
31
        $statusCode = (isset(self::$httpStatus[$this->code]) ? self::$httpStatus[$this->code] : 500);
32
33
        return Response::json($this->APIFormat(), $statusCode);
34
    }
35
36
}
37