SiteMapUrlCollection::count()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
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);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
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);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
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());
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
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);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
133
    }
134
135
}