GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ExceptionManager   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 75
rs 10
c 0
b 0
f 0
ccs 23
cts 23
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A configure() 0 16 2
A getConfigException() 0 19 3
1
<?php
2
3
namespace M6Web\Bundle\ApiExceptionBundle\Manager;
4
5
use M6Web\Bundle\ApiExceptionBundle\Exception\Interfaces\ExceptionInterface;
6
use M6Web\Bundle\ApiExceptionBundle\Exception\Interfaces\HttpExceptionInterface;
7
8
/**
9
 * Manage exceptions to define public data returned
10
 */
11
class ExceptionManager
12
{
13
    /**
14
     * @var array
15
     */
16
    protected $defaultConfig;
17
18
    /**
19
     * @var array
20
     */
21
    protected $exceptions;
22
23
    /**
24
     * Constructor.
25
     *
26
     * @param array $defaultConfig
27
     * @param array $exceptions
28
     */
29
    public function __construct(array $defaultConfig, array $exceptions)
30
    {
31 1
        $this->defaultConfig    = $defaultConfig;
32 1
        $this->exceptions       = $exceptions;
33 1
    }
34
35
    /**
36
     * Configure Exception
37
     *
38
     * @param ExceptionInterface $exception
39
     *
40
     * @return ExceptionInterface
41
     */
42
    public function configure(ExceptionInterface $exception)
43
    {
44 1
        $exceptionName = get_class($exception);
45
46 1
        $configException = $this->getConfigException($exceptionName);
47
48 1
        $exception->setCode($configException['code']);
49 1
        $exception->setMessage($configException['message']);
50
51 1
        if ($exception instanceof HttpExceptionInterface) {
52 1
            $exception->setStatusCode($configException['status']);
53 1
            $exception->setHeaders($configException['headers']);
54 1
        }
55
56 1
        return $exception;
57
    }
58
59
    /**
60
     * Get config to exception
61
     *
62
     * @param string $exceptionName
63
     *
64
     * @return array
65
     */
66
    protected function getConfigException($exceptionName)
67
    {
68 1
        $exceptionParentName = get_parent_class($exceptionName);
69
70 1
        if (in_array(
71 1
            'M6Web\Bundle\ApiExceptionBundle\Exception\Interfaces\ExceptionInterface',
72 1
            class_implements($exceptionParentName)
73 1
        )) {
74 1
            $parentConfig = $this->getConfigException($exceptionParentName);
75 1
        } else {
76 1
            $parentConfig = $this->defaultConfig;
77
        }
78
79 1
        if (isset($this->exceptions[$exceptionName])) {
80 1
            return array_merge($parentConfig, $this->exceptions[$exceptionName]);
81
        }
82
83 1
        return $parentConfig;
84
    }
85
}
86