Issues (32)

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.

src/Api/Album.php (14 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 Mechpave\ImgurClient\Api;
4
5
use Mechpave\ImgurClient\Entity\AlbumInterface;
6
use Mechpave\ImgurClient\Http\HttpClientInterface;
7
use Mechpave\ImgurClient\Mapper\AlbumMapper;
8
9
/**
10
 * Class Album
11
 * @package Mechpave\ImgurClient\Api
12
 * @see http://api.imgur.com/endpoints/album
13
 */
14
class Album extends AbstractApi
15
{
16
    /**
17
     * @var AlbumMapper
18
     */
19
    protected $albumMapper;
20
21
    /**
22
     * Album constructor.
23
     * @param HttpClientInterface $httpClient
24
     * @param AlbumMapper $albumMapper
25
     */
26
    public function __construct(HttpClientInterface $httpClient, AlbumMapper $albumMapper)
27
    {
28
        parent::__construct($httpClient);
29
        $this->albumMapper = $albumMapper;
30
    }
31
32
    /**
33
     * Get information about a specific album
34
     *
35
     * @param $id
36
     * @return AlbumInterface
37
     */
38
    public function get($id)
39
    {
40
        $response = $this->httpClient->get(
41
            'album/' . $id
42
        );
43
44
        $album = $this->albumMapper->buildAlbum($response->getBody()['data']);
45
46
        return $album;
47
    }
48
49
    /**
50
     * Create a new album
51
     *
52
     * @param array $ids Ids of the images you want to add to the album
53
     * @param string $title
54
     * @param string $description
55
     * @param string $privacy
56
     * @param string $layout
57
     * @param string $cover
58
     * @return AlbumInterface
59
     */
60
    public function create(
61
        $ids = [],
62
        $title = null,
63
        $description = null,
64
        $privacy = null,
65
        $layout = null,
66
        $cover = null
67
    )
68
    {
69
        $postData = [];
70
71
        if (!empty($ids)) {
72
            $postData['ids'] = implode(',', $ids);
73
        }
74
        if($title) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $title of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
75
            $postData['title'] = $title;
76
        }
77
        if($description) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $description of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
78
            $postData['description'] = $description;
79
        }
80
        if($privacy) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $privacy of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
81
            $postData['privacy'] = $privacy;
82
        }
83
        if($layout) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $layout of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
84
            $postData['layout'] = $layout;
85
        }
86
        if($cover) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $cover of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
87
            $postData['cover'] = $cover;
88
        }
89
90
        $response = $this->httpClient->post(
91
            'album',
92
            $postData
93
        );
94
95
        $album = $this->albumMapper->buildAlbum($response->getBody()['data']);
96
        $album->setTitle($title);
97
        $album->setDescription($description);
98
        $album->setPrivacy($privacy);
99
        $album->setLayout($layout);
100
        $album->setCover($cover);
101
102
        return $album;
103
    }
104
105
    /**
106
     * Update album
107
     *
108
     * @param string $id Imgur Id of the album
109
     * @param array $ids Ids of the images you want to add to the album
110
     * @param string $title
111
     * @param string $description
112
     * @param string $privacy
113
     * @param string $layout
114
     * @param string $cover
115
     * @return bool
116
     */
117
    public function update(
118
        $id,
119
        $ids = [],
120
        $title = null,
121
        $description = null,
122
        $privacy = null,
123
        $layout = null,
124
        $cover = null
125
    )
126
    {
127
        $postData = [];
128
129
        if (!empty($ids)) {
130
            $postData['ids'] = implode(',', $ids);
131
        }
132
        if($title) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $title of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
133
            $postData['title'] = $title;
134
        }
135
        if($description) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $description of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
136
            $postData['description'] = $description;
137
        }
138
        if($privacy) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $privacy of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
139
            $postData['privacy'] = $privacy;
140
        }
141
        if($layout) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $layout of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
142
            $postData['layout'] = $layout;
143
        }
144
        if($cover) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $cover of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
145
            $postData['cover'] = $cover;
146
        }
147
148
        $response = $this->httpClient->post(
149
            'album/' . $id,
150
            $postData
151
        );
152
153
        return $response->getBody()['success'];
154
    }
155
156
    /**
157
     * Delete an album
158
     *
159
     * @param string $id Imgur Id or deletehash of the album
160
     * @return bool
161
     */
162
    public function delete($id)
163
    {
164
        $response = $this->httpClient->delete(
165
            'album/' . $id
166
        );
167
168
        return $response->getBody()['success'];
169
    }
170
171
    /**
172
     * Favorite an album
173
     *
174
     * @param string $id
175
     * @return bool
176
     */
177
    public function favorite($id)
178
    {
179
        $response = $this->httpClient->post(
180
            'album/' . $id . '/favorite'
181
        );
182
183
        return $response->getBody()['success'];
184
    }
185
186
    /**
187
     * Sets the images for an album, removes all other images and only uses the images in this request.
188
     *
189
     * @param string $id
190
     * @param array $ids
191
     * @return bool
192
     */
193 View Code Duplication
    public function setImages($id, array $ids)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
194
    {
195
        if (empty($ids)) {
196
            throw new \InvalidArgumentException('Images ids must be not empty array');
197
        }
198
199
        $postData = [];
200
        $postData['ids'] = implode(',', $ids);
201
202
        $response = $this->httpClient->post(
203
            'album/' . $id,
204
            $postData
205
        );
206
207
        return $response->getBody()['success'];
208
    }
209
210
    /**
211
     * Adds images to an album
212
     *
213
     * @param string $id
214
     * @param array $ids
215
     * @return bool
216
     */
217 View Code Duplication
    public function addImages($id, array $ids)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
218
    {
219
        if (empty($ids)) {
220
            throw new \InvalidArgumentException('Images ids must be not empty array');
221
        }
222
223
        $postData = [];
224
        $postData['ids'] = implode(',', $ids);
225
226
        $response = $this->httpClient->post(
227
            'album/' . $id . '/add',
228
            $postData
229
        );
230
231
        return $response->getBody()['success'];
232
    }
233
234
    /**
235
     * Removes images from an album
236
     *
237
     * @param string $id
238
     * @param array $ids
239
     * @return bool
240
     */
241 View Code Duplication
    public function removeImages($id, array $ids)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
242
    {
243
        if (empty($ids)) {
244
            throw new \InvalidArgumentException('Images ids must be not empty array');
245
        }
246
247
        $postData = [];
248
        $postData['ids'] = implode(',', $ids);
249
250
        $response = $this->httpClient->delete(
251
            'album/' . $id . '/remove_images',
252
            $postData
0 ignored issues
show
The call to HttpClientInterface::delete() has too many arguments starting with $postData.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
253
        );
254
255
        return $response->getBody()['success'];
256
    }
257
}