Passed
Pull Request — master (#175)
by Arnaud
03:44
created

ConfigurationException   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 40
rs 10
c 1
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfiguration() 0 3 1
A __construct() 0 28 5
1
<?php
2
3
namespace LAG\AdminBundle\Exception;
4
5
use Throwable;
6
7
/**
8
 * This exception is thrown when the configuration given to the AdminBundle is invalid. this can be when creating the
9
 * application, an admin, an action or a menu.
10
 */
11
class ConfigurationException extends Exception
12
{
13
    /**
14
     * @var array
15
     */
16
    private $configuration;
17
18
    public function __construct(
19
        string $type = null,
20
        string $typeName = '',
21
        $code = 0,
22
        Throwable $previous = null,
23
        array $configuration = []
24
    ) {
25
        $typeMessage = 'An error has occurred when resolving a configuration';
26
27
        if ('menu' === $type) {
28
            $typeMessage = 'An error has occurred when resolving the configuration for the menu "%s"';
29
        }
30
31
        if ('action' === $type) {
32
            $typeMessage = 'An error has occurred when resolving the configuration of the action "%s"';
33
        }
34
35
        if ('admin' === $type) {
36
            $typeMessage = 'An error has occurred when resolving the configuration of the admin "%s"';
37
        }
38
        $message = sprintf($typeMessage, $typeName);
39
40
        if ($previous) {
41
            $message .= ' : '.$previous->getMessage();
42
        }
43
44
        parent::__construct($message, $code, $previous);
45
        $this->configuration = $configuration;
46
    }
47
48
    public function getConfiguration(): array
49
    {
50
        return $this->configuration;
51
    }
52
}
53