Collection::has()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Dafiti\Silex\Log;
4
5
class Collection implements \Countable, \IteratorAggregate
6
{
7
    private $loggers = [];
8
9
    public function add(Logger $logger)
10
    {
11
        $this->loggers[$logger->getName()] = $logger;
12
13
        return $this;
14
    }
15
16
    public function count()
17
    {
18
        return count($this->loggers);
19
    }
20
21
    public function getIterator()
22
    {
23
        return new \ArrayIterator($this->loggers);
24
    }
25
26
    public function has($name)
27
    {
28
        if (!is_string($name)) {
29
            throw new \InvalidArgumentException('The argument of has method must be string');
30
        }
31
32
        return isset($this->loggers[$name]);
33
    }
34
35
    public function get($name)
36
    {
37
        if (!is_string($name)) {
38
            throw new \InvalidArgumentException('The argument of get method must be string');
39
        }
40
41
        if (!$this->has($name)) {
42
            $message = sprintf('Logger %s is not defined', $name);
43
            throw new \OutOfBoundsException($message);
44
        }
45
46
        return $this->loggers[$name];
47
    }
48
49
    public function __get($name)
50
    {
51
        return $this->get($name);
52
    }
53
}
54