Completed
Push — master ( 95a6e8...b8af6d )
by Filipe
07:12
created

DefinitionList   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 35
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A append() 0 8 2
A offsetSet() 0 11 2
1
<?php
2
3
/**
4
 * This file is part of slick/di package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Di\Definition;
11
12
use Slick\Common\Utils\ArrayObject;
13
use Slick\Di\DefinitionInterface;
14
use Slick\Di\Exception\InvalidArgumentException;
15
16
/**
17
 * A list of definitions
18
 *
19
 * @package Slick\Di\Definition
20
 * @author  Filipe Silva <[email protected]>
21
 */
22
class DefinitionList extends ArrayObject
23
{
24
25
    /**
26
     * Appends a definition to the list
27
     *
28
     * @param DefinitionInterface $value
29
     */
30 72
    public function append($value)
31
    {
32 72
        $index = $this->count();
33 72
        if ($value instanceof DefinitionInterface) {
34 72
            $index = $value->getName();
35 72
        }
36 72
        $this->offsetSet($index, $value);
37 72
    }
38
39
    /**
40
     * Sets the value on a specific offset index
41
     *
42
     * @param mixed $offset The index being set.
43
     * @param mixed $value  The new value for the index.
44
     */
45 74
    public function offsetSet($offset, $value)
46
    {
47 74
        if (!($value instanceof DefinitionInterface)) {
48 2
            throw new InvalidArgumentException(
49
                "Trying to add an object to definition list that does ".
50
                "not implement 'DefinitionInterface'."
51 2
            );
52
        }
53
54 72
        parent::offsetSet($offset, $value);
55
    }
56
}