Passed
Push — master ( ea7869...3cbc1f )
by Julito
09:01
created

HandlerCollection::getHandler()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Tool;
8
9
use InvalidArgumentException;
10
11
class HandlerCollection
12
{
13
    /**
14
     * @var AbstractTool[]|iterable
15
     */
16
    private $handlers;
17
18
    public function __construct(iterable $handlers)
19
    {
20
        $this->handlers = $handlers;
21
    }
22
23
    public function getHandler(string $name): AbstractTool
24
    {
25
        foreach ($this->handlers as $handler) {
26
            if ($name === $handler->getName()) {
27
                return $handler;
28
            }
29
        }
30
31
        throw new InvalidArgumentException(sprintf('Cannot handle tool "%s"', $name));
32
    }
33
34
    /**
35
     * @return AbstractTool[]|iterable
36
     */
37
    public function getCollection()
38
    {
39
        return $this->handlers;
40
    }
41
}
42