Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
20 | class JCFirebase |
||
21 | { |
||
22 | public $firebaseURI; |
||
23 | |||
24 | public $rootPath; |
||
25 | |||
26 | /** |
||
27 | * @var array |
||
28 | */ |
||
29 | public $requestHeader = array( |
||
30 | 'accept' => 'application/json', |
||
31 | 'contentType' => 'application/json; charset=utf-8', |
||
32 | 'dataType' => 'json' |
||
33 | ); |
||
34 | |||
35 | public $requestOptions = array(); |
||
36 | |||
37 | /** |
||
38 | * @var OAuth |
||
39 | */ |
||
40 | public $auth; |
||
41 | |||
42 | public $client; |
||
43 | |||
44 | /** |
||
45 | * JCFirebase constructor. |
||
46 | * |
||
47 | * @param $firebaseURI |
||
48 | * @param OAuth $auth |
||
49 | * @param string $rootPath |
||
50 | */ |
||
51 | public function __construct($firebaseURI, OAuth $auth, $rootPath = '/') |
||
58 | |||
59 | |||
60 | /** |
||
61 | * @param $firebaseURI |
||
62 | * @param $jsonString |
||
63 | * @param string $rootPath |
||
64 | * @return JCFirebase |
||
65 | * @throws \Exception |
||
66 | */ |
||
67 | public static function fromJson($firebaseURI, $jsonString, $rootPath = '/') |
||
71 | |||
72 | /** |
||
73 | * @param $firebaseURI |
||
74 | * @param $keyFile |
||
75 | * @param string $rootPath |
||
76 | * |
||
77 | * @return JCFirebase |
||
78 | * @throws \Exception |
||
79 | */ |
||
80 | public static function fromKeyFile($firebaseURI, $keyFile, $rootPath = '/') |
||
84 | 14 | ||
85 | public function getPathURI($path = '', $print = '') |
||
122 | 1 | ||
123 | public function getShallow($path = '', $options = array()) |
||
133 | |||
134 | /** |
||
135 | * @param string $path |
||
136 | * @param array $options |
||
137 | * |
||
138 | * @return JCResponseInterface |
||
139 | 8 | */ |
|
140 | public function get($path = '', $options = array()) |
||
148 | |||
149 | /** |
||
150 | * @param string $path |
||
151 | * @param array $options |
||
152 | * |
||
153 | * @return JCResponseInterface |
||
154 | 7 | */ |
|
155 | View Code Duplication | public function put($path = '', $options = array()) |
|
162 | |||
163 | /** |
||
164 | * @param string $path |
||
165 | * @param array $options |
||
166 | * |
||
167 | * @return JCResponseInterface |
||
168 | 5 | */ |
|
169 | View Code Duplication | public function post($path = '', $options = array()) |
|
177 | |||
178 | /** |
||
179 | * @param string $path |
||
180 | * @param array $options |
||
181 | * |
||
182 | * @return JCResponseInterface |
||
183 | 1 | */ |
|
184 | View Code Duplication | public function patch($path = '', $options = array()) |
|
192 | |||
193 | /** |
||
194 | * @param string $path |
||
195 | * @param array $options |
||
196 | * |
||
197 | * @return JCResponseInterface |
||
198 | 2 | */ |
|
199 | public function delete($path = '', $options = array()) |
||
207 | |||
208 | /** |
||
209 | * Function that check firebase authencation |
||
210 | * and configuration valid or not |
||
211 | * |
||
212 | * @return bool |
||
213 | 1 | */ |
|
214 | public function isValid() |
||
220 | 14 | ||
221 | protected function refreshToken() |
||
225 | 8 | ||
226 | protected function addDataToPathURI($path = '', $options = array(), $reqType = RequestType::GET) |
||
235 | 13 | ||
236 | protected function addDataToRequest($options = array(), $jsonEncode = false) |
||
250 | } |
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.