Issues (58)

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/Adapters/GuzzleHttpAdapter.php (13 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
/*
4
 * This file is part of Laravel SMSFactor.
5
 *
6
 * (c) Filippo Galante <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace IlGala\SMSFactor\Adapters;
13
14
use GuzzleHttp\Client;
15
use GuzzleHttp\ClientInterface;
16
use GuzzleHttp\Exception\RequestException;
17
use GuzzleHttp\Message\ResponseInterface;
18
use GuzzleHttp\Psr7\Response;
19
use IlGala\SMSFactor\Exceptions\HttpException;
20
21
/**
22
 * @author Filippo Galante <[email protected]>
23
 */
24
class GuzzleHttpAdapter implements AdapterInterface
25
{
26
27
    /**
28
     * @var ClientInterface
29
     */
30
    protected $client;
31
32
    /**
33
     * @var Response|ResponseInterface
34
     */
35
    protected $response;
36
37
    /**
38
     * @param string               $username
39
     * @param string               $password
40
     * @param string               $accept
41
     * @param ClientInterface|null $client
42
     */
43
    public function __construct($username, $password, $accept, ClientInterface $client = null)
44
    {
45
        if (version_compare(ClientInterface::VERSION, '6') === 1) {
46
            $this->client = $client ?: new Client(['headers' => [
47
                    'sfusername' => $username,
48
                    'sfpassword' => $password,
49
                    'Accept' => $accept
50
            ]]);
51
        } else {
52
            $this->client = $client ?: new Client();
53
            $this->client->setDefaultOption('headers/sfusername', $username);
0 ignored issues
show
The method setDefaultOption() does not seem to exist on object<GuzzleHttp\ClientInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
            $this->client->setDefaultOption('headers/sfpassword', $password);
0 ignored issues
show
The method setDefaultOption() does not seem to exist on object<GuzzleHttp\ClientInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
            $this->client->setDefaultOption('headers/Accept', $accept);
0 ignored issues
show
The method setDefaultOption() does not seem to exist on object<GuzzleHttp\ClientInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
        }
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 View Code Duplication
    public function get($url)
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...
63
    {
64
        try {
65
            $this->response = $this->client->get($url);
66
        } catch (RequestException $e) {
67
            $this->response = $e->getResponse();
0 ignored issues
show
Documentation Bug introduced by
It seems like $e->getResponse() can also be of type object<Psr\Http\Message\ResponseInterface>. However, the property $response is declared as type object<GuzzleHttp\Psr7\R...sage\ResponseInterface>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
68
            $this->handleError();
69
        }
70
        return $this->response->getBody();
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76 View Code Duplication
    public function delete($url)
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...
77
    {
78
        try {
79
            $this->response = $this->client->delete($url);
80
        } catch (RequestException $e) {
81
            $this->response = $e->getResponse();
0 ignored issues
show
Documentation Bug introduced by
It seems like $e->getResponse() can also be of type object<Psr\Http\Message\ResponseInterface>. However, the property $response is declared as type object<GuzzleHttp\Psr7\R...sage\ResponseInterface>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
82
            $this->handleError();
83
        }
84
        return $this->response->getBody();
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90 View Code Duplication
    public function put($url, $content = '')
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...
91
    {
92
        $options = [];
93
        $options[is_array($content) ? 'json' : 'body'] = $content;
94
        try {
95
            $this->response = $this->client->put($url, $options);
96
        } catch (RequestException $e) {
97
            $this->response = $e->getResponse();
0 ignored issues
show
Documentation Bug introduced by
It seems like $e->getResponse() can also be of type object<Psr\Http\Message\ResponseInterface>. However, the property $response is declared as type object<GuzzleHttp\Psr7\R...sage\ResponseInterface>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
98
            $this->handleError();
99
        }
100
        return $this->response->getBody();
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106 View Code Duplication
    public function post($url, $content = '')
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...
107
    {
108
        $options = [];
109
        $options[is_array($content) ? 'json' : 'body'] = $content;
110
        try {
111
            $this->response = $this->client->post($url, $options);
112
        } catch (RequestException $e) {
113
            $this->response = $e->getResponse();
0 ignored issues
show
Documentation Bug introduced by
It seems like $e->getResponse() can also be of type object<Psr\Http\Message\ResponseInterface>. However, the property $response is declared as type object<GuzzleHttp\Psr7\R...sage\ResponseInterface>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
114
            $this->handleError();
115
        }
116
        return $this->response->getBody();
117
    }
118
119
    /**
120
     * {@inheritdoc}
121
     */
122 View Code Duplication
    public function getLatestResponseHeaders()
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...
123
    {
124
        if (null === $this->response) {
125
            return;
126
        }
127
        return [
128
            'reset' => (int) (string) $this->response->getHeader('RateLimit-Reset'),
129
            'remaining' => (int) (string) $this->response->getHeader('RateLimit-Remaining'),
130
            'limit' => (int) (string) $this->response->getHeader('RateLimit-Limit'),
131
        ];
132
    }
133
134
    /**
135
     * @throws HttpException
136
     */
137 View Code Duplication
    protected function handleError()
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...
138
    {
139
        $body = (string) $this->response->getBody();
140
        $code = (int) $this->response->getStatusCode();
141
        $content = json_decode($body);
142
        throw new HttpException(isset($content->message) ? $content->message : 'Request not processed.', $code);
143
    }
144
}
145