This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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 Districts 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/' . 'districts_'; |
||
45 | |||
46 | /** |
||
47 | * Returns a list of all the districts in a city. |
||
48 | * |
||
49 | * @param int $cityId |
||
50 | * @param string $lang |
||
51 | * @return Districts |
||
52 | */ |
||
53 | public function all($cityId = 1, $lang = 'A') |
||
54 | { |
||
55 | $cache = $this->file . $cityId . '_' . strtolower($lang) . '.data'; |
||
56 | |||
57 | $this->response = $this->cacheValue($cache); |
||
58 | |||
59 | View Code Duplication | if ($this->response == null) { |
|
0 ignored issues
–
show
|
|||
60 | $response = $this->_get( |
||
61 | 'v3.1/lookup/districts', |
||
62 | $lang, |
||
63 | [ |
||
64 | 'cityid' => $cityId |
||
65 | ] |
||
66 | ); |
||
67 | if ($this->config->getCache()) { |
||
68 | (!file_exists($this->cacheDir)) ? |
||
69 | mkdir($this->cacheDir, 0755, false) : ((file_exists($cache)) ? unlink($cache) : touch($cache)); |
||
70 | file_put_contents($cache, serialize($response)); |
||
71 | } |
||
72 | $this->response = $response; |
||
73 | } |
||
74 | |||
75 | return $this; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Returns a the response. |
||
80 | * |
||
81 | * @return array |
||
82 | */ |
||
83 | public function get() |
||
84 | { |
||
85 | $this->check(); |
||
86 | |||
87 | return $this->response['Districts']; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Returns a specific district from a city by ID. |
||
92 | * |
||
93 | * @param int $districtId |
||
94 | * @return array |
||
95 | */ |
||
96 | View Code Duplication | public function getId(int $districtId) |
|
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. ![]() |
|||
97 | { |
||
98 | $this->check(); |
||
99 | |||
100 | $key = array_search($districtId, array_column($this->response['Districts'], 'Id')); |
||
101 | |||
102 | return $this->response['Districts'][$key]; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Returns a specific district from a city by ID. |
||
107 | * |
||
108 | * @param int $districtId |
||
109 | * @return array |
||
110 | */ |
||
111 | public function byId(int $districtId) |
||
112 | { |
||
113 | return $this->getId($districtId); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Returns a specific district from a city by ID. |
||
118 | * |
||
119 | * @param int $districtId |
||
120 | * @return array |
||
121 | */ |
||
122 | public function id(int $districtId) |
||
123 | { |
||
124 | return $this->getId($districtId); |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * Returns a certian district from a city by name. |
||
129 | * |
||
130 | * @param string $districtName |
||
131 | * @return array |
||
132 | */ |
||
133 | View Code Duplication | public function getName($districtName) |
|
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. ![]() |
|||
134 | { |
||
135 | $this->check(); |
||
136 | |||
137 | $key = array_search($districtName, array_column($this->response['Districts'], 'Name')); |
||
138 | |||
139 | return $this->response[$key]; |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * Returns a certian district from a city by name. |
||
144 | * |
||
145 | * @param string $districtName |
||
146 | * @return array |
||
147 | */ |
||
148 | public function byName($districtName) |
||
149 | { |
||
150 | return $this->getName($districtName); |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * Returns a certian district from a city by name. |
||
155 | * |
||
156 | * @param string $districtName |
||
157 | * @return array |
||
158 | */ |
||
159 | public function named($districtName) |
||
160 | { |
||
161 | return $this->getName($districtName); |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * Returns a certian district from a city by name. |
||
166 | * |
||
167 | * @param string $districtName |
||
168 | * @return array |
||
169 | */ |
||
170 | public function districtName($districtName) |
||
171 | { |
||
172 | return $this->getName($districtName); |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * Check if all() method was called first. |
||
177 | * |
||
178 | * @return void |
||
179 | * @throws \BadMethodCallException |
||
180 | */ |
||
181 | protected function check() |
||
182 | { |
||
183 | if ($this->response == null) { |
||
184 | throw new \BadMethodCallException("You need to call all() method first."); |
||
185 | } |
||
186 | } |
||
187 | } |
||
188 |
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.