ConfigurationException::getConfiguration()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\Exception;
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
    private array $configuration;
14
15
    public function __construct(
16
        string $resourceType = null,
17
        string $resourceName = '',
18
        \Throwable $previous = null,
19
        array $configuration = []
20
    ) {
21
        $typeMessage = 'An error has occurred when resolving a configuration';
22
23
        if ($resourceType === 'menu') {
24
            $typeMessage = 'An error has occurred when resolving the configuration for the menu "%s"';
25
        }
26
27
        if ($resourceType === 'action') {
28
            $typeMessage = 'An error has occurred when resolving the configuration of the action "%s"';
29
        }
30
31
        if ($resourceType === 'admin') {
32
            $typeMessage = 'An error has occurred when resolving the configuration of the admin "%s"';
33
        }
34
        $message = sprintf($typeMessage, $resourceName);
35
        $code = 0;
36
37
        if ($previous !== null) {
38
            $message .= ' : '.$previous->getMessage();
39
            $code = $previous->getCode();
40
        }
41
42
        parent::__construct($message, $code, $previous);
43
        $this->configuration = $configuration;
44
    }
45
46
    public function getConfiguration(): array
47
    {
48
        return $this->configuration;
49
    }
50
}
51