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

HandlerCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 29
rs 10
c 1
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCollection() 0 3 1
A getHandler() 0 9 3
A __construct() 0 3 1
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