ChainResolver::resolve()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Cubiche\Core\Bus\Middlewares\Handler\Resolver\HandlerMethodName;
13
14
use Cubiche\Core\Bus\Exception\NotFoundException;
15
use Cubiche\Core\Collections\ArrayCollection\ArrayList;
16
17
/**
18
 * ChainResolver class.
19
 *
20
 * @author Ivannis Suárez Jerez <[email protected]>
21
 */
22 View Code Duplication
class ChainResolver implements ResolverInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
{
24
    /**
25
     * @var ArrayList
26
     */
27
    protected $resolvers;
28
29
    /**
30
     * ChainResolver constructor.
31
     *
32
     * @param array $resolvers
33
     *
34
     * @throws \Cubiche\Core\Bus\Exception\InvalidLocatorException
35
     */
36
    public function __construct(array $resolvers)
37
    {
38
        $this->resolvers = new ArrayList();
39
        foreach ($resolvers as $resolver) {
40
            $this->addResolver($resolver);
41
        }
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function resolve($className)
48
    {
49
        foreach ($this->resolvers as $resolver) {
50
            try {
51
                /* @var ResolverInterface $resolver */
52
                return $resolver->resolve($className);
53
            } catch (\Exception $exception) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
54
            }
55
        }
56
57
        throw NotFoundException::handlerMethodNameForObject($className);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    protected function addResolver(ResolverInterface $resolver)
64
    {
65
        $this->resolvers->add($resolver);
66
    }
67
}
68