ChainResolver   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 46
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 2
A resolve() 12 12 3
A addResolver() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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