Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
73.58% |
39 / 53 |
|
53.33% |
8 / 15 |
CRAP | |
0.00% |
0 / 1 |
| common_Collection | |
73.58% |
39 / 53 |
|
53.33% |
8 / 15 |
30.92 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| count | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| indexOf | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| get | |
80.00% |
4 / 5 |
|
0.00% |
0 / 1 |
3.07 | |||
| isEmpty | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| offsetSet | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| offsetGet | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| offsetUnset | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| offsetExists | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getIterator | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| add | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| remove | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
3.03 | |||
| union | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| intersect | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg |
| 19 | * (under the project TAO & TAO2); |
| 20 | * 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung |
| 21 | * (under the project TAO-TRANSFER); |
| 22 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 23 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | |
| 28 | /** |
| 29 | * Generis Object Oriented API - common\class.Collection.php |
| 30 | * |
| 31 | * Object Collection |
| 32 | * |
| 33 | * This file is part of Generis Object Oriented API. |
| 34 | * |
| 35 | * Automatically generated on 24.03.2010, 14:38:36 with ArgoUML PHP module |
| 36 | * (last revised $Date: 2008-04-19 08:22:08 +0200 (Sat, 19 Apr 2008) $) |
| 37 | * |
| 38 | * @author Lionel Lecaque <lionel.lecaque@tudor.lu> |
| 39 | * @package generis |
| 40 | * @see @license GNU General Public (GPL) Version 2 http://www.opensource.org/licenses/gpl-2.0.php |
| 41 | */ |
| 42 | |
| 43 | class common_Collection extends common_Object implements IteratorAggregate, Countable |
| 44 | { |
| 45 | // --- ASSOCIATIONS --- |
| 46 | |
| 47 | |
| 48 | // --- ATTRIBUTES --- |
| 49 | |
| 50 | /** |
| 51 | * Short description of attribute sequence |
| 52 | * |
| 53 | * @access public |
| 54 | * @var array |
| 55 | */ |
| 56 | public $sequence = []; |
| 57 | |
| 58 | /** |
| 59 | * Short description of attribute container |
| 60 | * |
| 61 | * @access public |
| 62 | * @var Object |
| 63 | */ |
| 64 | public $container = null; |
| 65 | |
| 66 | // --- OPERATIONS --- |
| 67 | |
| 68 | /** |
| 69 | * Short description of method __construct |
| 70 | * |
| 71 | * @access public |
| 72 | * @author Lionel Lecaque <lionel.lecaque@tudor.lu> |
| 73 | * @param Object container |
| 74 | * @param string debug |
| 75 | * @return void |
| 76 | */ |
| 77 | public function __construct(common_Object $container, $debug = '') |
| 78 | { |
| 79 | |
| 80 | $this->sequence = []; |
| 81 | $this->container = $container; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * return the number of node of the collection (only this level) |
| 86 | * |
| 87 | * @access public |
| 88 | * @author Lionel Lecaque <lionel.lecaque@tudor.lu> |
| 89 | * @return int |
| 90 | */ |
| 91 | public function count() |
| 92 | { |
| 93 | $returnValue = (int) 0; |
| 94 | |
| 95 | |
| 96 | $returnValue = count($this->sequence); |
| 97 | |
| 98 | |
| 99 | return (int) $returnValue; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * return the index of the node array at which the given node resides |
| 104 | * |
| 105 | * @access public |
| 106 | * @author Lionel Lecaque <lionel.lecaque@tudor.lu> |
| 107 | * @param Object object |
| 108 | * @return int |
| 109 | */ |
| 110 | public function indexOf(common_Object $object) |
| 111 | { |
| 112 | $returnValue = (int) 0; |
| 113 | |
| 114 | |
| 115 | $returnValue = -1; |
| 116 | foreach ($this->sequence as $index => $_object) { |
| 117 | if ($object === $_object) { |
| 118 | return $index; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | |
| 123 | return (int) $returnValue; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Retrun the node at the given index |
| 128 | * |
| 129 | * @access public |
| 130 | * @author Lionel Lecaque <lionel.lecaque@tudor.lu> |
| 131 | * @param int index |
| 132 | * @return common_Object |
| 133 | */ |
| 134 | public function get($index) |
| 135 | { |
| 136 | $returnValue = null; |
| 137 | |
| 138 | |
| 139 | |
| 140 | $returnValue = isset($this->sequence[$index]) ? $this->sequence[$index] : null; |
| 141 | if ($returnValue == null) { |
| 142 | throw new common_Exception('index is out of range'); |
| 143 | } |
| 144 | |
| 145 | |
| 146 | return $returnValue; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Short description of method isEmpty |
| 151 | * |
| 152 | * @access public |
| 153 | * @author Lionel Lecaque <lionel.lecaque@tudor.lu> |
| 154 | * @return boolean |
| 155 | */ |
| 156 | public function isEmpty() |
| 157 | { |
| 158 | $returnValue = (bool) false; |
| 159 | |
| 160 | |
| 161 | $returnValue = (count($this->sequence) == 0); |
| 162 | |
| 163 | |
| 164 | return (bool) $returnValue; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Implementation of ArrayAccess:offsetSet() |
| 169 | * |
| 170 | * @access public |
| 171 | * @author Lionel Lecaque <lionel.lecaque@tudor.lu> |
| 172 | * @param Object key |
| 173 | * @param Object value |
| 174 | * @return void |
| 175 | */ |
| 176 | public function offsetSet(common_Object $key, common_Object $value) |
| 177 | { |
| 178 | |
| 179 | $this->sequence[$key] = $value; |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Implementation of ArrayAccess:offsetGet() |
| 184 | * |
| 185 | * @access public |
| 186 | * @author Lionel Lecaque <lionel.lecaque@tudor.lu> |
| 187 | * @param Object key |
| 188 | * @return common_Object |
| 189 | */ |
| 190 | public function offsetGet(common_Object $key) |
| 191 | { |
| 192 | $returnValue = null; |
| 193 | |
| 194 | |
| 195 | $returnValue = $this->sequence[$key]; |
| 196 | |
| 197 | |
| 198 | return $returnValue; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Implementation of ArrayAccess:offsetUnset() |
| 203 | * |
| 204 | * @access public |
| 205 | * @author Lionel Lecaque <lionel.lecaque@tudor.lu> |
| 206 | * @param Object key |
| 207 | * @return void |
| 208 | */ |
| 209 | public function offsetUnset(common_Object $key) |
| 210 | { |
| 211 | |
| 212 | unset($this->sequence[$key]); |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Implementation of ArrayAccess:offsetExists() |
| 217 | * |
| 218 | * @access public |
| 219 | * @author Lionel Lecaque <lionel.lecaque@tudor.lu> |
| 220 | * @param Object key |
| 221 | * @return boolean |
| 222 | */ |
| 223 | public function offsetExists(common_Object $key) |
| 224 | { |
| 225 | $returnValue = (bool) false; |
| 226 | |
| 227 | |
| 228 | $returnValue = isset($this->sequence[$key]); |
| 229 | |
| 230 | |
| 231 | return (bool) $returnValue; |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Implementation of IteratorAggregate::getIterator() |
| 236 | * |
| 237 | * @access public |
| 238 | * @author Lionel Lecaque <lionel.lecaque@tudor.lu> |
| 239 | * @return mixed |
| 240 | */ |
| 241 | public function getIterator() |
| 242 | { |
| 243 | |
| 244 | return new ArrayIterator($this->sequence); |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Add a node to the collection |
| 249 | * |
| 250 | * @access public |
| 251 | * @author Lionel Lecaque <lionel.lecaque@tudor.lu> |
| 252 | * @param Object node |
| 253 | * @return mixed |
| 254 | */ |
| 255 | public function add(common_Object $node) |
| 256 | { |
| 257 | |
| 258 | $this->sequence[] = $node; |
| 259 | $returnValue = $node; |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Remove the node from the collection |
| 264 | * |
| 265 | * @access public |
| 266 | * @author Lionel Lecaque <lionel.lecaque@tudor.lu> |
| 267 | * @param Object object |
| 268 | * @return boolean |
| 269 | */ |
| 270 | public function remove(common_Object $object) |
| 271 | { |
| 272 | $returnValue = (bool) false; |
| 273 | |
| 274 | |
| 275 | foreach ($this->sequence as $index => $_node) { |
| 276 | if ($_node === $object) { |
| 277 | unset($this->sequence[$index]); |
| 278 | $this->sequence = array_values($this->sequence); |
| 279 | return true; |
| 280 | } |
| 281 | } |
| 282 | return false; |
| 283 | |
| 284 | |
| 285 | return (bool) $returnValue; |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * Short description of method union |
| 290 | * |
| 291 | * @access public |
| 292 | * @author Lionel Lecaque <lionel.lecaque@tudor.lu> |
| 293 | * @param Collection collection |
| 294 | * @return common_Collection |
| 295 | */ |
| 296 | public function union(common_Collection $collection) |
| 297 | { |
| 298 | $returnValue = null; |
| 299 | |
| 300 | |
| 301 | $returnValue = new common_Collection($this); |
| 302 | $returnValue->sequence = array_merge($this->sequence, $collection->sequence); |
| 303 | |
| 304 | |
| 305 | return $returnValue; |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * Short description of method intersect |
| 310 | * |
| 311 | * @access public |
| 312 | * @author Lionel Lecaque <lionel.lecaque@tudor.lu> |
| 313 | * @param Collection collection |
| 314 | * @return common_Collection |
| 315 | */ |
| 316 | public function intersect(common_Collection $collection) |
| 317 | { |
| 318 | $returnValue = null; |
| 319 | |
| 320 | |
| 321 | $returnValue = new common_Collection(new common_Object(__METHOD__)); |
| 322 | $returnValue->sequence = array_uintersect( |
| 323 | $this->sequence, |
| 324 | $collection->sequence, |
| 325 | 'core_kernel_classes_ContainerComparator::compare' |
| 326 | ); |
| 327 | |
| 328 | |
| 329 | return $returnValue; |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Short description of method toArray |
| 334 | * |
| 335 | * @access public |
| 336 | * @author Lionel Lecaque <lionel.lecaque@tudor.lu> |
| 337 | * @return array |
| 338 | */ |
| 339 | public function toArray() |
| 340 | { |
| 341 | $returnValue = []; |
| 342 | |
| 343 | |
| 344 | foreach ($this->getIterator() as $it) { |
| 345 | $returnValue[] = $it; |
| 346 | } |
| 347 | |
| 348 | |
| 349 | return (array) $returnValue; |
| 350 | } |
| 351 | } |