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.

src/Request.php (1 issue)

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 seregazhuk\HeadHunterApi;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Psr7\Request as GuzzleRequest;
7
8
class Request
9
{
10
    const BASE_URL = 'https://api.hh.ru/';
11
12
    /**
13
     * @var Client
14
     */
15
    protected $client;
16
17
    /**
18
     * @var array
19
     */
20
    protected $headers = [];
21
22
    /**
23
     * @var string
24
     */
25
    protected $locale = 'RU';
26
27
    /**
28
     * @var string
29
     */
30
    protected $host = 'hh.ru';
31
32
    /**
33
     * @param string $token
34
     */
35
    public function __construct($token = null)
36
    {
37
        $this->client = new Client([
38
            'base_uri'    => self::BASE_URL,
39
            'http_errors' => false,
40
        ]);
41
42
        if ($token) $this->setToken($token);
0 ignored issues
show
Bug Best Practice introduced by
The expression $token 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...
43
    }
44
45
    /**
46
     * @param string $uri
47
     * @param array $params
48
     * @return array|null
49
     */
50
    public function get($uri, $params = [])
51
    {
52
        $uri = $this->makeUriWithQuery($uri, $params);
53
54
        return $this->executeRequest('GET', $uri);
55
    }
56
57
    /**
58
     * @param string $uri
59
     * @param array $params
60
     * @return array|null
61
     */
62
    public function post($uri, $params = [])
63
    {
64
        return $this->executeRequest(
65
            'POST', $uri, ['query' => $params]
66
        );
67
    }
68
69
    /**
70
     * @param string $uri
71
     * @param array $params
72
     * @return array|null
73
     */
74
    public function postJson($uri, $params = [])
75
    {
76
        return $this->executeRequest(
77
            'POST', $uri, ['json' => $params]
78
        );
79
    }
80
81
    /**
82
     * @param string $uri
83
     * @param array $params
84
     * @return array|null
85
     */
86
    public function postFile($uri, $params = [])
87
    {
88
        return $this->executeRequest(
89
            'POST', $uri, ['multipart' => $params]
90
        );
91
    }
92
93
    /**
94
     * @param string $uri
95
     * @param array $params
96
     * @return array|null
97
     */
98
    public function put($uri, $params = [])
99
    {
100
        return $this->executeRequest(
101
            'PUT', $uri, ['query' => $params]
102
        );
103
    }
104
105
    /**
106
     * @param string $uri
107
     * @param array $params
108
     * @return array|null
109
     */
110
    public function putJson($uri, $params = [])
111
    {
112
        return $this->executeRequest(
113
            'PUT', $uri, ['json' => $params]
114
        );
115
    }
116
117
    /**
118
     * @param string $uri
119
     * @param array $params
120
     * @return array|null
121
     */
122
    public function delete($uri, $params = [])
123
    {
124
        $uri = $this->makeUriWithQuery($uri, $params);
125
126
        return $this->executeRequest('DELETE', $uri);
127
    }
128
129
    /**
130
     * @param string $method
131
     * @param string $uri
132
     * @param array $options
133
     * @return array|null
134
     */
135
    protected function executeRequest($method, $uri, array $options = [])
136
    {
137
        $request = new GuzzleRequest($method, $uri, $this->headers);
138
139
        $response = $this->client->send($request, $options);
140
141
	    return json_decode($response->getBody(), true);
142
    }
143
144
    /**
145
     * @param string $locale
146
     * @return $this
147
     */
148
    public function setLocale($locale)
149
    {
150
        $this->locale = $locale;
151
152
        return $this;
153
    }
154
155
    /**
156
     * @param $params
157
     * @return string
158
     */
159
    protected function makeQueryString($params = [])
160
    {
161
        $customOptions = [
162
            'host'   => $this->host,
163
            'locale' => $this->locale,
164
        ];
165
166
        // Merge specified params with defaults
167
        $params = array_merge(
168
            $customOptions,
169
            $params
170
        );
171
172
        return http_build_query($params);
173
    }
174
175
    /**
176
     * @param string $host
177
     * @return $this
178
     */
179
    public function setHost($host)
180
    {
181
        $this->host = $host;
182
183
        return $this;
184
    }
185
186
    /**
187
     * @param string $token
188
     * @return $this
189
     */
190
    public function setToken($token)
191
    {
192
	    $this->headers = ['Authorization' => 'Bearer ' . $token];
193
194
        return $this;
195
    }
196
197
    /**
198
     * @param string $uri
199
     * @param array $params
200
     * @return string
201
     */
202
    protected function makeUriWithQuery($uri, array $params = [])
203
    {
204
        if (!empty($params)) {
205
            $uri .= '?' . $this->makeQueryString($params);
206
        }
207
208
        return $uri;
209
    }
210
}
211