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

ConfigurationException::__construct()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 28
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 12
nc 16
nop 5
dl 0
loc 28
rs 9.5555
c 1
b 0
f 0
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