1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is a part of Sculpin. |
5
|
|
|
* |
6
|
|
|
* (c) Dragonfly Development Inc. |
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 Symplify\PHP7_Sculpin\PostsBundle\ProxySourceCollection; |
13
|
|
|
|
14
|
|
|
use Symplify\PHP7_Sculpin\PostsBundle\ProxySourceCollection\Sorter\DefaultSorter; |
15
|
|
|
|
16
|
|
|
class ProxySourceCollection implements \ArrayAccess, \Iterator, \Countable |
17
|
|
|
{ |
18
|
|
|
protected $items; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var DefaultSorter |
22
|
|
|
*/ |
23
|
|
|
protected $sorter; |
24
|
|
|
|
25
|
|
|
public function __construct(array $items = [], DefaultSorter $sorter = null) |
26
|
|
|
{ |
27
|
|
|
$this->items = $items; |
28
|
|
|
$this->sorter = $sorter ?: new DefaultSorter(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function offsetSet($offset, $value) |
32
|
|
|
{ |
33
|
|
|
if (is_null($offset)) { |
34
|
|
|
$this->items[] = $value; |
35
|
|
|
} else { |
36
|
|
|
$this->items[$offset] = $value; |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function offsetExists($offset) |
41
|
|
|
{ |
42
|
|
|
return isset($this->items[$offset]); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function offsetUnset($offset) |
46
|
|
|
{ |
47
|
|
|
unset($this->items[$offset]); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function offsetGet($offset) |
51
|
|
|
{ |
52
|
|
|
return isset($this->items[$offset]) ? $this->items[$offset] : null; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function rewind() |
56
|
|
|
{ |
57
|
|
|
reset($this->items); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function current() |
61
|
|
|
{ |
62
|
|
|
return current($this->items); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function key() |
66
|
|
|
{ |
67
|
|
|
return key($this->items); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function next() |
71
|
|
|
{ |
72
|
|
|
return next($this->items); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function valid() |
76
|
|
|
{ |
77
|
|
|
return $this->current() !== false; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function count() |
81
|
|
|
{ |
82
|
|
|
return count($this->items); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function init() |
86
|
|
|
{ |
87
|
|
|
// $this->sort(); |
|
|
|
|
88
|
|
|
|
89
|
|
|
$previousItem = null; |
90
|
|
|
$item = null; |
91
|
|
|
|
92
|
|
|
foreach (array_reverse($this->items) as $item) { |
93
|
|
|
if ($previousItem) { |
94
|
|
|
$previousItem->setNextItem($item); |
95
|
|
|
} |
96
|
|
|
$item->setPreviousItem($previousItem); |
97
|
|
|
$previousItem = $item; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
if ($item) { |
101
|
|
|
$item->setNextItem(null); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function first() |
106
|
|
|
{ |
107
|
|
|
$keys = array_keys($this->items); |
108
|
|
|
|
109
|
|
|
return $this->items[$keys[0]]; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
// public function sort() |
|
|
|
|
113
|
|
|
// { |
114
|
|
|
// uasort($this->items, [$this->sorter, 'sort']); |
115
|
|
|
// } |
116
|
|
|
} |
117
|
|
|
|
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.