NormalizerGuesser::guessNormalizer()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 2
eloc 7
nc 2
nop 2
1
<?php
2
3
namespace Actualys\Bundle\DrupalCommerceConnectorBundle\Guesser;
4
5
use Actualys\Bundle\DrupalCommerceConnectorBundle\DependencyInjection\Compiler\AggregatedTaggedNormalizer;
6
use Actualys\Bundle\DrupalCommerceConnectorBundle\Guesser\Exception\GuessException;
7
8
class NormalizerGuesser
9
{
10
    /** @var AggregatedTaggedNormalizer */
11
    protected $normalizers;
12
13
    /**
14
     * @param AggregatedTaggedNormalizer $normalizer
15
     */
16
    public function __construct(
17
      AggregatedTaggedNormalizer $normalizer
18
    ) {
19
        $this->normalizers = $normalizer;
20
    }
21
22
    /**
23
     * @param $type
24
     * @param $normalizeType
25
     * @return mixed
26
     * @throws GuessException
27
     */
28
    public function guessNormalizer($type, $normalizeType)
29
    {
30
        $normalizer = $this->normalizers->getNormalizer(
31
          $type.'.'.$normalizeType
32
        );
33
        if (is_null($normalizer)) {
34
            throw new GuessException(
35
              'Type de normalizer non géré: '.$normalizeType.' pour '.$type
36
            );
37
        }
38
39
        return $normalizer;
40
    }
41
}
42