Issues (38)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/FeedIo/Feed/Node.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\Feed;
12
13
use FeedIo\Feed\Node\Category;
14
use FeedIo\Feed\Node\CategoryInterface;
15
16
class Node implements NodeInterface, ElementsAwareInterface, ArrayableInterface
17
{
18
    use ElementsAwareTrait;
19
20
    /**
21
     * @var \ArrayIterator
22
     */
23
    protected $categories;
24
25
    /**
26
     * @var string
27
     */
28
    protected $title;
29
30
    /**
31
     * @var string
32
     */
33
    protected $publicId;
34
35
    /**
36
     * @var string
37
     */
38
    protected $description;
39
40
    /**
41
     * @var \DateTime
42
     */
43
    protected $lastModified;
44
45
    /**
46
     * @var string
47
     */
48
    protected $link;
49
50
    /**
51
     * @var string
52
     */
53
    protected $host;
54
55 122
    public function __construct()
56
    {
57 122
        $this->initElements();
58 122
        $this->categories = new \ArrayIterator();
59 122
    }
60
61
    /**
62
     * @param  string $name  element name
63
     * @param  string $value element value
64
     * @return NodeInterface
65
     */
66 13
    public function set(string $name, string $value = null) : NodeInterface
67
    {
68 13
        $element = $this->newElement();
69
70 13
        $element->setName($name);
71 13
        $element->setValue($value);
72
73 13
        $this->addElement($element);
74
75 13
        return $this;
76
    }
77
78
    /**
79
     * returns node's categories
80
     *
81
     * @return iterable
82
     */
83 12
    public function getCategories() : iterable
84
    {
85 12
        return $this->categories;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->categories; (ArrayIterator) is incompatible with the return type declared by the interface FeedIo\Feed\NodeInterface::getCategories of type FeedIo\Feed\iterable.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
86
    }
87
88
    /**
89
     * @return \Generator
90
     */
91 6
    public function getCategoriesGenerator() : \Generator
92
    {
93 6
        foreach ($this->categories as $category) {
94 2
            yield $category->getlabel();
95
        }
96 5
    }
97
98
    /**
99
     * adds a category to the node
100
     *
101
     * @param \FeedIo\Feed\Node\CategoryInterface $category
102
     * @return NodeInterface
103
     */
104 16
    public function addCategory(CategoryInterface $category) : NodeInterface
105
    {
106 16
        $this->categories->append($category);
107
108 16
        return $this;
109
    }
110
111
    /**
112
     * returns a new CategoryInterface
113
     *
114
     * @return \FeedIo\Feed\Node\CategoryInterface
115
     */
116 9
    public function newCategory() : CategoryInterface
117
    {
118 9
        return new Category();
119
    }
120
121
    /**
122
     * @return string
123
     */
124 24
    public function getTitle() : ? string
125
    {
126 24
        return $this->title;
127
    }
128
129
    /**
130
     * @param  string $title
131
     * @return NodeInterface
132
     */
133 29
    public function setTitle(string $title = null) : NodeInterface
134
    {
135 29
        $this->title = $title;
136
137 29
        return $this;
138
    }
139
140
    /**
141
     * @return string
142
     */
143 14
    public function getPublicId() : ? string
144
    {
145 14
        return $this->publicId;
146
    }
147
148
    /**
149
     * @param  string $publicId
150
     * @return NodeInterface
151
     */
152 16
    public function setPublicId(string $publicId = null) : NodeInterface
153
    {
154 16
        $this->publicId = $publicId;
155
156 16
        return $this;
157
    }
158
159
    /**
160
     * @return string
161
     */
162 15
    public function getDescription() : ? string
163
    {
164 15
        return $this->description;
165
    }
166
167
    /**
168
     * @param  string $description
169
     * @return NodeInterface
170
     */
171 23
    public function setDescription(string $description = null) : NodeInterface
172
    {
173 23
        $this->description = $description;
174
175 23
        return $this;
176
    }
177
178
    /**
179
     * @return \DateTime
180
     */
181 27
    public function getLastModified() : ? \DateTime
182
    {
183 27
        return $this->lastModified;
184
    }
185
186
    /**
187
     * @param  \DateTime $lastModified
188
     * @return NodeInterface
189
     */
190 34
    public function setLastModified(\DateTime $lastModified = null) : NodeInterface
191
    {
192 34
        $this->lastModified = $lastModified;
193
194 34
        return $this;
195
    }
196
197
    /**
198
     * @return string
199
     */
200 16
    public function getHost(): ? string
201
    {
202 16
        return $this->host;
203
    }
204
205
    /**
206
     * @return string
207
     */
208 19
    public function getLink() : ? string
209
    {
210 19
        return $this->link;
211
    }
212
213
    /**
214
     * @param  string $link
215
     * @return NodeInterface
216
     */
217 27
    public function setLink(string $link = null) : NodeInterface
218
    {
219 27
        $this->link = $link;
220 27
        $this->setHost($link);
221
222 27
        return $this;
223
    }
224
225
    /**
226
     * @param string|null $link
227
     */
228 27
    protected function setHost(string $link = null): void
229
    {
230 27
        if (!is_null($link)) {
231 27
            $this->host = '//' . parse_url($link, PHP_URL_HOST);
232
        }
233 27
    }
234
235
    /**
236
     * @param string $name element name
237
     * @return null|string
238
     */
239 4
    public function getValue(string $name) : ? string
240
    {
241 4
        foreach ($this->getElementIterator($name) as $element) {
242 4
            return $element->getValue();
243
        }
244
245 1
        return null;
246
    }
247
248
    /**
249
     * @return array
250
     */
251 5
    public function toArray() : array
252
    {
253 5
        $properties = get_object_vars($this);
254 5
        $properties['elements'] = iterator_to_array($this->getElementsGenerator());
255 5
        $properties['categories'] = iterator_to_array($this->getCategoriesGenerator());
256
257 5
        foreach ($properties as $name => $property) {
258 5
            if ($property instanceof \DateTime) {
259 3
                $properties[$name] = $property->format(\DateTime::ATOM);
260 5
            } elseif ($property instanceof \ArrayIterator) {
261 4
                $properties[$name] = [];
262 4
                foreach ($property as $entry) {
263 4
                    if ($entry instanceof ArrayableInterface) {
264 4
                        $entry = $entry->toArray();
265
                    }
266 4
                    $properties[$name] []= $entry;
267
                }
268 5
            } elseif ($property instanceof ArrayableInterface) {
269 2
                $properties[$name] = $property->toArray();
270
            }
271
        }
272
273 5
        return $properties;
274
    }
275
}
276