Completed
Pull Request — master (#230)
by
unknown
10:00
created

Feed::getImage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
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 $image
36 41
     */
37
    protected $image;
38 41
39 41
    protected $ns;
40
41 41
    public function __construct()
42 41
    {
43
        $this->items = new \ArrayIterator();
44
        $this->ns = new \ArrayIterator();
45
46
        parent::__construct();
47 3
    }
48
49 3
    /**
50
     * @return string $url
51
     */
52
    public function getUrl() : ? string
53
    {
54
        return $this->url;
55
    }
56 5
57
    /**
58 5
     * @param string $url
59
     * @return FeedInterface
60 5
     */
61
    public function setUrl(string $url = null) : FeedInterface
62
    {
63
        $this->url = $url;
64
65
        return $this;
66 4
    }
67
68 4
    /**
69
     * @return string $language
70
     */
71
    public function getLanguage(): ? string
72
    {
73
        return $this->language;
74
    }
75 2
76
    /**
77 2
     * @param string $language
78
     * @return FeedInterface
79 2
     */
80
    public function setLanguage(string $language = null): FeedInterface
81
    {
82
        $this->language = $language;
83
84
        return $this;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getImage() : ? string
91 19
    {
92
        return $this->image;
93 19
    }
94
95
    /**
96
     * @param  string $description
0 ignored issues
show
Bug introduced by
There is no parameter named $description. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
97
     * @return NodeInterface
98
     */
99
    public function setImage(string $image = null) : FeedInterface
100
    {
101
        $this->image = $image;
102 17
103
        return $this;
104 17
    }
105 17
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 2
     * @return mixed Can return any type.
114
     */
115 2
    public function current()
116
    {
117
        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 21
     */
126
    public function next()
127 21
    {
128
        $this->items->next();
129
    }
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 19
     */
137
    public function key()
138 19
    {
139 19
        return $this->items->key();
140
    }
141
142
    /**
143
     * (PHP 5 &gt;= 5.0.0)<br/>
144
     * Checks if current position is valid
145 28
     * @link http://php.net/manual/en/iterator.valid.php
146
     * @return boolean The return value will be casted to boolean and then evaluated.
147 28
     *                 Returns true on success or false on failure.
148
     */
149 28
    public function valid()
150
    {
151
        return $this->items->valid();
152 2
    }
153
154 2
    /**
155
     * (PHP 5 &gt;= 5.0.0)<br/>
156 2
     * 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 6
     */
160
    public function rewind()
161 6
    {
162
        $this->items->rewind();
163
    }
164
165
    /**
166
     * @param  ItemInterface $item
167 10
     * @return $this
168
     */
169 10
    public function add(ItemInterface $item) : FeedInterface
170
    {
171
        $this->items->append($item);
172
173
        return $this;
174
    }
175 1
176
    public function addNS(string $ns, string $dtd) : FeedInterface
177 1
    {
178
        $this->ns->offsetSet($ns, $dtd);
179
180
        return $this;
181
    }
182
183 3
    public function getNS() : \ArrayIterator
184
    {
185 3
        return $this->ns;
186
    }
187 3
188 3
    /**
189
     * @return ItemInterface
190
     */
191 3
    public function newItem() : ItemInterface
192 3
    {
193
        return new Item();
194 3
    }
195
196
    /**
197
     * @return array
198
     */
199
    public function jsonSerialize() : array
200 1
    {
201
        return $this->toArray();
202 1
    }
203
204
    /**
205
     * @return array
206
     */
207
    public function toArray() : array
208
    {
209
        $items = [];
210
211
        foreach ($this->items as $item) {
212
            $items[] = $item->toArray();
213
        }
214
215
        $properties = parent::toArray();
216
        $properties['items'] = $items;
217
218
        return $properties;
219
    }
220
221
    /**
222
     * @return int
223
     */
224
    public function count() : int
225
    {
226
        return count($this->items);
227
    }
228
}
229