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/Image.php (6 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\ImageInterface;
6
use Mechpave\ImgurClient\Http\HttpClientInterface;
7
use Mechpave\ImgurClient\Mapper\ImageMapper;
8
use Mechpave\ImgurClient\Model\ImageModel;
9
10
/**
11
 * Class Image
12
 * @package Mechpave\ImgurClient\Api
13
 * @see http://api.imgur.com/endpoints/image
14
 */
15
class Image extends AbstractApi
16
{
17
    /**
18
     * @var ImageMapper
19
     */
20
    protected $imageMapper;
21
22
    /**
23
     * Image constructor.
24
     * @param HttpClientInterface $httpClient
25
     * @param ImageMapper $imageMapper
26
     */
27
    public function __construct(HttpClientInterface $httpClient, ImageMapper $imageMapper)
28
    {
29
        parent::__construct($httpClient);
30
        $this->imageMapper = $imageMapper;
31
    }
32
33
    /**
34
     * Get image Information endpoint
35
     *
36
     * @param $id
37
     * @return ImageInterface
38
     */
39
    public function get($id)
40
    {
41
        $response = $this->httpClient->get(
42
            'image/' . $id
43
        );
44
45
        $image = $this->imageMapper->buildImage($response->getBody()['data']);
46
47
        return $image;
48
    }
49
50
    /**
51
     * Upload Image to Imgur
52
     *
53
     * @param string $image A binary file (path to file), base64 data, or a URL for an image. (up to 10MB)
54
     * @param string $type Image type. Use Mechpave\ImgurClient\Model\ImageModel
55
     * @param string $title The title of the image
56
     * @param string $description The description of the image
57
     * @param string $album The id of the album you want to add the image to. For anonymous albums, {album} should be the deletehash that is returned at creation.
58
     * @param string $name The name of the file
59
     * @throws \UnexpectedValueException
60
     * @return ImageInterface
61
     */
62
    public function upload(
63
        $image,
64
        $type,
65
        $title = null,
66
        $description = null,
67
        $album = null,
68
        $name = null
69
    )
70
    {
71
        if ($type == ImageModel::TYPE_FILE) {
72
            //check if file exists and get its contents
73
74
            if (!file_exists($image)) {
75
                throw new \UnexpectedValueException('Provided file does not exist');
76
            }
77
78
            $contents = file_get_contents($image);
79
            if (!$contents) {
80
                throw new \UnexpectedValueException('Could not get file contents');
81
            }
82
83
            $image = $contents;
84
        }
85
86
        $postData = [
87
            'image' => $image,
88
            'type' => $type,
89
        ];
90
91
        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...
92
            $postData['title'] = $title;
93
        }
94
        if ($name) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $name 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...
95
            $postData['name'] = $name;
96
        }
97
        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...
98
            $postData['description'] = $description;
99
        }
100
        if ($album) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $album 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...
101
            $postData['album'] = $album;
102
        }
103
104
        $response = $this->httpClient->post(
105
            'image',
106
            $postData
107
        );
108
109
        $image = $this->imageMapper->buildImage($response->getBody()['data']);
110
111
        return $image;
112
    }
113
114
    /**
115
     * Update uploaded image. You can only update title or description of the image
116
     *
117
     * @param string $id Imgur Id of the image. For anonymous image it must be deleteHash
118
     * @param string $title The title of the image.
119
     * @param string $description The description of the image
120
     * @return bool
121
     */
122
    public function update(
123
        $id,
124
        $title = null,
125
        $description = null
126
    )
127
    {
128
        $postData = [];
129
130
        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...
131
            $postData['title'] = $title;
132
        }
133
        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...
134
            $postData['description'] = $description;
135
        }
136
137
        $response = $this->httpClient->post(
138
            'image/' . $id,
139
            $postData
140
        );
141
142
        return $response->getBody()['success'];
143
    }
144
145
    /**
146
     * Delete image from Imgur
147
     *
148
     * @param string $id Imgur Id of the image. For anonymous image it must be deleteHash
149
     * @return bool
150
     */
151
    public function delete($id)
152
    {
153
        $response = $this->httpClient->delete(
154
            'image/' . $id
155
        );
156
157
        return $response->getBody()['success'];
158
    }
159
160
    /**
161
     * Favorite an image with the given ID. The user is required to be logged in to favorite the image.
162
     *
163
     * @param string $id Imgur Id of the image.
164
     * @return bool
165
     */
166
    public function favorite($id)
167
    {
168
        $response = $this->httpClient->post(
169
            'image/' . $id . '/favorite'
170
        );
171
172
        return $response->getBody()['success'];
173
    }
174
}