AbstractHandler::getMappingName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 0
cts 4
cp 0
crap 6
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace LAG\SmokerBundle\Response\Handler;
4
5
use LAG\SmokerBundle\Contracts\Response\Handler\ResponseHandlerInterface;
6
7
abstract class AbstractHandler implements ResponseHandlerInterface
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $configuration = [];
13
14
    abstract public function getName(): string;
15
16
    /**
17
     * ResponseCodeHandler constructor.
18
     */
19 6
    public function __construct(array $configuration = [])
20
    {
21 6
        $this->configuration = $configuration;
22 6
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 1
    public function supports(string $routeName): bool
28
    {
29 1
        if (!key_exists($routeName, $this->configuration)) {
30 1
            return false;
31
        }
32
33 1
        if (!key_exists('handlers', $this->configuration[$routeName])) {
34 1
            return false;
35
        }
36
37 1
        return key_exists($this->getName(), $this->configuration[$routeName]['handlers']);
38
    }
39
40
    protected function getConfiguration(string $routeName): array
41
    {
42
        return $this->configuration[$routeName]['handlers'][$this->getName()];
43
    }
44
45
    protected function getMappingName(string $routeName): ?string
46
    {
47
        if (!key_exists('mapping', $this->configuration[$routeName])) {
48
            return null;
49
        }
50
51
        return $this->configuration[$routeName]['mapping'];
52
    }
53
}
54