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

AddressBookLocation::addLocationsFromCsvFile()   F

Complexity

Conditions 67
Paths 4035

Size

Total Lines 168
Code Lines 117

Duplication

Lines 39
Ratio 23.21 %

Importance

Changes 0
Metric Value
cc 67
eloc 117
nc 4035
nop 2
dl 39
loc 168
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 6 and the first side effect is on line 452.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
	namespace Route4Me;
3
	
4
	use Route4Me\Common;
5
	
6
	class AddressBookLocation extends Common
7
	{
8
		static public $apiUrl = '/api.v4/address_book.php';
9
		static public $apiUrl00 = '/api/address_book/modify_contact.php';
10
		
11
		public $address_id;
12
		public $address_group;
13
		public $address_alias;
14
		public $address_1;
15
		public $address_2;
16
		public $first_name;
17
		public $last_name;
18
		public $address_email;
19
		public $address_phone_number;
20
		public $address_city;
21
		public $address_state_id;
22
		public $address_country_id;
23
		public $address_zip;
24
		public $cached_lat;
25
		public $cached_lng;
26
        public $curbside_lat;
27
        public $curbside_lng;
28
		public $color;
29
        public $address_custom_data;
30
        public $schedule;
31
		
32
		//public $offset;
33
		//public $limit;
34
		
35
		public function __construct () {  }
36
		
37
		public static function fromArray(array $params) {
38
			$addressbooklocation = new AddressBookLocation();
39
	        foreach($params as $key => $value) {
40
	            if (property_exists($addressbooklocation, $key)) {
41
	                $addressbooklocation->{$key} = $value;
42
	            }
43
			}
44
			
45
			return $addressbooklocation;
46
		}
47
		
48 View Code Duplication
		public static function getAddressBookLocation($addressId)
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...
49
	    {
50
	    	$ablocations = Route4Me::makeRequst(array(
51
	            'url'    => self::$apiUrl,
52
	            'method' => 'GET',
53
	            'query'  => array(
54
	                'query' => $addressId,
55
	                'limit' => 30
56
	            )
57
	        ));
58
59
			return $ablocations;
60
		}
61
		
62 View Code Duplication
		public static function searchRoutedLocation($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...
63
	    {
64
	    	$result= Route4Me::makeRequst(array(
65
	            'url'    => self::$apiUrl,
66
	            'method' => 'GET',
67
	            'query'  => array(
68
	                'display' => isset($params['display']) ? $params['display']: null,
69
	                'query' => isset($params['query']) ? $params['query']: null,
70
	                'fields' => isset($params['fields']) ? $params['fields']: null,
71
	                'limit' => isset($params['limit']) ? $params['limit']: null,
72
	                'offset' => isset($params['offset']) ? $params['offset'] : null,
73
	            )
74
	        ));
75
76
			return $result;
77
		}
78
		
79 View Code Duplication
		public static function getAddressBookLocations($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...
80
	    {
81
	    	$ablocations = Route4Me::makeRequst(array(
82
	            'url'    => self::$apiUrl,
83
	            'method' => 'GET',
84
	            'query'  => array(
85
	                'limit' => isset($params->limit) ? $params->limit: null,
86
	                'offset' => isset($params->offset) ? $params->offset : null,
87
	            )
88
	        ));
89
90
			return $ablocations;
91
		}
92
		
93 View Code Duplication
		public static function getAddressBookLocationsByIds($ids)
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...
94
	    {
95
	    	$ablocations = Route4Me::makeRequst(array(
96
	            'url'    => self::$apiUrl,
97
	            'method' => 'GET',
98
	            'query'  => array(
99
	                'address_id' => $ids
100
	            )
101
	        ));
102
103
			return $ablocations;
104
		}
105
		
106
		public static function addAdressBookLocation($params)
107
	    {
108
	    	$ablocations = Route4Me::makeRequst(array(
109
	            'url'    => self::$apiUrl,
110
	            'method' => 'POST',
111
	            'body'  => array(
112
	            	'address_1' => 	isset($params->address_1) ? $params->address_1: null,
113
	            	'address_2' =>    isset($params->address_2) ? $params->address_2: null,
114
	            	'address_alias' =>    isset($params->address_alias) ? $params->address_alias: null,
115
	                'cached_lat' => isset($params->cached_lat) ? $params->cached_lat : null,
116
	                'cached_lng' => isset($params->cached_lng) ? $params->cached_lng : null,
117
	                'curbside_lat' => isset($params->curbside_lat) ? $params->curbside_lat : null,
118
                    'curbside_lng' => isset($params->curbside_lng) ? $params->curbside_lng : null,
119
	                'address_phone_number' =>    isset($params->address_phone_number) ? $params->address_phone_number: null,
120
	                'address_group' =>    isset($params->address_group) ? $params->address_group: null,
121
	                'first_name' =>    isset($params->first_name) ? $params->first_name: null,
122
	                'last_name' =>    isset($params->last_name) ? $params->last_name: null,
123
                    'local_time_window_start' =>    isset($params->local_time_window_start) ? $params->local_time_window_start: null,
124
                    'local_time_window_end' =>    isset($params->local_time_window_end) ? $params->local_time_window_end: null,
125
                    'local_time_window_start_2' =>    isset($params->local_time_window_start_2) ? $params->local_time_window_start_2: null,
126
                    'local_time_window_end_2' =>    isset($params->local_time_window_end_2) ? $params->local_time_window_end_2: null,
127
	                'address_email' =>    isset($params->address_email) ? $params->address_email: null,
128
	                'address_city' =>    isset($params->address_city) ? $params->address_city: null,
129
	                'address_state_id' =>    isset($params->address_state_id) ? $params->address_state_id: null,
130
	                'address_country_id' =>    isset($params->address_country_id) ? $params->address_country_id: null,
131
	                'address_zip' =>    isset($params->address_zip) ? $params->address_zip: null,
132
	                'address_custom_data' =>    isset($params->address_custom_data) ? $params->address_custom_data: null,
133
	                'schedule' =>    isset($params->schedule) ? $params->schedule: null,
134
	                'schedule_blacklist' =>    isset($params->schedule_blacklist) ? $params->schedule_blacklist: null,
135
	                'service_time' =>    isset($params->service_time) ? $params->service_time: null,
136
	                'local_timezone_string' =>    isset($params->local_timezone_string) ? $params->local_timezone_string: null,
137
	                'color' =>    isset($params->color) ? $params->color: null,
138
	                'address_icon' =>    isset($params->address_icon) ? $params->address_icon: null,
139
	                'address_stop_type' =>    isset($params->address_stop_type) ? $params->address_stop_type: null,
140
	                'address_cube' =>    isset($params->address_cube) ? $params->address_cube: null,
141
	                'address_pieces' =>    isset($params->address_pieces) ? $params->address_pieces: null,
142
	                'address_reference_no' =>    isset($params->address_reference_no) ? $params->address_reference_no: null,
143
	                'address_revenue' =>    isset($params->address_revenue) ? $params->address_revenue: null,
144
	                'address_weight' =>    isset($params->address_weight) ? $params->address_weight: null,
145
	                'address_priority' =>    isset($params->address_priority) ? $params->address_priority: null,
146
	                'address_customer_po' =>    isset($params->address_customer_po) ? $params->address_customer_po: null,
147
	            )
148
	        ));
149
150
			return $ablocations;
151
		}
152
		
153 View Code Duplication
		public function deleteAdressBookLocation($address_ids)
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...
154
	    {
155
	        $address = Route4Me::makeRequst(array(
156
	            'url'    => self::$apiUrl,
157
	            'method' => 'DELETEARRAY',
158
	            'query'  => array(
159
	                'address_ids'     => $address_ids
160
	            )
161
	        ));
162
	
163
	        return $address;
164
	    }
165
		
166
		public function updateAdressBookLocation($params)
167
	    {
168
	    	//echo "address_id --> ".$params["address_id"]."<br";
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
169
	        $address = Route4Me::makeRequst(array(
170
	            'url'    => self::$apiUrl,
171
	            'method' => 'PUT',
172
	            'query'   => $params,
173
174
	        ));
175
	
176
	        return $address;
177
	    }
178
			
179 View Code Duplication
		public static function get($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...
180
	    {
181
	    	$ablocations = Route4Me::makeRequst(array(
182
	            'url'    => self::$apiUrl,
183
	            'method' => 'ADD',
184
	            'query'  => array(
185
	                'first_name' => isset($params->first_name) ? $params->first_name : null,
186
	                'address_1' => isset($params->address_1) ? $params->address_1: null,
187
	                'cached_lat' => isset($params->cached_lat) ? $params->cached_lat : null,
188
	                'cached_lng' => isset($params->cached_lng) ? $params->cached_lng : null,
189
	            )
190
	        ));
191
192
			return $ablocations;
193
		}
194
        
195
        public static function validateScheduleMode($scheduleMode)
196
        {
197
            $schedMmodes=array("daily","weekly","monthly","annually");
198
            
199
            if (in_array($scheduleMode, $schedMmodes)) return TRUE; else return FALSE;
200
        }
201
        
202
        public static function validateScheduleEnable($scheduleEnabled)
203
        {
204
            $schedEnambles=array(TRUE,FALSE);
205
            
206
            if (in_array($scheduleEnabled, $schedEnambles)) return TRUE; else return FALSE;
207
        }
208
        
209
        public static function validateScheduleEvery($scheduleEvery)
210
        {
211
            if (is_numeric($scheduleEvery)) return TRUE; else return FALSE;
212
        }
213
        
214 View Code Duplication
        public static function validateScheduleWeekDays($scheduleWeekDays)
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...
215
        {
216
            $weekdays = explode(',', $scheduleWeekDays);
217
            
218
            if (sizeof($weekdays)<1) return FALSE;
219
            
220
            $isValid=TRUE;
221
            
222
            for ($i=0; $i < sizeof($weekdays); $i++) { 
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function sizeof() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
223
                if (is_numeric($weekdays[$i])) {
224
                    $wday=intval($weekdays[$i]);
225
                    if ($wday<1 || $wday>7) $isValid=FALSE;
226
                }
227
                else $isValid=FALSE;
228
            }
229
            //echo $scheduleWeekDays.' --- '. $isValid."<br>";
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
230
            return $isValid;
231
        }
232
        
233
        public static function validateScheduleMonthlyMode($scheduleMonthlyMode)
234
        {
235
            $schedMonthlyMmodes=array("dates","nth");
236
            
237
            if (in_array($scheduleMonthlyMode, $schedMonthlyMmodes)) return TRUE; else return FALSE;
238
        }
239
        
240 View Code Duplication
        public static function validateScheduleMonthlyDates($scheduleMonthlyDates)
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
            $monthlyDates = explode(',', $scheduleMonthlyDates);
243
            
244
            if (sizeof($monthlyDates)<1) return FALSE;
245
            
246
            $isValid=TRUE;
247
            
248
            for ($i=0; $i < sizeof($monthlyDates); $i++) { 
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function sizeof() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
249
                if (is_numeric($monthlyDates[$i])) {
250
                    $mday=intval($monthlyDates[$i]);
251
                    if ($mday<1 || $mday>31) $isValid=FALSE;
252
                }
253
                else $isValid=FALSE;
254
            }
255
256
            return $isValid;
257
        }
258
        
259
        public static function validateScheduleNthN($scheduleNthN)
260
        {
261
            if (!is_numeric($scheduleNthN)) return FALSE;
262
            
263
            $schedNthNs=array(1,2,3,4,5,-1);
264
            if (in_array($scheduleNthN, $schedNthNs)) return TRUE; else return FALSE;
265
        }
266
        
267
        public static function validateScheduleNthWhat($scheduleNthWhat)
268
        {
269
            if (!is_numeric($scheduleNthWhat)) return FALSE;
270
            
271
            $schedNthWhats=array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
272
            if (in_array($scheduleNthWhat, $schedNthWhats)) return TRUE; else return FALSE;
273
        }
274
        
275
        /* Function adds the locations (with/without schedule) from the CSV file. 
276
         * $csvFileHandle - a file handler.
277
         * Returns array $results which contains two arrays: fail and succes.
278
         */
279
        public function addLocationsFromCsvFile($csvFileHandle, $locationsFieldsMapping)
280
        {
281
            $max_line_length = 512;
282
            $delemietr=',';
283
            
284
            $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...
285
            $results['success']=array();
286
            
287
            $columns = fgetcsv($csvFileHandle, $max_line_length, $delemietr);
288
            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...
289
                array_push($results['fail'],'Empty CSV table');
290
                return ($results);
291
            }
292
                     
293
            $iRow=1;
294
            
295
            while (($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr)) !== false) {
296
                if ($rows[$locationsFieldsMapping['cached_lat']] && $rows[$locationsFieldsMapping['cached_lng']] && $rows[$locationsFieldsMapping['address_1']] && array(null) !== $rows) {
297
                    $schedule="";
0 ignored issues
show
Unused Code introduced by
$schedule 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...
298
                    $mode="";
299
                    
300 View Code Duplication
                    if (isset($rows[$locationsFieldsMapping['schedule_mode']])) {
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...
301
                        if ($this->validateScheduleMode($rows[$locationsFieldsMapping['schedule_mode']])) {
302
                            $schedule='"mode":"'.$rows[$locationsFieldsMapping['schedule_mode']].'",'; 
303
                            $mode=$rows[$locationsFieldsMapping['schedule_mode']];
304
                        }
305
                        else {array_push($results['fail'],"$iRow --> Wrong schedule mode parameter"); $schedule="";}
306
                    }
307
                    else {array_push($results['fail'],"$iRow --> The schedule mode parameter is not set"); $schedule="";}
308
                    
309
                    if (isset($rows[$locationsFieldsMapping['schedule_enabled']])) {
310
                        if ($this->validateScheduleEnable($rows[$locationsFieldsMapping['schedule_enabled']])) { 
311
                            $schedule.='"enabled":'.$rows[$locationsFieldsMapping['schedule_enabled']].',';
312
                        }
313
                        else {array_push($results['fail'],"$iRow --> The schedule enabled parameter is not set ");  $schedule="";}
314
                    }
315
                    
316
                    if (isset($rows[$locationsFieldsMapping['schedule_every']])) {
317
                        if ($this->validateScheduleEvery($rows[$locationsFieldsMapping['schedule_every']])) {
318
                            $schedule.='"'.$mode.'":{'.'"every":'.$rows[$locationsFieldsMapping['schedule_every']].','; 
319
                            if ($mode=='daily') {
320
                                $schedule=trim($schedule,',');
321
                                $schedule.='}';
322
                            }
323
                        }
324
                        else {array_push($results['fail'],"$iRow --> The parameter sched_every is not set"); $schedule=""; }
325
                    }
326
                    
327
                    if ($mode!='daily') {
328
                        switch ($mode) {
329
                            case 'weekly':
330 View Code Duplication
                                if (isset($rows[$locationsFieldsMapping['schedule_weekdays']])) {
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...
331
                                    if ($this->validateScheduleWeekDays($rows[$locationsFieldsMapping['schedule_weekdays']])) {
332
                                         $schedule.='"weekdays":['.$rows[$locationsFieldsMapping['schedule_weekdays']].']}';
333
                                    }
334
                                    else {array_push($results['fail'],"$iRow --> Wrong weekdays"); $schedule="";}
335
                                }
336
                                else {array_push($results['fail'],"$iRow --> The parameters sched_weekdays is not set"); $schedule="";}
337
                                break;
338
                            case 'monthly':
339
                                $monthlyMode="";
340 View Code Duplication
                                if (isset($rows[$locationsFieldsMapping['monthly_mode']])) {
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...
341
                                    if ($this->validateScheduleMonthlyMode($rows[$locationsFieldsMapping['monthly_mode']])) {
342
                                         $monthlyMode=$rows[$locationsFieldsMapping['monthly_mode']];
343
                                         $schedule.='"mode": "'.$rows[$locationsFieldsMapping['monthly_mode']].'",';
344
                                    }
345
                                    else {array_push($results['fail'],"$iRow --> Wrong monthly mode"); $schedule="";}
346
                                }
347
                                else {array_push($results['fail'],"$iRow --> The parameter sched_monthly_mode is not set"); $schedule="";}
348
                                
349
                                if ($monthlyMode!="") {
350
                                    switch ($monthlyMode) {
351
                                        case 'dates':
352
                                            if (isset($rows[$locationsFieldsMapping['monthly_dates']])) {
353
                                                if ($this->validateScheduleMonthlyDates($rows[$locationsFieldsMapping['monthly_dates']])) {
354
                                                     $schedule.='"dates":['.$rows[$locationsFieldsMapping['monthly_dates']].']}';
355
                                                }
356
                                                else {array_push($results['fail'],"$iRow --> Wrong monthly dates"); $schedule="";}
357
                                            }
358
                                            break;
359
                                        case 'nth':
360 View Code Duplication
                                            if (isset($rows[$locationsFieldsMapping['monthly_nth_n']])) {
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...
361
                                                if ($this->validateScheduleNthN($rows[$locationsFieldsMapping['monthly_nth_n']])) {
362
                                                     $schedule.='"nth":{"n":'.$rows[$locationsFieldsMapping['monthly_nth_n']].',';
363
                                                }
364
                                                else {array_push($results['fail'],"$iRow --> Wrong parameter sched_nth_n"); $schedule="";}
365
                                            }
366
                                            else {array_push($results['fail'],"$iRow --> The parameter sched_nth_n is not set"); $schedule="";}
367
                                            
368 View Code Duplication
                                            if ($schedule!="") {
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...
369
                                                if (isset($rows[$locationsFieldsMapping['monthly_nth_wwhat']])) {
370
                                                    if ($this->validateScheduleNthWhat($rows[$locationsFieldsMapping['monthly_nth_wwhat']])) {
371
                                                         $schedule.='"what":'.$rows[$locationsFieldsMapping['monthly_nth_wwhat']].'}}';
372
                                                    }
373
                                                    else {array_push($results['fail'],"$iRow --> Wrong parameter sched_nth_what"); $schedule="";}
374
                                                }
375
                                                else {array_push($results['fail'],"$iRow --> The parameter sched_nth_what is not set"); $schedule="";}
376
                                            }
377
                                            
378
                                            break;
379
                                    }
380
                                }
381
                                break;
382
                            default:
383
                                $schedule=="";
384
                                break;
385
                        }
386
                        
387
                    }
388
389
                    if (($mode=='daily' || $mode=='weekly' || $mode=='monthy') && $schedule=="") {$iRow++; continue;}
390
                    
391
                    $schedule=strtolower($schedule);
392
                    
393
                    $schedule='[{'.$schedule.'}]';
394
395
                    $oSchedule= json_decode($schedule,TRUE);
396
                    
397
                    $AdressBookLocationParameters=AddressBookLocation::fromArray(array(
398
                        "cached_lat"    => $rows[$locationsFieldsMapping['cached_lat']],
399
                        "cached_lng"    => $rows[$locationsFieldsMapping['cached_lng']],
400
                        "curbside_lat"     => isset($locationsFieldsMapping['curbside_lat']) ? $rows[$locationsFieldsMapping['curbside_lat']] : null,
401
                        "curbside_lng"     => isset($locationsFieldsMapping['curbside_lng']) ? $rows[$locationsFieldsMapping['curbside_lng']] : null,
402
                        "address_alias"     => isset($locationsFieldsMapping['address_alias']) ? $rows[$locationsFieldsMapping['address_alias']] : null,
403
                        "address_1"     => $rows[$locationsFieldsMapping['address_1']],
404
                        "address_2"     => isset($locationsFieldsMapping['address_2']) ? $rows[$locationsFieldsMapping['address_2']] : null,
405
                        "address_city"     => isset($locationsFieldsMapping['address_city']) ? $rows[$locationsFieldsMapping['address_city']] : null,
406
                        "address_state_id"     => isset($locationsFieldsMapping['address_state_id']) ? $rows[$locationsFieldsMapping['address_state_id']] : null,
407
                        "address_zip"     => isset($locationsFieldsMapping['address_zip']) ? $rows[$locationsFieldsMapping['address_zip']] : null,
408
                        "address_phone_number"  => isset($locationsFieldsMapping['address_phone_number']) ? $rows[$locationsFieldsMapping['address_phone_number']] : null,
409
                        "schedule" => isset($oSchedule) ? $oSchedule : null,
410
                        "address_group"  => isset($locationsFieldsMapping['address_group']) ? $rows[$locationsFieldsMapping['address_group']] : null,
411
                        "first_name"  => isset($locationsFieldsMapping['first_name']) ? $rows[$locationsFieldsMapping['first_name']] : null,
412
                        "last_name"  => isset($locationsFieldsMapping['last_name']) ? $rows[$locationsFieldsMapping['last_name']] : null,
413
                        "local_time_window_start"  => isset($locationsFieldsMapping['local_time_window_start']) ? $rows[$locationsFieldsMapping['local_time_window_start']] : null,
414
                        "local_time_window_end"  => isset($locationsFieldsMapping['local_time_window_end']) ? $rows[$locationsFieldsMapping['local_time_window_end']] : null,
415
                        "local_time_window_start_2"  => isset($locationsFieldsMapping['local_time_window_start_2']) ? $rows[$locationsFieldsMapping['local_time_window_start_2']] : null,
416
                        "local_time_window_end_2"  => isset($locationsFieldsMapping['local_time_window_end_2']) ? $rows[$locationsFieldsMapping['local_time_window_end_2']] : null,
417
                        "address_email"  => isset($locationsFieldsMapping['address_email']) ? $rows[$locationsFieldsMapping['address_email']] : null,
418
                        "address_country_id"  => isset($locationsFieldsMapping['address_country_id']) ? $rows[$locationsFieldsMapping['address_country_id']] : null,
419
                        "address_custom_data"  => isset($locationsFieldsMapping['address_custom_data']) ? $rows[$locationsFieldsMapping['address_custom_data']] : null,
420
                        "schedule_blacklist"  => isset($locationsFieldsMapping['schedule_blacklist']) ? $rows[$locationsFieldsMapping['schedule_blacklist']] : null,
421
                        "service_time"  => isset($locationsFieldsMapping['service_time']) ? $rows[$locationsFieldsMapping['service_time']] : null,
422
                        "local_timezone_string"  => isset($locationsFieldsMapping['local_timezone_string']) ? $rows[$locationsFieldsMapping['local_timezone_string']] : null,
423
                        "color"  => isset($locationsFieldsMapping['color']) ? $rows[$locationsFieldsMapping['color']] : null,
424
                        "address_icon"  => isset($locationsFieldsMapping['address_icon']) ? $rows[$locationsFieldsMapping['address_icon']] : null,
425
                        "address_stop_type"  => isset($locationsFieldsMapping['address_stop_type']) ? $rows[$locationsFieldsMapping['address_stop_type']] : null,
426
                        "address_cube"  => isset($locationsFieldsMapping['address_cube']) ? $rows[$locationsFieldsMapping['address_cube']] : null,
427
                        "address_pieces"  => isset($locationsFieldsMapping['address_pieces']) ? $rows[$locationsFieldsMapping['address_pieces']] : null,
428
                        "address_reference_no"  => isset($locationsFieldsMapping['address_reference_no']) ? $rows[$locationsFieldsMapping['address_reference_no']] : null,
429
                        "address_revenue"  => isset($locationsFieldsMapping['address_revenue']) ? $rows[$locationsFieldsMapping['address_revenue']] : null,
430
                        "address_weight"  => isset($locationsFieldsMapping['address_weight']) ? $rows[$locationsFieldsMapping['address_weight']] : null,
431
                        "address_priority"  => isset($locationsFieldsMapping['address_priority']) ? $rows[$locationsFieldsMapping['address_priority']] : null,
432
                        "address_customer_po"  => isset($locationsFieldsMapping['address_customer_po']) ? $rows[$locationsFieldsMapping['address_customer_po']] : null,
433
                    ));
434
                    
435
                    $abContacts=new AddressBookLocation();
436
    
437
                    $abcResults=$abContacts->addAdressBookLocation($AdressBookLocationParameters); //temporarry
438
                    
439
                    array_push($results['success'],"The schedule location with address_id = ".strval($abcResults["address_id"])." added successfuly.");
440
441
                }
442
                
443
            }
444
445
            return $results;
446
        }
447
	
448
	   
449
	}
450
	
451
?>
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...
452