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.
Test Failed
Push — master ( e93048...2c5e37 )
by Oleg
02:40
created

Order::validateLatitude()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
eloc 4
nc 3
nop 1
dl 8
loc 8
rs 9.2
c 0
b 0
f 0
1
<?php
2
	namespace Route4Me;
3
	
4
	use Route4Me\Common;
5
	
6
	class Order extends Common
7
	{
8
		static public $apiUrl = '/api.v4/order.php';
9
		static public $apiUrlRoute = '/api.v4/route.php';
10
		static public $apiUrlOpt = '/api.v4/optimization_problem.php';
11
		
12
		public $address_1;
13
        public $address_2;
14
		public $cached_lat;
15
		public $cached_lng;
16
        public $curbside_lat;
17
        public $curbside_lng;
18
		public $address_alias;
19
		public $address_city;
20
		public $EXT_FIELD_first_name;
21
		public $EXT_FIELD_last_name;
22
		public $EXT_FIELD_email;
23
		public $EXT_FIELD_phone;
24
		public $EXT_FIELD_custom_data;
25
        
26
        public $color;
27
        public $order_icon;
28
        public $local_time_window_start;
29
        public $local_time_window_end;
30
        public $local_time_window_start_2;
31
        public $local_time_window_end_2;
32
        public $service_time;
33
        
34
        public $day_scheduled_for_YYMMDD;
35
		
36
		public $route_id;
37
		public $redirect;
38
		public $optimization_problem_id;
39
		public $order_id;
40
		public $order_ids;
41
		
42
		public $day_added_YYMMDD;
43
		public $scheduled_for_YYMMDD;
44
		public $fields;
45
		public $offset;
46
		public $limit;
47
		public $query;
48
		
49
		public function __construct () {  }
50
		
51
		public static function fromArray(array $params) {
52
			$order= new Order();
53
	        foreach($params as $key => $value) {
54
	            if (property_exists($order, $key)) {
55
	                $order->{$key} = $value;
56
	            }
57
			}
58
			
59
			return $order;
60
		}
61
		
62
		public static function addOrder($params)
63
	    {
64
	    	$response = Route4Me::makeRequst(array(
65
	            'url'    => self::$apiUrl,
66
	            'method' => 'POST',
67
	            'body'  => array(
68
					'address_1' => 	isset($params->address_1) ? $params->address_1: null,
69
					'address_2' =>     isset($params->address_2) ? $params->address_2: null,
70
	                'cached_lat' => isset($params->cached_lat) ? $params->cached_lat : null,
71
	                'cached_lng' => isset($params->cached_lng) ? $params->cached_lng : null,
72
	                'curbside_lat' => isset($params->curbside_lat) ? $params->curbside_lat : null,
73
                    'curbside_lng' => isset($params->curbside_lng) ? $params->curbside_lng : null,
74
	                'color' => isset($params->color) ? $params->color : null,
75
	                'order_icon' => isset($params->order_icon) ? $params->order_icon : null,
76
	                'day_scheduled_for_YYMMDD' => isset($params->day_scheduled_for_YYMMDD) ? $params->day_scheduled_for_YYMMDD : null,
77
	                'address_alias' => isset($params->address_alias) ? $params->address_alias : null,
78
	                'address_city' => 	isset($params->address_city) ? $params->address_city: null,
79
	                'local_time_window_start' =>  isset($params->local_time_window_start) ? $params->local_time_window_start: null,
80
	                'local_time_window_end' =>  isset($params->local_time_window_end) ? $params->local_time_window_end: null,
81
	                'local_time_window_start_2' =>  isset($params->local_time_window_start_2) ? $params->local_time_window_start_2: null,
82
	                'local_time_window_end_2' =>  isset($params->local_time_window_end_2) ? $params->local_time_window_end_2: null,
83
	                'service_time' =>  isset($params->service_time) ? $params->service_time: null,
84
	                'EXT_FIELD_first_name' => 	isset($params->EXT_FIELD_first_name) ? $params->EXT_FIELD_first_name: null,
85
	                'EXT_FIELD_last_name' => 	isset($params->EXT_FIELD_last_name) ? $params->EXT_FIELD_last_name: null,
86
	                'EXT_FIELD_email' => 	isset($params->EXT_FIELD_email) ? $params->EXT_FIELD_email: null,
87
	                'EXT_FIELD_phone' => 	isset($params->EXT_FIELD_phone) ? $params->EXT_FIELD_phone: null,
88
	                'EXT_FIELD_custom_data' => 	isset($params->EXT_FIELD_custom_data) ? $params->EXT_FIELD_custom_data: null,
89
				)
90
	        ));
91
92
			return $response;
93
		}
94
95 View Code Duplication
		public static function addOrder2Route($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...
96
	    {
97
	    	$response = Route4Me::makeRequst(array(
98
	            'url'    => self::$apiUrlRoute,
99
	            'method' => 'PUT',
100
	            'query'  => array(
101
					'route_id' => 	isset($params->route_id) ? $params->route_id: null,
102
	                'redirect' => isset($params->redirect) ? $params->redirect : null
103
				),
104
				'body'  => (array)$body
105
			));
106
107
			return $response;
108
		}
109
		
110 View Code Duplication
		public static function addOrder2Destination($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...
111
	    {
112
	    	$response = Route4Me::makeRequst(array(
113
	            'url'    => self::$apiUrlOpt,
114
	            'method' => 'PUT',
115
	            'query'  => array(
116
					'optimization_problem_id' => 	isset($params->optimization_problem_id) ? $params->optimization_problem_id: null,
117
	                'redirect' => isset($params->redirect) ? $params->redirect : null
118
				),
119
				'body'  => (array)$body
120
			));
121
122
			return $response;
123
		}
124
		
125 View Code Duplication
		public static function getOrder($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...
126
	    {
127
	    	$response = Route4Me::makeRequst(array(
128
	            'url'    => self::$apiUrl,
129
	            'method' => 'GET',
130
	            'query'  => array(
131
					'order_id' => 	isset($params->order_id) ? $params->order_id: null,
132
				)
133
	        ));
134
135
			return $response;
136
		}
137
		
138
		public static function getOrders()
139
	    {
140
	    	$response = Route4Me::makeRequst(array(
141
	            'url'    => self::$apiUrl,
142
	            'method' => 'GET'
143
	        ));
144
145
			return $response;
146
		}
147
		
148 View Code Duplication
		public static function removeOrder($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...
149
	    {
150
	    	$response = Route4Me::makeRequst(array(
151
	            'url'    => self::$apiUrl,
152
	            'method' => 'DELETE',
153
	            'body'  => array(
154
					'order_ids' => 	isset($params->order_ids) ? $params->order_ids: null
155
				)
156
	        ));
157
158
			return $response;
159
		}
160
		
161 View Code Duplication
		public static function updateOrder($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...
162
	    {
163
	    	$response = Route4Me::makeRequst(array(
164
	            'url'    => self::$apiUrl,
165
	            'method' => 'PUT',
166
	            'body'  => (array)$body
167
	        ));
168
169
			return $response;
170
		}
171
		
172
		public static function searchOrder($params)
173
	    {
174
	    	$response = Route4Me::makeRequst(array(
175
	            'url'    => self::$apiUrl,
176
	            'method' => 'GET',
177
	            'query'  => array(
178
					'day_added_YYMMDD' => 	isset($params->day_added_YYMMDD) ? $params->day_added_YYMMDD: null,
179
					'scheduled_for_YYMMDD' => 	isset($params->scheduled_for_YYMMDD) ? $params->scheduled_for_YYMMDD: null,
180
					'fields' => 	isset($params->fields) ? $params->fields: null,
181
					'offset' => 	isset($params->offset) ? $params->offset: null,
182
					'limit' => 	isset($params->limit) ? $params->limit: null,
183
					'query' => 	isset($params->query) ? $params->query: null,
184
				)
185
	        ));
186
187
			return $response;
188
		}
189
        
190 View Code Duplication
        public static function validateLatitude($lat)
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...
191
        {
192
            if (!is_numeric($lat)) return false;
193
            
194
            if ($lat>90 || $lat<-90) return false;
195
            
196
            return true;
197
        }
198
        
199 View Code Duplication
        public static function validateLongitude($lng)
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...
200
        {
201
            if (!is_numeric($lng)) return false;
202
            
203
            if ($lng>180 || $lng<-180) return false;
204
            
205
            return true;
206
        }
207
        
208
        public function addOrdersFromCsvFile($csvFileHandle, $ordersFieldsMapping)
209
        {
210
            $max_line_length = 512;
211
            $delemietr=',';
212
            
213
            $results['fail']=array();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$results was never initialized. Although not strictly required by PHP, it is generally a good practice to add $results = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
214
            $results['success']=array();
215
            
216
            $columns = fgetcsv($csvFileHandle, $max_line_length, $delemietr);
217
            
218
            if (!$columns) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $columns of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
219
                 array_push($results['fail'],'Empty CSV table');
220
                 return ($results);
221
            }
222
                     
223
            $iRow=1;
224
            
225
            while (($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr)) !== false) {
226
                if ($rows[$ordersFieldsMapping['cached_lat']] && $rows[$ordersFieldsMapping['cached_lng']] && $rows[$ordersFieldsMapping['address_1']] && array(null) !== $rows) {
227
                    
228
                    $cached_lat=0.000;
0 ignored issues
show
Unused Code introduced by
$cached_lat is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
229
                    
230 View Code Duplication
                    if (!$this->validateLatitude($rows[$ordersFieldsMapping['cached_lat']])) {
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...
231
                        array_push($results['fail'],"$iRow --> Wrong cached_lat"); 
232
                        $iRow++;
233
                        continue;
234
                    }
235
                    else $cached_lat=doubleval($rows[$ordersFieldsMapping['cached_lat']]);
236
                    
237
                    $cached_lng=0.000;
0 ignored issues
show
Unused Code introduced by
$cached_lng is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
238
                    
239 View Code Duplication
                    if (!$this->validateLongitude($rows[$ordersFieldsMapping['cached_lng']])) {
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...
240
                        array_push($results['fail'],"$iRow --> Wrong cached_lng"); 
241
                        $iRow++;
242
                        continue;
243
                    }
244
                    else $cached_lng=doubleval($rows[$ordersFieldsMapping['cached_lng']]);
245
                    
246
                    
247
                    
248
                    if (isset($ordersFieldsMapping['curbside_lat'])) {
249
                        if (!$this->validateLatitude($rows[$ordersFieldsMapping['curbside_lat']])) {
250
                            array_push($results['fail'],"$iRow --> Wrong curbside_lat"); 
251
                            $iRow++;
252
                            continue;
253
                        }
254
                    }
255
                    
256
                    if (isset($ordersFieldsMapping['curbside_lng'])) {
257
                        if (!$this->validateLongitude($rows[$ordersFieldsMapping['curbside_lng']])) {
258
                            array_push($results['fail'],"$iRow --> Wrong curbside_lng"); 
259
                            $iRow++;
260
                            continue;
261
                        }
262
                    }
263
                    
264
                    $address=$rows[$ordersFieldsMapping['address_1']];
265
                    
266
                    if (isset($ordersFieldsMapping['order_city'])) $address.=', '.$rows[$ordersFieldsMapping['order_city']];
267
                    if (isset($ordersFieldsMapping['order_state_id'])) $address.=', '.$rows[$ordersFieldsMapping['order_state_id']];
268
                    if (isset($ordersFieldsMapping['order_zip_code'])) $address.=', '.$rows[$ordersFieldsMapping['order_zip_code']];
269
                    if (isset($ordersFieldsMapping['order_country_id'])) $address.=', '.$rows[$ordersFieldsMapping['order_country_id']];
270
                    
271
                    echo "$iRow --> ".$ordersFieldsMapping['day_scheduled_for_YYMMDD'].", ".$rows[$ordersFieldsMapping['day_scheduled_for_YYMMDD']]."<br>";
272
                    
273
                    $orderParameters = Order::fromArray(array(
274
                        "cached_lat"    => $cached_lat,
275
                        "cached_lng"    => $cached_lng,
276
                        "curbside_lat"     => isset($ordersFieldsMapping['curbside_lat']) ? $rows[$ordersFieldsMapping['curbside_lat']] : null,
277
                        "curbside_lng"     => isset($ordersFieldsMapping['curbside_lng']) ? $rows[$ordersFieldsMapping['curbside_lng']] : null,
278
                        "color"     => isset($ordersFieldsMapping['color']) ? $rows[$ordersFieldsMapping['color']] : null,
279
                        "day_scheduled_for_YYMMDD"     => isset($ordersFieldsMapping['day_scheduled_for_YYMMDD']) ? $rows[$ordersFieldsMapping['day_scheduled_for_YYMMDD']] : null,
280
                        "address_alias"     => isset($ordersFieldsMapping['address_alias']) ? $rows[$ordersFieldsMapping['address_alias']] : null,
281
                        "address_1"     => $address,
282
                        "address_2"     => isset($ordersFieldsMapping['address_2']) ? $rows[$ordersFieldsMapping['address_2']] : null,
283
                        "local_time_window_start"     => isset($ordersFieldsMapping['local_time_window_start']) ? $rows[$ordersFieldsMapping['local_time_window_start']] : null,
284
                        "local_time_window_end"     => isset($ordersFieldsMapping['local_time_window_end']) ? $rows[$ordersFieldsMapping['local_time_window_end']] : null,
285
                        "local_time_window_start_2"     => isset($ordersFieldsMapping['local_time_window_start_2']) ? $rows[$ordersFieldsMapping['local_time_window_start_2']] : null,
286
                        "local_time_window_end_2"     => isset($ordersFieldsMapping['local_time_window_end_2']) ? $rows[$ordersFieldsMapping['local_time_window_end_2']] : null,
287
                        "service_time"     => isset($ordersFieldsMapping['service_time']) ? $rows[$ordersFieldsMapping['service_time']] : null,
288
                        "EXT_FIELD_first_name"     => isset($ordersFieldsMapping['EXT_FIELD_first_name']) ? $rows[$ordersFieldsMapping['EXT_FIELD_first_name']] : null,
289
                        "EXT_FIELD_last_name"     => isset($ordersFieldsMapping['EXT_FIELD_last_name']) ? $rows[$ordersFieldsMapping['EXT_FIELD_last_name']] : null,
290
                        "EXT_FIELD_email"     => isset($ordersFieldsMapping['EXT_FIELD_email']) ? $rows[$ordersFieldsMapping['EXT_FIELD_email']] : null,
291
                        "EXT_FIELD_phone"     => isset($ordersFieldsMapping['EXT_FIELD_phone']) ? $rows[$ordersFieldsMapping['EXT_FIELD_phone']] : null,
292
                        "EXT_FIELD_custom_data"     => isset($ordersFieldsMapping['EXT_FIELD_custom_data']) ? $rows[$ordersFieldsMapping['EXT_FIELD_custom_data']] : null,
293
                        "order_icon"     => isset($ordersFieldsMapping['order_icon']) ? $rows[$ordersFieldsMapping['order_icon']] : null,
294
                    ));
295
                    
296
                    $order = new Order();
297
                    
298
                    $orderResults = $order->addOrder($orderParameters);
299
                    
300
                    array_push($results['success'],"The order with order_id = ".strval($orderResults["order_id"])." added successfuly.");
301
                }
302
                else {
303
                    array_push($results['fail'],"$iRow --> one of the parameters cached_lat, cached_lng, address_1 is not set"); 
304
                }
305
                
306
                $iRow++;
307
            }
308
        }
309
310
	}
311
	
312
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...