Issues (5)

Security Analysis    no request data  

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.

Blog/Library.php (4 issues)

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
2
3
namespace Matks\MarkdownBlogBundle\Blog;
4
5
class Library
6
{
7
    /**
8
     * @var string[]
9
     */
10
    private $categoryIndex = [];
11
12
    /**
13
     * @var string[]
14
     */
15
    private $dateIndex = [];
16
17
    /**
18
     * @var string[]
19
     */
20
    private $tagsIndex = [];
21
22
    /**
23
     * Posts indexed by names.
24
     *
25
     * @var Post[]
26
     */
27
    private $posts = [];
28
29
    /**
30
     * @param Post[] $postNames
0 ignored issues
show
There is no parameter named $postNames. 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...
31
     */
32
    public function __construct(array $posts)
33
    {
34 1
        foreach ($posts as $post) {
35 1
            $this->addPost($post);
36 1
        }
37 1
    }
38
39
    /**
40
     * @return Post[]
41
     */
42
    public function getAllPosts()
43
    {
44 1
        return $this->posts;
45
    }
46
47
    /**
48
     * @param string $postName
49
     *
50
     * @return bool
51
     */
52
    public function isPostRegistered($postName)
53
    {
54 1
        return true === isset($this->posts[$postName]);
55
    }
56
57
    /**
58
     * @param Post $post
59
     *
60
     * @throws \InvalidArgumentException if post is already registerd in Library
61
     */
62
    public function addPost(Post $post)
63
    {
64 1
        $postName = $post->getName();
65
66 1
        if ($this->isPostRegistered($postName)) {
67 1
            throw new \InvalidArgumentException("Duplicate post $postName");
68
        }
69
70 1
        $this->registerPost($post);
71 1
    }
72
73
    /**
74
     * @param string $postName
75
     *
76
     * @return Post|null
77
     */
78
    public function getPostByName($postName)
79
    {
80 1
        if (false === $this->isPostRegistered($postName)) {
81
            return;
82
        }
83
84 1
        return $this->posts[$postName];
85
    }
86
87
    /**
88
     * @param string[] $postNames
89
     *
90
     * @return Post[]
91
     */
92 1
    public function getPostsByName(array $postNames)
93
    {
94 1
        $posts = [];
95 1
        foreach ($postNames as $postName) {
96 1
            if (false === $this->isPostRegistered($postName)) {
97
                continue;
98
            }
99 1
            $posts[$postName] = $this->posts[$postName];
100 1
        }
101
102 1
        return $posts;
103
    }
104
105
    /**
106
     * @param string $date expected format: YYYY-MM-DD
107
     *
108
     * @return Post[]
109
     */
110
    public function getPostsByDate($date)
111
    {
112 1
        if (false === array_key_exists($date, $this->dateIndex)) {
113
            return [];
114
        }
115
116 1
        $postNames = $this->dateIndex[$date];
117
118 1
        return $this->getPostsByName($postNames);
0 ignored issues
show
$postNames is of type string, but the function expects a array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
119
    }
120
121
    /**
122
     * @param string $category
123
     *
124
     * @return Post[]
125
     */
126
    public function getPostsByCategory($category)
127
    {
128
        if (false === array_key_exists($category, $this->categoryIndex)) {
129
            return [];
130
        }
131
132
        $postNames = $this->categoryIndex[$category];
133
134
        return $this->getPostsByName($postNames);
0 ignored issues
show
$postNames is of type string, but the function expects a array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
135
    }
136
137
    /**
138
     * @param string $tag
139
     *
140
     * @return Post[]
141
     */
142
    public function getPostsByTag($tag)
143
    {
144
        if (false === array_key_exists($tag, $this->tagsIndex)) {
145
            return [];
146
        }
147
148
        $postNames = $this->tagsIndex[$tag];
149
150
        return $this->getPostsByName($postNames);
0 ignored issues
show
$postNames is of type string, but the function expects a array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
151
    }
152
153
    /**
154
     * @param Post $post
155
     */
156
    private function registerPost(Post $post)
157
    {
158 1
        $postName = $post->getName();
159
160 1
        $this->posts[$postName] = $post;
161
162 1
        $this->registerPostInDateIndex($post);
163
164 1
        if ($post->getCategory() !== null) {
165
            $this->registerPostInCategoryIndex($post);
166
        }
167
168 1
        $postTags = $post->getTags();
169 1
        if (false === empty($postTags)) {
170
            $this->registerPostInTagsIndex($post);
171
        }
172 1
    }
173
174
    /**
175
     * @param Post $post
176
     */
177
    private function registerPostInDateIndex(Post $post)
178
    {
179 1
        $postDate = $post->getPublishDate();
180
181 1
        if (array_key_exists($postDate, $this->dateIndex)) {
182 1
            $this->dateIndex[$postDate][] = $post->getName();
183 1
        } else {
184 1
            $this->dateIndex[$postDate] = [$post->getName()];
185
        }
186 1
    }
187
188
    /**
189
     * @param Post $post
190
     */
191
    private function registerPostInCategoryIndex(Post $post)
192
    {
193
        $category = $post->getCategory();
194
195
        if (array_key_exists($category, $this->categoryIndex)) {
196
            $this->categoryIndex[$category][] = $post->getName();
197
        } else {
198
            $this->categoryIndex[$category] = [$post->getName()];
199
        }
200
    }
201
202
    /**
203
     * @param Post $post
204
     */
205
    private function registerPostInTagsIndex(Post $post)
206
    {
207
        foreach ($post->getTags() as $tag) {
208
            if (array_key_exists($tag, $this->tagsIndex)) {
209
                $this->tagsIndex[$tag][] = $post->getName();
210
            } else {
211
                $this->tagsIndex[$tag] = [$post->getName()];
212
            }
213
        }
214
    }
215
}
216