Completed
Push — master ( 124fed...6caa0a )
by Tomáš
12s
created

ProxySourceCollection::first()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
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();
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
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()
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
113
//    {
114
//        uasort($this->items, [$this->sorter, 'sort']);
115
//    }
116
}
117