http://phing.info/

Source Code Coverage

Designed for use with PHPUnit2, Xdebug and Phing.

Methods: 17 LOC: 241 Statements: 19
Legend: executednot executeddead code
Source file Statements Methods Total coverage
Delegate.php 100.0% 100.0% 100.0%
 
1
<?php
2
/**
3
 * Xyster Framework
4
 *
5
 * This source file is subject to the new BSD license that is bundled
6
 * with this package in the file LICENSE.txt.
7
 * It is also available through the world-wide-web at this URL:
8
 * http://www.opensource.org/licenses/bsd-license.php
9
 *
10
 * @category  Xyster
11
 * @package   Xyster_Collection
12
 * @copyright Copyright LibreWorks, LLC (http://libreworks.net)
13
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
14
 * @version   $Id: Delegate.php 418 2010-10-18 21:40:08Z jonathanhawk $
15
 */
16
namespace Xyster\Collection;
17
/**
18
 * A collection that delegates its methods to an internal collection
19
 *
20
 * @category  Xyster
21
 * @package   Xyster_Collection
22
 * @copyright Copyright LibreWorks, LLC (http://libreworks.net)
23
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
24
 */
25
class Delegate implements ICollection
26
{
27
    /**
28
     * @var ICollection
29
     */
30
    private $_delegate;
31
32
    /**
33
     * Creates a new delegate collection
34
     *
35
     * @param ICollection $delegate
36
     */
37
    public function __construct( ICollection $delegate )
38
    {
39 33
        $this->_delegate = $delegate;
40
    }
41
42
    /**
43
     * Adds an item to the collection
44
     *
45
     * Some collections don't accept duplicate values, and should return false
46
     * if the provided value is already in the collection.  If the collection is
47
     * not allowed to contain the supplied value, an InvalidArgumentException
48
     * should be thrown.
49
     *
50
     * @param mixed $item The item to add
51
     * @return boolean Whether the collection changed as a result of this method
52
     * @throws InvalidArgumentException if the collection cannot contain the value
53
     * @throws \Xyster\Collection\Exception if the collection cannot be modified
54
     */
55
    function add( $item )
56
    {
57 1
        return $this->_delegate->add($item);
58
    }
59
60
    /**
61
     * Removes all items from the collection
62
     *
63
     * @throws \Xyster\Collection\Exception if the collection cannot be modified
64
     */
65
    public function clear()
66
    {
67 1
        $this->_delegate->clear();
68
    }
69
70
    /**
71
     * Gets the number of items in the collection
72
     *
73
     * @return int The number of items
74
     */
75
    public function count()
76
    {
77 11
        return $this->_delegate->count();
78
    }
79
80
    /**
81
     * Gets an iterator for the values in the collection
82
     *
83
     * @return SeekableIterator
84
     */
85
    public function getIterator()
86
    {
87 8
        return $this->_delegate->getIterator();
88
    }
89
90
    /**
91
     * Tests to see whether the collection contains the value supplied
92
     *
93
     * If the supplied value is an object, the comparison will be done for
94
     * identity (===) and not for value (==).
95
     *
96
     * @param mixed $item The item to test
97
     * @return boolean Whether the collection contains the supplied value
98
     */
99
    public function contains( $item )
100
    {
101 3
        return $this->_delegate->contains($item);
102
    }
103
104
    /**
105
     * Tests to see whether the collection contains all of the supplied values
106
     *
107
     * @param ICollection $values The values to test
108
     * @return boolean Whether the collection contains all of the supplied values
109
     */
110
    public function containsAll( ICollection $values )
111
    {
112 3
        return $this->_delegate->containsAll($values);
113
    }
114
115
    /**
116
     * Tests to see whether the collection contains any of the supplied values
117
     *
118
     * Basically, implementations can safely return true on the first item that
119
     * is found.
120
     *
121
     * @param ICollection $values The values to test
122
     * @return boolean Whether the collection contains any of the supplied values
123
     */
124
    public function containsAny( ICollection $values )
125
    {
126 1
        return $this->_delegate->containsAny($values);
127
    }
128
129
    /**
130
     * Tests to see if the collection contains no elements
131
     *
132
     * The return value from this method should be equivalent to
133
     * <code>( $collection->count() == 0 )</code>.
134
     *
135
     * @return boolean Whether this collection has no elements
136
     */
137
    public function isEmpty()
138
    {
139 1
        return $this->_delegate->isEmpty();
140
    }
141
142
    /**
143
     * Merges the values from the supplied collection into this one
144
     *
145
     * If the implementing collection is not allowed to contain the same value
146
     * twice, it should only add ones in $values not present in $this.  If the
147
     * implementing collection can contain duplicates, then the values can just
148
     * be appended.
149
     *
150
     * If the collection is not allowed to contain the supplied value, an
151
     * InvalidArgumentException should be thrown.
152
     *
153
     * @param ICollection $values
154
     * @return boolean Whether the collection changed as a result of this method
155
     * @throws InvalidArgumentException if the collection cannot contain the value
156
     * @throws \Xyster\Collection\Exception if the collection cannot be modified
157
     */
158
    public function merge( ICollection $values )
159
    {
160 1
        return $this->_delegate->merge($values);
161
    }
162
163
    /**
164
     * Removes the specified value from the collection
165
     *
166
     * @param mixed $item The value to remove
167
     * @return boolean If the value was in the collection
168
     * @throws \Xyster\Collection\Exception if the collection cannot be modified
169
     */
170
    public function remove( $item )
171
    {
172 1
        return $this->_delegate->remove($item);
173
    }
174
175
    /**
176
     * Removes all of the specified values from the collection
177
     *
178
     * @param ICollection $values The values to remove
179
     * @return boolean Whether the collection changed as a result of this method
180
     * @throws \Xyster\Collection\Exception if the collection cannot be modified
181
     */
182
    public function removeAll( ICollection $values )
183
    {
184 1
        return $this->_delegate->removeAll($values);
185
    }
186
187
    /**
188
     * Removes all values from the collection except for the ones specified
189
     *
190
     * If the collection doesn't contain any of the values supplied, it should
191
     * simply be emptied.
192
     *
193
     * @param ICollection $values The values to keep
194
     * @return boolean Whether the collection changed as a result of this method
195
     * @throws \Xyster\Collection\Exception if the collection cannot be modified
196
     */
197
    public function retainAll( ICollection $values )
198
    {
199 1
        return $this->_delegate->retainAll($values);
200
    }
201
202
    /**
203
     * Puts the items in this collection into an array
204
     *
205
     * @return array The items in this collection
206
     */
207
    public function toArray()
208
    {
209 1
        return $this->_delegate->toArray();
210
    }
211
212
    /**
213
     * Returns the string representation of this object
214
     *
215
     * @return string
216
     */
217
    public function __toString()
218
    {
219 4
        return $this->_delegate->__toString();
220
    }
221
222
    /**
223
     * Gets the delegate collection
224
     *
225
     * @return ICollection
226
     */
227
    protected function _getDelegate()
228
    {
229 4
        return $this->_delegate;
230
    }
231
232
    /**
233
     * Sets the delegate collection
234
     *
235
     * @param ICollection $collection
236
     */
237
    protected function _setDelegate( ICollection $collection )
238
    {
239 24
        $this->_delegate = $collection;
240
    }
241 1
}


Report generated at 2010-10-18T17:19:49-04:00