1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of sitemap-common. |
4
|
|
|
* |
5
|
|
|
* (c) 2016 Daniele Moraschi |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace SiteMap\Schema; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
class SiteMapUrlCollection implements \Iterator, \Countable |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The array containing the entries of this collection. |
19
|
|
|
* |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
private $elements = array(); |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The iterator cursor |
26
|
|
|
* |
27
|
|
|
* @var int |
28
|
|
|
*/ |
29
|
|
|
private $index = 0; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Initializes a new SiteMapUrlCollection. |
33
|
|
|
* |
34
|
|
|
* @param array $elements |
35
|
|
|
*/ |
36
|
|
|
public function __construct(array $elements = array()) |
37
|
|
|
{ |
38
|
|
|
foreach ($elements as $siteMapUrl) { |
39
|
|
|
$this->add($siteMapUrl); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param SiteMapUrl $siteMapUrl |
45
|
|
|
* @return SiteMapUrl |
46
|
|
|
*/ |
47
|
|
|
public function add(SiteMapUrl $siteMapUrl) |
48
|
|
|
{ |
49
|
|
|
return $this->elements[] = $siteMapUrl; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param $offset |
54
|
|
|
* @param SiteMapUrl $siteMapUrl |
55
|
|
|
* @return SiteMapUrl |
56
|
|
|
*/ |
57
|
|
|
public function set($offset, SiteMapUrl $siteMapUrl) |
58
|
|
|
{ |
59
|
|
|
return $this->elements[$offset] = $siteMapUrl; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Required by interface Countable. |
64
|
|
|
* |
65
|
|
|
* {@inheritDoc} |
66
|
|
|
*/ |
67
|
|
|
public function count() |
68
|
|
|
{ |
69
|
|
|
return count($this->elements); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
|
|
public function toArray() |
76
|
|
|
{ |
77
|
|
|
return $this->elements; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Required by interface Iterator. |
82
|
|
|
* |
83
|
|
|
* {@inheritDoc} |
84
|
|
|
*/ |
85
|
|
|
public function current() |
86
|
|
|
{ |
87
|
|
|
return $this->elements[$this->index]; |
88
|
|
|
//return current($this->elements); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Required by interface Iterator. |
93
|
|
|
* |
94
|
|
|
* {@inheritDoc} |
95
|
|
|
*/ |
96
|
|
|
public function next() |
97
|
|
|
{ |
98
|
|
|
$this->index ++; |
99
|
|
|
//return next($this->elements); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Required by interface Iterator. |
104
|
|
|
* |
105
|
|
|
* {@inheritDoc} |
106
|
|
|
*/ |
107
|
|
|
public function key() |
108
|
|
|
{ |
109
|
|
|
return $this->index; |
110
|
|
|
//return key($this->elements); |
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Required by interface Iterator. |
115
|
|
|
* |
116
|
|
|
* {@inheritDoc} |
117
|
|
|
*/ |
118
|
|
|
public function valid() |
119
|
|
|
{ |
120
|
|
|
return isset($this->elements[$this->key()]); |
121
|
|
|
//return ($this->key() < $this->count()); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Required by interface Iterator. |
126
|
|
|
* |
127
|
|
|
* {@inheritDoc} |
128
|
|
|
*/ |
129
|
|
|
public function rewind() |
130
|
|
|
{ |
131
|
|
|
$this->index = 0; |
132
|
|
|
//return reset($this->elements); |
|
|
|
|
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
} |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.