ChainResolver::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
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\NameOfMessage;
13
14
use Cubiche\Core\Bus\Exception\NotFoundException;
15
use Cubiche\Core\Bus\MessageInterface;
16
use Cubiche\Core\Collections\ArrayCollection\ArrayList;
17
18
/**
19
 * ChainResolver class.
20
 *
21
 * @author Ivannis Suárez Jerez <[email protected]>
22
 */
23 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...
24
{
25
    /**
26
     * @var ArrayList
27
     */
28
    protected $resolvers;
29
30
    /**
31
     * ChainResolver constructor.
32
     *
33
     * @param array $resolvers
34
     */
35
    public function __construct(array $resolvers)
36
    {
37
        $this->resolvers = new ArrayList();
38
        foreach ($resolvers as $resolver) {
39
            $this->addResolver($resolver);
40
        }
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function resolve(MessageInterface $message)
47
    {
48
        foreach ($this->resolvers as $resolver) {
49
            try {
50
                /* @var ResolverInterface $resolver */
51
                return $resolver->resolve($message);
52
            } catch (\Exception $exception) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
53
            }
54
        }
55
56
        throw $this->notFoundException($message);
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    protected function addResolver(ResolverInterface $resolver)
63
    {
64
        $this->resolvers->add($resolver);
65
    }
66
67
    /**
68
     * @param MessageInterface $message
69
     *
70
     * @return NotFoundException
71
     */
72
    protected function notFoundException($message)
73
    {
74
        return NotFoundException::nameOfMessage($message);
75
    }
76
}
77