Completed
Push — release/3.0 ( 106435...2e0212 )
by Alex
01:55
created

Feed::setLanguage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
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 36
    public function __construct()
35
    {
36 36
        $this->items = new \ArrayIterator();
37
38 36
        parent::__construct();
39 36
    }
40
41
    /**
42
     * @return string $url
43
     */
44 2
    public function getUrl()
45
    {
46 2
        return $this->url;
47
    }
48
49
    /**
50
     * @param string $url
51
     * @return FeedInterface
52
     */
53 2
    public function setUrl($url)
54
    {
55 2
        $this->url = $url;
56
        
57 2
        return $this;
58
    }
59
60
    /**
61
     * @return string $language
62
     */
63 2
    public function getLanguage()
64
    {
65 2
        return $this->language;
66
    }
67
68
    /**
69
     * @param string $language
70
     * @return FeedInterface
71
     */
72 2
    public function setLanguage($language)
73
    {
74 2
        $this->language = $language;
75
76 2
        return $this;
77
    }
78
79
80
81
82
    /**
83
     * (PHP 5 &gt;= 5.0.0)<br/>
84
     * Return the current element
85
     * @link http://php.net/manual/en/iterator.current.php
86
     * @return mixed Can return any type.
87
     */
88 16
    public function current()
89
    {
90 16
        return $this->items->current();
91
    }
92
93
    /**
94
     * (PHP 5 &gt;= 5.0.0)<br/>
95
     * Move forward to next element
96
     * @link http://php.net/manual/en/iterator.next.php
97
     * @return void Any returned value is ignored.
98
     */
99 14
    public function next()
100
    {
101 14
        $this->items->next();
102 14
    }
103
104
    /**
105
     * (PHP 5 &gt;= 5.0.0)<br/>
106
     * Return the key of the current element
107
     * @link http://php.net/manual/en/iterator.key.php
108
     * @return mixed scalar on success, or null on failure.
109
     */
110 2
    public function key()
111
    {
112 2
        return $this->items->key();
113
    }
114
115
    /**
116
     * (PHP 5 &gt;= 5.0.0)<br/>
117
     * Checks if current position is valid
118
     * @link http://php.net/manual/en/iterator.valid.php
119
     * @return boolean The return value will be casted to boolean and then evaluated.
120
     *                 Returns true on success or false on failure.
121
     */
122 18
    public function valid()
123
    {
124 18
        return $this->items->valid();
125
    }
126
127
    /**
128
     * (PHP 5 &gt;= 5.0.0)<br/>
129
     * Rewind the Iterator to the first element
130
     * @link http://php.net/manual/en/iterator.rewind.php
131
     * @return void Any returned value is ignored.
132
     */
133 16
    public function rewind()
134
    {
135 16
        $this->items->rewind();
136 16
    }
137
138
    /**
139
     * @param  ItemInterface $item
140
     * @return $this
141
     */
142 23
    public function add(ItemInterface $item)
143
    {
144 23
        $this->items->append($item);
145
146 23
        return $this;
147
    }
148
149
    /**
150
     * @return ItemInterface
151
     */
152 8
    public function newItem()
153
    {
154 8
        return new Item();
155
    }
156
157
    /**
158
     * @return array
159
     */
160 1
    public function jsonSerialize()
161
    {
162 1
        return $this->toArray();
163
    }
164
165
    /**
166
     * @return array
167
     */
168 2
    public function toArray()
169
    {
170 2
        $items = [];
171
172 2
        foreach ($this->items as $item) {
173 2
            $items[] = $item->toArray();
174 2
        }
175
176 2
        $properties = parent::toArray();
177 2
        $properties['items'] = $items;
178
179 2
        return $properties;
180
    }
181
182
    /**
183
     * @return int
184
     */
185 1
    public function count()
186
    {
187 1
        return count($this->items);
188
    }
189
}
190