ResourceAssemblerResolver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 37
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A resolve() 0 15 3
1
<?php
2
3
declare(strict_types = 1);
4
5
/*
6
 * This file is part of the FiveLab Resource package
7
 *
8
 * (c) FiveLab
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code
12
 */
13
14
namespace FiveLab\Component\Resource\Assembler\Resolver;
15
16
use FiveLab\Component\Resource\Assembler\ResourceAssemblerInterface;
17
18
/**
19
 * Resolve resource assembler.
20
 *
21
 * @author Vitaliy Zhuk <[email protected]>
22
 */
23
class ResourceAssemblerResolver implements ResourceAssemblerResolverInterface
24
{
25
    /**
26
     * @var array
27
     */
28
    private $map = [];
29
30
    /**
31
     * Add the resource assembler to registry
32
     *
33
     * @param ResourceAssemblerSupportableInterface $supportable
34
     * @param ResourceAssemblerInterface            $assembler
35
     */
36 1
    public function add(ResourceAssemblerSupportableInterface $supportable, ResourceAssemblerInterface $assembler): void
37
    {
38 1
        $this->map[] = [$supportable, $assembler];
39 1
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 2
    public function resolve(string $objectClass, string $resourceClass): ResourceAssemblerInterface
45
    {
46
        /** @var ResourceAssemblerSupportableInterface $supportable */
47 2
        foreach ($this->map as [$supportable, $assembler]) {
48 1
            if ($supportable->supports($objectClass, $resourceClass)) {
0 ignored issues
show
Bug introduced by
The variable $supportable does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
49 1
                return $assembler;
0 ignored issues
show
Bug introduced by
The variable $assembler does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
50
            }
51
        }
52
53 1
        throw new ResourceAssemblerNotFoundException(sprintf(
54 1
            'Not found assembler for resource by class "%s" and object by class "%s".',
55 1
            $resourceClass,
56 1
            $objectClass
57
        ));
58
    }
59
}
60