Completed
Push — master ( 33bbaa...8a8db9 )
by Alex
13s queued 11s
created

Feed::rewind()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of the feed-io package.
4
 *
5
 * (c) Alexandre Debril <[email protected]>
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 FeedIo;
12
13
use FeedIo\Feed\Node;
14
use FeedIo\Feed\Item;
15
use FeedIo\Feed\ItemInterface;
16
17
class Feed extends Node implements FeedInterface, \JsonSerializable
18
{
19
    /**
20
     * @var \ArrayIterator
21
     */
22
    protected $items;
23
24
    /**
25
     * @var string $url
26
     */
27
    protected $url;
28
29
    /**
30
     * @var string $language
31
     */
32
    protected $language;
33
34
    /**
35
     * @var string $logo
36
     */
37
    protected $logo;
38
39
    protected $ns;
40
41 45
    public function __construct()
42
    {
43 45
        $this->items = new \ArrayIterator();
44 45
        $this->ns = new \ArrayIterator();
45
46 45
        parent::__construct();
47 45
    }
48
49
    /**
50
     * @return string $url
51
     */
52 3
    public function getUrl() : ? string
53
    {
54 3
        return $this->url;
55
    }
56
57
    /**
58
     * @param string $url
59
     * @return FeedInterface
60
     */
61 5
    public function setUrl(string $url = null) : FeedInterface
62
    {
63 5
        $this->url = $url;
64
65 5
        return $this;
66
    }
67
68
    /**
69
     * @return string $language
70
     */
71 4
    public function getLanguage(): ? string
72
    {
73 4
        return $this->language;
74
    }
75
76
    /**
77
     * @param string $language
78
     * @return FeedInterface
79
     */
80 2
    public function setLanguage(string $language = null): FeedInterface
81
    {
82 2
        $this->language = $language;
83
84 2
        return $this;
85
    }
86
87
    /**
88
     * @return string
89
     */
90 8
    public function getLogo() : ? string
91
    {
92 8
        return $this->logo;
93
    }
94
95
    /**
96
     * @param  string $logo
97
     * @return NodeInterface
98
     */
99 4
    public function setLogo(string $logo = null) : FeedInterface
100
    {
101 4
        $this->logo = $logo;
102
103 4
        return $this;
104
    }
105
106
107
108
109
    /**
110
     * (PHP 5 &gt;= 5.0.0)<br/>
111
     * Return the current element
112
     * @link http://php.net/manual/en/iterator.current.php
113
     * @return mixed Can return any type.
114
     */
115 19
    public function current()
116
    {
117 19
        return $this->items->current();
118
    }
119
120
    /**
121
     * (PHP 5 &gt;= 5.0.0)<br/>
122
     * Move forward to next element
123
     * @link http://php.net/manual/en/iterator.next.php
124
     * @return void Any returned value is ignored.
125
     */
126 17
    public function next()
127
    {
128 17
        $this->items->next();
129 17
    }
130
131
    /**
132
     * (PHP 5 &gt;= 5.0.0)<br/>
133
     * Return the key of the current element
134
     * @link http://php.net/manual/en/iterator.key.php
135
     * @return mixed scalar on success, or null on failure.
136
     */
137 2
    public function key()
138
    {
139 2
        return $this->items->key();
140
    }
141
142
    /**
143
     * (PHP 5 &gt;= 5.0.0)<br/>
144
     * Checks if current position is valid
145
     * @link http://php.net/manual/en/iterator.valid.php
146
     * @return boolean The return value will be casted to boolean and then evaluated.
147
     *                 Returns true on success or false on failure.
148
     */
149 21
    public function valid()
150
    {
151 21
        return $this->items->valid();
152
    }
153
154
    /**
155
     * (PHP 5 &gt;= 5.0.0)<br/>
156
     * Rewind the Iterator to the first element
157
     * @link http://php.net/manual/en/iterator.rewind.php
158
     * @return void Any returned value is ignored.
159
     */
160 19
    public function rewind()
161
    {
162 19
        $this->items->rewind();
163 19
    }
164
165
    /**
166
     * @param  ItemInterface $item
167
     * @return $this
168
     */
169 28
    public function add(ItemInterface $item) : FeedInterface
170
    {
171 28
        $this->items->append($item);
172
173 28
        return $this;
174
    }
175
176 2
    public function addNS(string $ns, string $dtd) : FeedInterface
177
    {
178 2
        $this->ns->offsetSet($ns, $dtd);
179
180 2
        return $this;
181
    }
182
183 6
    public function getNS() : \ArrayIterator
184
    {
185 6
        return $this->ns;
186
    }
187
188
    /**
189
     * @return ItemInterface
190
     */
191 10
    public function newItem() : ItemInterface
192
    {
193 10
        return new Item();
194
    }
195
196
    /**
197
     * @return array
198
     */
199 1
    public function jsonSerialize() : array
200
    {
201 1
        return $this->toArray();
202
    }
203
204
    /**
205
     * @return array
206
     */
207 3
    public function toArray() : array
208
    {
209 3
        $items = [];
210
211 3
        foreach ($this->items as $item) {
212 3
            $items[] = $item->toArray();
213
        }
214
215 3
        $properties = parent::toArray();
216 3
        $properties['items'] = $items;
217
218 3
        return $properties;
219
    }
220
221
    /**
222
     * @return int
223
     */
224 1
    public function count() : int
225
    {
226 1
        return count($this->items);
227
    }
228
}
229