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

DefinitionList::offsetSet()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
crap 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
}