GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 7f01d7...1527b5 )
by Oleg
02:36
created

Route::deleteRoutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
namespace Route4Me;
3
4
use Route4Me\Common;
5
use Route4Me\Address;
6
use Route4Me\RouteParameters;
7
use Route4Me\Route4Me;
8
use Route4Me\Enum\Endpoint;
9
10
class Route extends Common
11
{
12
    public $route_id;
13
    public $member_id;
14
    public $route_destination_id;
15
    public $optimization_problem_id;
16
    public $vehicle_alias;
17
    public $driver_alias;
18
    public $trip_distance;
19
    public $mpg;
20
    public $gas_price;
21
    public $route_duration_sec;
22
    public $destination_count;
23
    public $parameters;
24
    public $addresses = array();
25
    public $links = array();
26
    public $directions = array();
27
    public $path = array();
28
    public $tracking_history = array();
29
    public $recipient_email;
30
    public $httpheaders;
31
    public $is_unrouted;
32
    public $time;
33
    
34
    public $dev_lat;
35
    public $dev_lng;
36
    
37
    public $user_route_rating;
38
    public $member_email;
39
    public $member_first_name;
40
    public $member_last_name;
41
    public $channel_name;
42
    public $route_cost;
43
    public $route_revenue;
44
    public $net_revenue_per_distance_unit;
45
    public $created_timestamp;
46
    public $planned_total_route_duration;
47
    public $actual_travel_distance;
48
    public $actual_travel_time;
49
    public $actual_footsteps;
50
    public $working_time;
51
    public $driving_time;
52
    public $idling_time;
53
    public $paying_miles;
54
    public $geofence_polygon_type;
55
    public $geofence_polygon_size;
56
    public $notes;
57
    public $member_config_storage;
58
59
    public static function fromArray(array $params) 
60
    {
61
        $route = new Route();
62
        $route->route_id                = Common::getValue($params, 'route_id');
63
        $route->member_id               = Common::getValue($params, 'member_id');
64
        $route->optimization_problem_id = Common::getValue($params, 'optimization_problem_id');
65
        $route->vehicle_alias           = Common::getValue($params, 'vehicle_alias');
66
        $route->driver_alias            = Common::getValue($params, 'driver_alias');
67
        $route->trip_distance           = Common::getValue($params, 'trip_distance');
68
        $route->mpg                     = Common::getValue($params, 'mpg');
69
        $route->gas_price               = Common::getValue($params, 'gas_price');
70
        $route->route_duration_sec      = Common::getvalue($params, 'route_duration_sec');
71
        $route->destination_count       = Common::getvalue($params, 'destination_count');
72
        $route->is_unrouted             = Common::getvalue($params, 'is_unrouted');
73
74
        // Make RouteParameters
75
        if (isset($params['parameters'])) {
76
            $route->parameters = RouteParameters::fromArray($params['parameters']);
77
        }
78
79 View Code Duplication
        if (isset($params['addresses'])) {
0 ignored issues
show
Duplication introduced by
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...
80
            $addresses = array();
81
            foreach ($params['addresses'] as $address) {
82
                $addresses[] = Address::fromArray($address);
83
            }
84
85
            $route->addresses = $addresses;
86
        }
87
88
        $route->links            = Common::getValue($params, 'links', array());
89
        $route->directions       = Common::getValue($params, 'directions', array());
90
        $route->path             = Common::getValue($params, 'path', array());
91
        $route->tracking_history = Common::getValue($params, 'tracking_history', array());
92
93
        return $route;
94
    }
95
96 View Code Duplication
    public static function getRoutes($params = null)
0 ignored issues
show
Duplication introduced by
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...
97
    {
98
        $allQueryFields = array('route_id', 'route_path_output', 'query', 'directions', 'device_tracking_history', 'limit', 'offset');
99
        
100
        $result = Route4Me::makeRequst(array(
101
            'url'    => Endpoint::ROUTE_V4,
102
            'method' => 'GET',
103
            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params)
104
        ));
105
106
        if (isset($params['route_id'])) {
107
            return Route::fromArray($result); die("");
0 ignored issues
show
Unused Code introduced by
die(''); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
108
        } else {
109
            $routes = array();
110
            foreach ($result as $route) {
111
                $routes[] = Route::fromArray($route);
112
            }
113
            return $routes;
114
        }
115
    }
116
117 View Code Duplication
    public function getRoutePoints($params)
0 ignored issues
show
Duplication introduced by
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...
118
    {
119
        $allQueryFields = array('route_id', 'route_path_output', 'compress_path_points', 'directions');
120
        
121
        $result = Route4Me::makeRequst(array(
122
            'url'    => Endpoint::ROUTE_V4,
123
            'method' => 'GET',
124
            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params)
125
        ));
126
127
        return $result;
128
    }
129
130 View Code Duplication
    public function duplicateRoute($route_id)
0 ignored issues
show
Duplication introduced by
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...
131
    {
132
        $result = Route4Me::makeRequst(array(
133
            'url'    => Endpoint::ROUTE_DUPLICATE,
134
            'method' => 'GET',
135
            'query'  => array(
136
                'route_id' => $route_id,
137
                'to'       => 'none',
138
            )
139
        ));
140
        
141
        return $result;
142
    }
143
    
144 View Code Duplication
    public function resequenceRoute($params)
0 ignored issues
show
Duplication introduced by
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...
145
    {
146
        $allQueryFields = array('route_id', 'route_destination_id');
147
        $allBodyFields = array('addresses');
148
        
149
        $result = Route4Me::makeRequst(array(
150
            'url'    => Endpoint::ROUTE_V4,
151
            'method' => 'PUT',
152
            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
153
            'body'   => Route4Me::generateRequestParameters($allBodyFields, $params)
154
        ));
155
        
156
        return $result;
157
    }
158
    
159
    public function resequenceAllAddresses($params)
160
    {
161
        $allQueryFields = array('route_id', 'disable_optimization', 'optimize');
162
        
163
        $result = Route4Me::makeRequst(array(
164
            'url'    => Endpoint::REOPTIMIZE_V3_2,
165
            'method' => 'GET',
166
            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params)
167
        ));
168
        
169
        return $result;
170
    }
171
172 View Code Duplication
    public function mergeRoutes($params)
0 ignored issues
show
Duplication introduced by
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...
173
    {
174
        $allBodyFields = array('route_ids', 'depot_address', 'remove_origin', 'depot_lat',  'depot_lng');
175
        
176
        $result = Route4Me::makeRequst(array(
177
            'url'    => Endpoint::ROUTES_MERGE,
178
            'method' => 'POST',
179
            'body'   => Route4Me::generateRequestParameters($allBodyFields, $params),
180
            'HTTPHEADER'  => 'Content-Type: multipart/form-data'
181
        ));
182
        
183
        return $result;
184
    }
185
    
186 View Code Duplication
    public function shareRoute($params)
0 ignored issues
show
Duplication introduced by
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...
187
    {
188
        $allQueryFields = array('route_id', 'response_format');
189
        $allBodyFields = array('recipient_email');
190
        
191
        $result = Route4Me::makeRequst(array(
192
            'url'    => Endpoint::ROUTE_SHARE,
193
            'method' => 'POST',
194
            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
195
            'body'   => Route4Me::generateRequestParameters($allBodyFields, $params),
196
            'HTTPHEADER'  => 'Content-Type: multipart/form-data'
197
        ));
198
        
199
        return $result;
200
    }
201
    
202
    // Returns random route_id from existing routes between $offset and $offset+$limit
203
    public function getRandomRouteId($offset, $limit)
204
    {
205
        $params = array(
206
            'offset' => !is_null($offset) ? $offset : 0,
207
            'limit'  => !is_null($limit) ? $limit : 30
208
        );
209
        
210
        $routes = $this->getRoutes($params);
211
        
212
        if (is_null($routes) || sizeof($routes)<1) {
213
            echo "<br> There are no routes in the account. Please, create the routes first. <br>";
214
            return null;
215
        } 
216
        
217
        $randomIndex = rand(0, sizeof($routes) - 1);
218
        
219
        return $routes[$randomIndex]->route_id;
220
    }
221
222
    public function update()
223
    {
224
        $route = Route4Me::makeRequst(array(
225
            'url'    => Endpoint::ROUTE_V4,
226
            'method' => 'PUT',
227
            'query'  => array(
228
                'route_id'  => isset($this->route_id) ? $this->route_id : null
229
            ),
230
            'body' => array(
231
                'parameters' => $this->parameters,
232
                ),
233
            'HTTPHEADER'  => isset($this->httpheaders) ? $this->httpheaders : null,
234
        ));
235
236
        return Route::fromArray($route);
237
    }
238
    
239
    public function updateAddress($address = null)
0 ignored issues
show
Unused Code introduced by
The parameter $address is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
240
    {
241
        $body = sizeof($this->addresses)<1 ? get_object_vars($this->parameters) 
242
            : (isset($this->addresses[0]) ? $this->addresses[0] : get_object_vars($this->parameters));
243
244
        $result = Route4Me::makeRequst(array(
245
            'url'    => Endpoint::ADDRESS_V4,
246
            'method' => 'PUT',
247
            'query'  => array(
248
                'route_id'             => isset($this->route_id) ? $this->route_id : null,
249
                'route_destination_id' => isset($this->route_destination_id) ? $this->route_destination_id : null,
250
            ),
251
            'body'        => $body,
252
            'HTTPHEADER'  => isset($this->httpheaders) ? $this->httpheaders : null,
253
        ));
254
255
        return $result;
256
    }
257
258
    public function updateRouteAddress()
259
    {
260
        $result = Route4Me::makeRequst(array(
261
            'url'    => Endpoint::ADDRESS_V4,
262
            'method' => 'PUT',
263
            'query'  => array(
264
                'route_id'             => isset($this->route_id) ? $this->route_id : null,
265
                'route_destination_id' => isset($this->route_destination_id) ? $this->route_destination_id : null,
266
            ),
267
            'body'        => array(
268
                "parameters" => isset($this->parameters) ? get_object_vars($this->parameters) : null,
269
                "addresses"  => isset($this->addresses) ? $this->addresses : null
270
            ),
271
            'HTTPHEADER'  => isset($this->httpheaders) ? $this->httpheaders : null,
272
        ));
273
274
        return $result;
275
    }
276
277
    public function addAddresses($params)
278
    {
279
        $allQueryFields = array('route_id');
280
        $allBodyFields = array('addresses');
281
        
282
        $route = Route4Me::makeRequst(array(
283
            'url'    => Endpoint::ROUTE_V4,
284
            'method' => 'PUT',
285
            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
286
            'body'   => Route4Me::generateRequestParameters($allBodyFields, $params),
287
            'HTTPHEADER'  => isset($this->httpheaders) ? $this->httpheaders : null,
288
        ));
289
290
        return Route::fromArray($route);
291
    }
292
    
293 View Code Duplication
    public function insertAddressOptimalPosition(array $params)
0 ignored issues
show
Duplication introduced by
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...
294
    {
295
        $allQueryFields = array('route_id');
296
        $allBodyFields = array('addresses', 'optimal_position');
297
        
298
        $route = Route4Me::makeRequst(array(
299
            'url'    => Endpoint::ROUTE_V4,
300
            'method' => 'PUT',
301
            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
302
            'body'   => Route4Me::generateRequestParameters($allBodyFields, $params)
303
        ));
304
305
        return Route::fromArray($route);
306
    }
307
    
308
    public function addNoteFile($params)
309
    {
310
        $fname = isset($params['strFilename']) ? $params['strFilename'] : null;
311
        $rpath = realpath($fname);
312
        
313
        $allQueryFields = array('route_id', 'address_id', 'dev_lat', 'dev_lng', 'device_type');
314
        $allBodyFields = array('strUpdateType', 'strFilename', 'strNoteContents');
315
        
316
        $result = Route4Me::makeRequst(array(
317
            'url'    => Endpoint::ROUTE_NOTES_ADD,
318
            'method' => 'POST',
319
            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params),
320
            'body'   => Route4Me::generateRequestParameters($allBodyFields, $params),
321
            'FILE'   => $rpath,
322
            'HTTPHEADER' => array(
323
                'Content-Type: application/x-www-form-urlencoded'
324
            )
325
        ));
326
327
        return $result;
328
    }
329
330 View Code Duplication
    public function deleteRoutes($route_id)
0 ignored issues
show
Duplication introduced by
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...
331
    {
332
         $result = Route4Me::makeRequst(array(
333
            'url'    => Endpoint::ROUTES_DELETE,
334
            'method' => 'DELETE',
335
            'query'  => array(
336
                'route_id' => $route_id,
337
            )
338
        ));
339
        
340
        return $result;
341
    }
342
    
343
    public function GetAddressesFromRoute($route_id)
344
    {
345
        $route1 = Route::getRoutes(array('route_id' => $route_id));
346
        
347
        if (isset($route1)) {
348
            return $route1->addresses;
349
        } else {
350
            return null;
351
        }
352
    }
353
    
354
    public function GetRandomAddressFromRoute($route_id)
355
    {
356
        $route1 = Route::getRoutes(array('route_id' => $route_id));
357
        
358
        if (isset($route1)) {
359
            $addresses = $route1->addresses;
360
            
361
            $rnd = rand(0, sizeof($addresses) - 1);
362
            
363
            return $addresses[$rnd];
364
        } else {
365
            return null;
366
        }
367
    }
368
369
    public function getRouteId()
370
    {
371
        return $this->route_id;
372
    }
373
374
    public function getOptimizationId()
375
    {
376
        return $this->optimization_problem_id;
377
    }
378
    
379
    public function GetLastLocation(array $params)
380
    {
381
        $allQueryFields = array('route_id', 'device_tracking_history');
382
        
383
        $route = Route4Me::makeRequst(array(
384
            'url'    => Endpoint::ROUTE_V4,
385
            'method' => 'GET',
386
            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params)
387
        ));
388
389
        return Route::fromArray($route);
390
    }
391
    
392 View Code Duplication
    public function GetTrackingHistoryFromTimeRange(array $params)
0 ignored issues
show
Duplication introduced by
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...
393
    {
394
        $allQueryFields = array('route_id', 'format', 'time_period', 'start_date', 'end_date');
395
        
396
        $route = Route4Me::makeRequst(array(
397
            'url'    => Endpoint::GET_DEVICE_LOCATION,
398
            'method' => 'GET',
399
            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params)
400
        ));
401
402
        return $route;
403
    }
404
    
405
    public function GetAssetTracking(array $params)
406
    {
407
        $allQueryFields = array('tracking');
408
        
409
        $route = Route4Me::makeRequst(array(
410
            'url'    => Endpoint::STATUS_V4,
411
            'method' => 'GET',
412
            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params)
413
        ));
414
415
        return $route;
416
    }
417
}
418