Completed
Push — master ( d16017...97f55f )
by Alex
9s
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 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 41
    public function __construct()
35
    {
36 41
        $this->items = new \ArrayIterator();
37
38 41
        parent::__construct();
39 41
    }
40
41
    /**
42
     * @return string $url
43
     */
44 3
    public function getUrl() : ? string
45
    {
46 3
        return $this->url;
47
    }
48
49
    /**
50
     * @param string $url
51
     * @return FeedInterface
52
     */
53 5
    public function setUrl(string $url = null) : FeedInterface
54
    {
55 5
        $this->url = $url;
56
57 5
        return $this;
58
    }
59
60
    /**
61
     * @return string $language
62
     */
63 4
    public function getLanguage(): ? string
64
    {
65 4
        return $this->language;
66
    }
67
68
    /**
69
     * @param string $language
70
     * @return FeedInterface
71
     */
72 2
    public function setLanguage(string $language = null): FeedInterface
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 19
    public function current()
89
    {
90 19
        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 17
    public function next()
100
    {
101 17
        $this->items->next();
102 17
    }
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 21
    public function valid()
123
    {
124 21
        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 19
    public function rewind()
134
    {
135 19
        $this->items->rewind();
136 19
    }
137
138
    /**
139
     * @param  ItemInterface $item
140
     * @return $this
141
     */
142 28
    public function add(ItemInterface $item) : FeedInterface
143
    {
144 28
        $this->items->append($item);
145
146 28
        return $this;
147
    }
148
149
    /**
150
     * @return ItemInterface
151
     */
152 10
    public function newItem() : ItemInterface
153
    {
154 10
        return new Item();
155
    }
156
157
    /**
158
     * @return array
159
     */
160 1
    public function jsonSerialize() : array
161
    {
162 1
        return $this->toArray();
163
    }
164
165
    /**
166
     * @return array
167
     */
168 2
    public function toArray() : array
169
    {
170 2
        $items = [];
171
172 2
        foreach ($this->items as $item) {
173 2
            $items[] = $item->toArray();
174
        }
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() : int
186
    {
187 1
        return count($this->items);
188
    }
189
}
190