UseCollection   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 1 Features 1
Metric Value
wmc 13
c 7
b 1
f 1
lcom 1
cbo 2
dl 0
loc 100
ccs 34
cts 34
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A add() 0 8 2
A getIterator() 0 4 1
A toString() 0 10 2
A init() 0 3 1
A getParent() 0 4 1
A setParent() 0 9 2
A setOptions() 0 11 3
1
<?php
2
3
/*
4
 * This file is part of the ClassGeneration package.
5
 *
6
 * (c) Antonio Spinelli <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ClassGeneration;
13
14
use ClassGeneration\Collection\ArrayCollection;
15
use ClassGeneration\Element\ElementInterface;
16
17
/**
18
 * Use ClassGeneration
19
 * @author Antonio Spinelli <[email protected]>
20
 */
21
class UseCollection extends ArrayCollection implements ElementInterface
22
{
23
24
    protected $parent;
25
26
    /**
27
     * Initializes a new ArrayCollection.
28
     *
29
     * @param UseClass[] $elements
30
     */
31 39
    public function __construct(array $elements = array())
32
    {
33 39
        parent::__construct($elements);
34 39
        $this->init();
35 39
    }
36
37
    /**
38
     * Adds a new Use on the collection.
39
     *
40
     * @param UseInterface $use
41
     *
42
     * @throws \InvalidArgumentException
43
     * @return bool
44
     */
45 3
    public function add($use)
46
    {
47 3
        if (!$use instanceof UseInterface) {
48 1
            throw new \InvalidArgumentException('This Property must be a instance of \ClassGeneration\UseInterface');
49
        }
50
51 3
        return parent::add($use);
52
    }
53
54
    /**
55
     * @inheritdoc
56
     * @return UseIterator|UseClass[]
57
     */
58 10
    public function getIterator()
59
    {
60 10
        return new UseIterator($this);
61
    }
62
63
    /**
64
     * Parse the Uses to string;
65
     * @return string
66
     */
67 10
    public function toString()
68
    {
69 10
        $uses = $this->getIterator();
70 10
        $string = '';
71 10
        foreach ($uses as $use) {
72 1
            $string .= $use->toString();
73 10
        }
74
75 10
        return $string;
76
    }
77
78
    /**
79
     * @inheritdoc
80
     */
81 39
    public function init()
82
    {
83 39
    }
84
85
    /**
86
     * @inheritdoc
87
     */
88 1
    public function getParent()
89
    {
90 1
        return $this->parent;
91
    }
92
93
    /**
94
     * @inheritdoc
95
     */
96 1
    public function setParent(ElementInterface $parent)
97
    {
98 1
        if (!$parent instanceof PhpClassInterface) {
99 1
            throw new \InvalidArgumentException('Only accept instances from ClassGeneration\PhpClassInterface');
100
        }
101 1
        $this->parent = $parent;
102
103 1
        return $this;
104
    }
105
106
    /**
107
     * @inheritdoc
108
     */
109 1
    public function setOptions(array $options)
110
    {
111 1
        foreach ($options as $prop => $option) {
112 1
            $method = 'set' . ucfirst($prop);
113 1
            if (method_exists($this, $method)) {
114 1
                $this->$method($option);
115 1
            }
116 1
        }
117
118 1
        return $this;
119
    }
120
}
121