PathAttributeResolverRegistry::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Maba\Bundle\RestBundle\Service\PathAttributeResolver;
5
6
use InvalidArgumentException;
7
8
class PathAttributeResolverRegistry
9
{
10
    /**
11
     * @var array|PathAttributeResolverInterface[] by type
12
     */
13
    private $resolvers;
14
15 81
    public function __construct()
16
    {
17 81
        $this->resolvers = [];
18 81
    }
19
20 81
    public function registerPathAttributeResolver(PathAttributeResolverInterface $resolver, string $type)
21
    {
22 81
        $this->resolvers[$type] = $resolver;
23 81
    }
24
25 81
    public function getResolverByType(string $type): PathAttributeResolverInterface
26
    {
27 81
        if (!isset($this->resolvers[$type])) {
28
            throw new InvalidArgumentException(
29
                sprintf('No such path attribute resolver registered: "%s"', $type)
30
            );
31
        }
32
33 81
        return $this->resolvers[$type];
34
    }
35
}
36