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.
Completed
Branch Editing-Fixing (c4d168)
by Igor
03:30
created

Address::markAddress()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
nc 1
nop 2
dl 14
loc 14
rs 9.7998
c 0
b 0
f 0
1
<?php
2
namespace Route4Me;
3
4
use Route4Me\Exception\BadParam;
5
use Route4Me\Route4Me;
6
use GuzzleHttp\Client;
7
use Route4Me\Common;
8
use Route4Me\Enum\Endpoint;
9
10
class Address extends Common
11
{
12
    public $route_destination_id;
13
    public $alias;
14
    public $member_id;
15
    public $address;
16
    public $addressUpdate;
17
    public $is_depot = false;
18
    public $lat;
19
    public $lng;
20
    public $route_id;
21
    public $original_route_id;
22
    public $optimization_problem_id;
23
    public $sequence_no;
24
    public $geocoded;
25
    public $preferred_geocoding;
26
    public $failed_geocoding;
27
    public $geocodings = array();
28
    public $contact_id;
29
    public $is_visited;
30
    public $customer_po;
31
    public $invoice_no;
32
    public $reference_no;
33
    public $order_no;
34
    public $weight;
35
    public $cost;
36
    public $revenue;
37
    public $cube;
38
    public $pieces;
39
    public $email;
40
    public $phone;
41
    public $tracking_number;
42
    public $destination_note_count;
43
    public $drive_time_to_next_destination;
44
    public $distance_to_next_destination;
45
    public $generated_time_window_start;
46
    public $generated_time_window_end;
47
    public $time_window_start;
48
    public $time_window_end;
49
    public $time;
50
    public $notes;
51
    public $timestamp_last_visited;
52
    public $custom_fields = array();
53
    public $manifest = array();
54
    
55
    public $first_name;
56
    public $last_name;
57
    public $is_departed;
58
    public $timestamp_last_departed;
59
    public $order_id;
60
    public $priority;
61
    public $curbside_lat;
62
    public $curbside_lng;
63
    public $time_window_start_2;
64
    public $time_window_end_2;
65
66
    public static function fromArray(array $params)
67
    {
68
        /*if (!isset($params['address'])) {
69
            throw new BadParam('address must be provided');
70
        }
71
72
        if (!isset($params['lat'])) {
73
            throw new BadParam('lat must be provided');
74
        }
75
76
        if (!isset($params['lng'])) {
77
            throw new BadParam('lng must be provided');
78
        }*/
79
80
        $address = new Address();
81
        foreach($params as $key => $value) {
82
            if (property_exists($address, $key)) {
83
                $address->{$key} = $value;
84
            }
85
        }
86
87
        return $address;
88
    }
89
90
    public static function getAddress($routeId, $addressId)
91
    {
92
        $address = Route4Me::makeRequst(array(
93
            'url'    => Endpoint::ADDRESS_V4,
94
            'method' => 'GET',
95
            'query'  => array(
96
                'route_id'             => $routeId,
97
                'route_destination_id' => $addressId,
98
            )
99
        ));
100
101
        return Address::fromArray($address);
102
    }
103
    
104
    /*Get notes from the specified route destination
105
     * Returns an address object with notes, if an address exists, otherwise - return null.
106
     */
107 View Code Duplication
    public static function GetAddressesNotes($noteParams)
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...
108
    {
109
        $address = Route4Me::makeRequst(array(
110
            'url'    => Endpoint::ADDRESS_V4,
111
            'method' => 'GET',
112
            'query'  => array(
113
                'route_id'             => isset($noteParams['route_id']) ? $noteParams['route_id'] : null, 
114
                'route_destination_id' => isset($noteParams['route_destination_id']) 
115
                                             ? $noteParams['route_destination_id'] : null,
116
                'notes'                => 1,
117
            )
118
        ));
119
120
        return $address;
121
    }
122
123 View Code Duplication
    public function update()
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...
124
    {
125
        $addressUpdate = Route4Me::makeRequst(array(
126
            'url'    => Endpoint::ADDRESS_V4,
127
            'method' => 'PUT',
128
            'body'   => $this->toArray(),
129
            'query'  => array(
130
                'route_id'             => $this->route_id,
131
                'route_destination_id' => $this->route_destination_id,
132
            ),
133
        ));
134
135
        return Address::fromArray($addressUpdate);
136
    }
137
    
138 View Code Duplication
    public function markAddress($params, $body)
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...
139
    {
140
        $result = Route4Me::makeRequst(array(
141
            'url'    => Endpoint::ADDRESS_V4,
142
            'method' => 'PUT',
143
            'query'  => array(
144
                'route_id'             => isset($params['route_id']) ? $params['route_id'] : null, 
145
                'route_destination_id' => isset($params['route_destination_id']) ? $params['route_destination_id'] : null,
146
            ),
147
            'body'   => $body
148
        ));
149
150
        return $result;
151
    }
152
    
153
    public function markAsDeparted($params)
154
    {
155
        $address = Route4Me::makeRequst(array(
156
            'url'    => Endpoint::MARK_ADDRESS_DEPARTED,
157
            'method' => 'GET',
158
            'query'  => array(
159
                'route_id'     => isset($params['route_id']) ? $params['route_id']: null,
160
                'address_id'   => isset($params['address_id']) ? $params['address_id']: null,
161
                'is_departed'  => isset($params['is_departed']) ? $params['is_departed']: null,
162
                'member_id'    => isset($params['member_id']) ? $params['member_id']: null,
163
            ),
164
        ));
165
166
        return $address;
167
    }
168
    
169 View Code Duplication
    public function markAsVisited($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...
170
    {
171
        $address = Route4Me::makeRequst(array(
172
            'url'    => Endpoint::UPDATE_ADDRESS_VISITED,
173
            'method' => 'GET',
174
            'query'  => array(
175
                'route_id'   => isset($params['route_id']) ? $params['route_id'] : null,
176
                'address_id' => isset($params['address_id']) ? $params['address_id'] : null,
177
                'member_id'  => isset($params['member_id']) ? $params['member_id'] : null,
178
            ),
179
            'body'  =>  array(
180
                'is_visited' => isset($params['is_visited']) ? $params['is_visited'] : null
181
            )
182
        ));
183
184
        return $address;
185
    }
186
187 View Code Duplication
    public function delete()
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...
188
    {
189
        $address = Route4Me::makeRequst(array(
190
            'url'    => Endpoint::ADDRESS_V4,
191
            'method' => 'DELETE',
192
            'query'  => array(
193
                'route_id'             => $this->route_id,
194
                'route_destination_id' => $this->route_destination_id,
195
            )
196
        ));
197
198
        return (bool)$address['deleted'];
199
    }
200
    
201
    public function moveDestinationToRoute($params)
202
    {
203
        $result = Route4Me::makeRequst(array(
204
            'url'    => Endpoint::MOVE_ROUTE_DESTINATION,
205
            'method' => 'POST',
206
            'body'  => array(
207
                'to_route_id'          => isset($params['to_route_id']) ? $params['to_route_id'] : null,
208
                'route_destination_id' => isset($params['route_destination_id']) ? $params['route_destination_id'] : null,
209
                'after_destination_id' => isset($params['after_destination_id']) ? $params['after_destination_id'] : null
210
            ),
211
            'HTTPHEADER'  => 'Content-Type: multipart/form-data'
212
        ));
213
214
        return $result;
215
        
216
    }
217
    
218 View Code Duplication
    public function AddAddressNote($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...
219
    {
220
        $result = Route4Me::makeRequst(array(
221
            'url'    => Endpoint::ROUTE_NOTES_ADD,
222
            'method' => 'POST',
223
            'query'  => array(
224
                'route_id'     =>  isset($params['route_id']) ? $params['route_id'] : null,
225
                'address_id'   =>  isset($params['address_id']) ? $params['address_id'] : null,
226
                'dev_lat'      =>  isset($params['dev_lat']) ? $params['dev_lat'] : null,
227
                'dev_lng'      =>  isset($params['dev_lng']) ? $params['dev_lng'] : null,
228
                'device_type'  =>  isset($params['device_type']) ? $params['device_type'] : null
229
            ),
230
            'body'  => array(
231
                'strNoteContents' => isset($params['strNoteContents']) ? $params['strNoteContents'] : null,
232
                'strUpdateType'   => isset($params['strUpdateType']) ? $params['strUpdateType'] : null
233
            ),
234
            'HTTPHEADER'  => 'Content-Type: multipart/form-data'
235
        ));
236
237
        return $result;
238
    }
239
240 View Code Duplication
    public function AddNoteFile($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...
241
    {
242
        $result = Route4Me::fileUploadRequest(array(
243
            'url'    => Endpoint::ROUTE_NOTES_ADD,
244
            'method' => 'POST',
245
            'query'  => array(
246
                'route_id'      =>  isset($params['route_id']) ? $params['route_id'] : null,
247
                'address_id'    =>  isset($params['address_id']) ? $params['address_id'] : null,
248
                'dev_lat'       =>  isset($params['dev_lat']) ? $params['dev_lat'] : null,
249
                'dev_lng'       =>  isset($params['dev_lng']) ? $params['dev_lng'] : null,
250
                'device_type'   =>  isset($params['device_type']) ? $params['device_type'] : null,
251
                'strUpdateType' =>  isset($params['strUpdateType']) ? $params['strUpdateType'] : null
252
            ),
253
            'body'  => array(
254
                'strFilename' => isset($params['strFilename']) ? $params['strFilename'] : null
255
            ),
256
            'HTTPHEADER'  => 'Content-Type: multipart/form-data'
257
        ));
258
259
        return $result;
260
    }
261
262 View Code Duplication
    public function createCustomNoteType($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...
263
    {
264
        $result = Route4Me::makeRequst(array(
265
            'url'    => Endpoint::NOTE_CUSTOM_TYPES_V4,
266
            'method' => 'POST',
267
            'body'   => array(
268
                'type'   => isset($params['type']) ? $params['type'] : null,
269
                'values' => isset($params['values']) ? $params['values'] : null
270
            )
271
        ));
272
273
        return $result;
274
    }
275
    
276 View Code Duplication
    public function removeCustomNoteType($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...
277
    {
278
        $result = Route4Me::makeRequst(array(
279
            'url'    => Endpoint::NOTE_CUSTOM_TYPES_V4,
280
            'method' => 'DELETE',
281
            'body'   => array(
282
                'id' => isset($params['id']) ? $params['id'] : null
283
            )
284
        ));
285
286
        return $result;
287
    }
288
    
289
    public function getAllCustomNoteTypes()
290
    {
291
        $result = Route4Me::makeRequst(array(
292
            'url'    => Endpoint::NOTE_CUSTOM_TYPES_V4,
293
            'method' => 'GET'
294
        ));
295
296
        return $result;
297
    }
298
    
299
    public function addCustomNoteToRoute($params)
300
    {
301
        $customArray = array();
302
        
303
        foreach ($params as $key => $value) {
304
            $kpos = strpos($key, "custom_note_type");
305
            
306
            if ($kpos !== false) {
307
                $customArray[$key]=$value;
308
            }
309
        }
310
        
311
        $result = Route4Me::makeRequst(array(
312
            'url'    => Endpoint::ROUTE_NOTES_ADD,
313
            'method' => 'POST',
314
            'query'  => array(
315
                'route_id'      =>  isset($params['route_id']) ? $params['route_id'] : null,
316
                'address_id'    =>  isset($params['address_id']) ? $params['address_id'] : null,
317
                'format'        =>  isset($params['format']) ? $params['format'] : null,
318
                'dev_lat'       =>  isset($params['dev_lat']) ? $params['dev_lat'] : null,
319
                'dev_lng'       =>  isset($params['dev_lng']) ? $params['dev_lng'] : null
320
            ),
321
            'body'  => array_merge(array(
322
                'strUpdateType'   =>  isset($params['strUpdateType']) ? $params['strUpdateType'] : null,
323
                'strUpdateType'   =>  isset($params['strUpdateType']) ? $params['strUpdateType'] : null,
324
                'strNoteContents' =>  isset($params['strNoteContents']) ? $params['strNoteContents'] : null
325
            ), $customArray),
326
            'HTTPHEADER'  => 'Content-Type: multipart/form-data'
327
        ));
328
329
        return $result;
330
    }
331
332
    function getAddressId()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
333
    {
334
        return $this->route_destination_id;
335
    }
336
}
337