Issues (14)

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/Services.php (4 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
 * Part of the Saudi Address API PHP package.
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * Licensed under the MIT.
9
 *
10
 * This source file is subject to the MIT License that is
11
 * bundled with this package in the LICENSE file.
12
 *
13
 * @package    Saudi Address
14
 * @version    1.3
15
 * @author     Ali Alharthi
16
 * @license    MIT
17
 * @copyright  (c) 2020, Ali Alharthi
18
 * @link       https://aalharthi.sa
19
 */
20
21
namespace AliAlharthi\SaudiAddress\Api;
22
23
class Services extends Api
24
{
25
    /**
26
     * The response array.
27
     *
28
     * @var array|null
29
     */
30
    protected $response = null;
31
32
    /**
33
     * The cache directory.
34
     *
35
     * @var string|null
36
     */
37
    protected $cacheDir = __DIR__ . '/cache/';
38
39
    /**
40
     * The cache file name.
41
     *
42
     * @var string|null
43
     */
44
    protected $file = __DIR__ . '/cache/' . 'services_';
45
46
    /**
47
     * Returns a list of all the services categories.
48
     *
49
     * @param   string  $lang
50
     * @return  Services
51
     */
52
    public function categories($lang = 'A')
53
    {
54
55
        $cache = $this->file . 'categories_' . strtolower($lang) . '.data';
56
57
        $this->response = $this->cacheValue($cache);
58
59 View Code Duplication
        if ($this->response == null) {
0 ignored issues
show
This code seems to be duplicated across 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...
60
            $response = $this->_get(
61
                'v3.1/lookup/service-categories',
62
                $lang
63
            );
64
            if($response['success'] == false){
65
                return ;
66
            }
67
            if($this->config->getCache()){
68
                (!file_exists($this->cacheDir)) ?
69
                    mkdir($this->cacheDir, 0777, false) : ((file_exists($cache)) ? unlink($cache) : touch($cache));
70
                file_put_contents($cache, serialize($response['ServiceCategories']));
71
            }
72
            $this->response = $response['ServiceCategories'];
73
        }
74
75
        return $this;
76
    }
77
78
    /**
79
     * Returns a list of all the services categories.
80
     *
81
     * @param   string  $lang
82
     * @return  array
83
     */
84
    public function main($lang = 'A')
85
    {
86
        return $this->categories($lang);
87
    }
88
89
    /**
90
     * Returns a list of all the services categories.
91
     *
92
     * @param   string  $lang
93
     * @return  array
94
     */
95
    public function cat($lang = 'A')
96
    {
97
        return $this->categories($lang);
98
    }
99
100
    /**
101
     * Returns a list of all the sub services of a service.
102
     *
103
     * @param   int     $serviceId
104
     * @param   string  $lang
105
     * @return  Services
106
     */
107
    public function sub(int $serviceId = 1, $lang = 'A')
108
    {
109
        $cache = $this->file . 'sub_' . $serviceId . '_' . strtolower($lang) . '.data';
110
111
        $this->response = $this->cacheValue($cache);
112
113 View Code Duplication
        if ($this->config->getCache() && $this->response == null) {
0 ignored issues
show
This code seems to be duplicated across 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...
114
            $response = $this->_get(
115
                'v3.1/lookup/services-sub-categories',
116
                $lang,
117
                [
118
                    'servicecategoryid' => $serviceId
119
                ]
120
            );
121
            if ($response['success'] == false) {
122
                return;
123
            }
124
            if($this->config->getCache()){
125
                (!file_exists($this->cacheDir)) ?
126
                    mkdir($this->cacheDir, 0777, false) : ((file_exists($cache)) ? unlink($cache) : touch($cache));
127
                file_put_contents($cache, serialize($response['ServiceSubCategories']));
128
            }
129
            $this->response = $response['ServiceSubCategories'];
130
        }
131
132
        return $this;
133
    }
134
135
    /**
136
     * Returns a list of all the sub services of a service.
137
     *
138
     * @param   int     $serviceId
139
     * @param   string  $lang
140
     * @return  array
141
     */
142
    public function subCategories(int $serviceId = 1, $lang = 'A')
143
    {
144
        $this->sub($serviceId, $lang);
145
    }
146
147
    /**
148
     * Returns a list of all the sub services of a service.
149
     *
150
     * @param   int     $serviceId
151
     * @param   string  $lang
152
     * @return  array
153
     */
154
    public function subServices(int $serviceId = 1, $lang = 'A')
155
    {
156
        $this->sub($serviceId, $lang);
157
    }
158
159
    /**
160
     * Returns a the response.
161
     *
162
     * @return  array
163
     */
164
    public function get()
165
    {
166
        $this->check();
167
168
        return $this->response;
169
    }
170
171
    /**
172
     * Returns a specific service by id.
173
     *
174
     * @param   int     $serviceId
175
     * @return  array
176
     */
177 View Code Duplication
    public function getId(int $serviceId)
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...
178
    {
179
        $this->check();
180
181
        $key = array_search($serviceId, array_column($this->response, 'Id'));
182
183
        return $this->response[$key];
184
    }
185
186
    /**
187
     * Returns a specific service by id.
188
     *
189
     * @param   int     $serviceId
190
     * @return  array
191
     */
192
    public function byId(int $serviceId)
193
    {
194
        return $this->getId($serviceId);
195
    }
196
197
    /**
198
     * Returns a specific service by id.
199
     *
200
     * @param   int     $serviceId
201
     * @return  array
202
     */
203
    public function id(int $serviceId)
204
    {
205
        return $this->getId($serviceId);
206
    }
207
208
    /**
209
     * Returns a specific service by name.
210
     *
211
     * @param   string  $serviceName
212
     * @return  array
213
     */
214 View Code Duplication
    public function getName($serviceName)
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...
215
    {
216
        $this->check();
217
218
        $key = array_search($serviceName, array_column($this->response, 'Name'));
219
220
        return $this->response[$key];
221
    }
222
223
    /**
224
     * Returns a specific service by name.
225
     *
226
     * @param   string  $serviceName
227
     * @return  array
228
     */
229
    public function byName($serviceName)
230
    {
231
        return $this->getName($serviceName);
232
    }
233
234
    /**
235
     * Returns a specific service by name.
236
     *
237
     * @param   string  $serviceName
238
     * @return  array
239
     */
240
    public function named($serviceName)
241
    {
242
        return $this->getName($serviceName);
243
    }
244
245
    /**
246
     * Returns a specific service by name.
247
     *
248
     * @param   string  $serviceName
249
     * @return  array
250
     */
251
    public function serviceName($serviceName)
252
    {
253
        return $this->getName($serviceName);
254
    }
255
256
    /**
257
     * Check if all() method was called first.
258
     *
259
     * @return  void
260
     * @throws  \BadMethodCallException
261
     */
262
    protected function check()
263
    {
264
        if ($this->response == null) {
265
            throw new \BadMethodCallException("You need to call categories() or sub() methods first.");
266
        }
267
    }
268
}
269