DelegatingNormalizer   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 73.32%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 39
ccs 11
cts 15
cp 0.7332
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A normalize() 0 10 3
A supports() 0 10 3
1
<?php
2
3
namespace Bankiru\Seo\Destination\Normalizer;
4
5
use Bankiru\Seo\Destination\DestinationNormalizer;
6
use Bankiru\Seo\Exception\DestinationException;
7
8
final class DelegatingNormalizer implements DestinationNormalizer
9
{
10
    /** @var  DestinationNormalizer[] */
11
    private $normalizers = [];
12
13
    /**
14
     * DelegatingNormalizer constructor.
15
     *
16
     * @param DestinationNormalizer[] $normalizers
17
     */
18 1
    public function __construct(array $normalizers)
19
    {
20 1
        $this->normalizers = $normalizers;
21 1
    }
22
23
    /** {@inheritdoc} */
24 1
    public function normalize($item)
25
    {
26 1
        foreach ($this->normalizers as $normalizer) {
27 1
            if ($normalizer->supports($item)) {
28 1
                return $normalizer->normalize($item);
29
            }
30
        }
31
32
        throw DestinationException::normalizationFailed($item);
33
    }
34
35
    /** {@inheritdoc} */
36 1
    public function supports($item)
37
    {
38 1
        foreach ($this->normalizers as $normalizer) {
39 1
            if ($normalizer->supports($item)) {
40 1
                return true;
41
            }
42
        }
43
44
        return false;
45
    }
46
}
47