Issues (21)

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/Client.php (1 issue)

Labels
Severity

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 JulianoBailao\DomusApi;
4
5
use JulianoBailao\DomusApi\Core\Request;
6
use JulianoBailao\DomusApi\Exception\InvalidApiEndPointException;
7
use JulianoBailao\DomusApi\Exception\InvalidHostException;
8
9
class Client
10
{
11
    /**
12
     * The api host.
13
     *
14
     * @var string
15
     */
16
    protected $host;
17
18
    /**
19
     * The api port.
20
     *
21
     * @var string
22
     */
23
    protected $port;
24
25
    /**
26
     * Api usernamename / email.
27
     *
28
     * @var string
29
     */
30
    protected $username;
31
32
    /**
33
     * Api username password.
34
     *
35
     * @var string
36
     */
37
    protected $password;
38
39
    /**
40
     * Api authentication token.
41
     *
42
     * @var string
43
     */
44
    protected $token;
45
46
    /**
47
     * Domus branch id to login.
48
     *
49
     * @var int
50
     */
51
    protected $branchId;
52
53
    /**
54
     * The api client handler.
55
     *
56
     * @var mixed
57
     */
58
    protected $handler;
59
60
    /**
61
     * Create a new api client instance.
62
     *
63
     * @param string $host
64
     * @param string $port
65
     * @param string $username
66
     * @param string $password
67
     *
68
     * @throws InvalidHostException
69
     */
70 138
    public function __construct($host, $port, $username, $password)
71
    {
72 138
        $this->host = $host;
73 138
        $this->port = $port;
74 138
        $this->username = $username;
75 138
        $this->password = $password;
76 138
    }
77
78
    /**
79
     * Get the api uthetication token.
80
     *
81
     * @return string
82
     */
83 132
    public function getToken()
84
    {
85 132
        if ($this->token == null) {
86 132
            $this->auth();
87 132
        }
88
89 132
        return $this->token;
90
    }
91
92
    /**
93
     * Api authentication.
94
     *
95
     * @return self
96
     */
97 132
    protected function auth()
98
    {
99 132
        $request = new Request($this->handler);
100 132
        $this->token = $request->run('POST', $this->makeUrl('pedidovenda-rest/auth'), ['json' => [
101 132
            'login'    => $this->username,
102 132
            'password' => $this->password,
103 132
        ]])->token;
104
105 132
        return $this;
106
    }
107
108
    /**
109
     * Set the branch of endpoint operation.
110
     *
111
     * @param int $branchId
112
     *
113
     * @return self
114
     */
115 129
    public function setBranch($branchId)
116
    {
117 129
        $request = new Request($this->handler);
118 129
        $this->branchId = $request->run('PUT', $this->makeUrl('pedidovenda-rest/auth'), [
119
            'json' => [
120 129
                'id' => $branchId,
121 129
            ],
122
            'headers' => [
123 129
                'X-Session-ID' => $this->getToken(),
124 129
            ],
125 129
        ])->id;
126
127 129
        return $this;
128
    }
129
130
    /**
131
     * Make the endpoint full url.
132
     *
133
     * @param string $endpoint
134
     *
135
     * @return string
136
     */
137 135
    public function makeUrl($endpoint)
138
    {
139 135
        $host = rtrim(str_replace(['http://', 'https://'], null, $this->host), '/');
140 135
        $endpoint = ltrim($endpoint, '/');
141
142 135
        return $host.':'.$this->port.'/'.$endpoint;
143
    }
144
145
    /**
146
     * Sets the client handler.
147
     *
148
     * @param mixed $handler
149
     */
150 132
    public function setHandler($handler)
151
    {
152 132
        $this->handler = $handler;
153 132
    }
154
155
    /**
156
     * Gets the client handler.
157
     *
158
     * @param mixed $handler
0 ignored issues
show
There is no parameter named $handler. 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...
159
     */
160 126
    public function getHandler()
161
    {
162 126
        return $this->handler;
163
    }
164
165
    /**
166
     * Get the branch id.
167
     *
168
     * @return int
169
     */
170 3
    public function getBranchId()
171
    {
172 3
        return $this->branchId;
173
    }
174
175
    /**
176
     * Call a dinamyc api endpoint.
177
     *
178
     * @param string $method
179
     * @param array  $args
180
     *
181
     * @throws InvalidApiEndPointException
182
     *
183
     * @return mixed
184
     */
185 126
    public function __call($method, array $args)
186
    {
187 126
        $class = 'JulianoBailao\DomusApi\Endpoints\\'.ucfirst(strtolower($method));
188 126
        array_unshift($args, $this);
189
190 126
        return call_user_func_array([new \ReflectionClass($class), 'newInstance'], $args);
191
    }
192
}
193