Completed
Push — feature/html-code-handler ( e478ba )
by Arnaud
06:02
created

AbstractHandler::getMappingName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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