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
Push — master ( 51d0da...ea440c )
by Liuta
04:02 queued 45s
created
includes/class-xcloner-file-system.php 1 patch
Braces   +164 added lines, -121 removed lines patch added patch discarded remove patch
@@ -61,13 +61,14 @@  discard block
 block discarded – undo
61 61
 			$this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([
62 62
 					'disable_asserts' => true,
63 63
 				]));
64
-		}catch(Exception $e){
64
+		} catch(Exception $e){
65 65
 			return false;
66 66
 		}
67 67
 		
68 68
 		
69
-		if($value = get_option('xcloner_directories_to_scan_per_request'))
70
-			$this->folders_to_process_per_session = $value;
69
+		if($value = get_option('xcloner_directories_to_scan_per_request')) {
70
+					$this->folders_to_process_per_session = $value;
71
+		}
71 72
 
72 73
 	}
73 74
 	
@@ -130,8 +131,9 @@  discard block
 block discarded – undo
130 131
 	public function get_included_files_handler($metadata  = 0)
131 132
 	{
132 133
 		$path = $this->included_files_handler;
133
-		if(!$metadata)
134
-			return $path;
134
+		if(!$metadata) {
135
+					return $path;
136
+		}
135 137
 		
136 138
 		$spl_info = $this->getMetadataFull('tmp_adapter', $path);
137 139
 		return $spl_info;
@@ -147,31 +149,36 @@  discard block
 block discarded – undo
147 149
 	{
148 150
 		$files = $this->get_backup_archives_list();
149 151
 		
150
-		if(is_array($files))
151
-			$this->sort_by($files, "timestamp","desc");
152
+		if(is_array($files)) {
153
+					$this->sort_by($files, "timestamp","desc");
154
+		}
152 155
 		
153 156
 		$new_list = array();
154 157
 		
155
-		foreach($files as $key=>$file)
156
-			if(!isset($file['parent']))
158
+		foreach($files as $key=>$file) {
159
+					if(!isset($file['parent']))
157 160
 				$new_list[] = ($files[$key]);
161
+		}
158 162
 
159
-		if(isset($new_list[0]))
160
-			return $new_list[0];
163
+		if(isset($new_list[0])) {
164
+					return $new_list[0];
165
+		}
161 166
 	}
162 167
 	
163 168
 	public function get_latest_backups()
164 169
 	{
165 170
 		$files = $this->get_backup_archives_list();
166 171
 
167
-		if(is_array($files))
168
-			$this->sort_by($files, "timestamp","desc");
172
+		if(is_array($files)) {
173
+					$this->sort_by($files, "timestamp","desc");
174
+		}
169 175
 		
170 176
 		$new_list = array();
171 177
 		
172
-		foreach($files as $key=>$file)
173
-			if(!isset($file['parent']))
178
+		foreach($files as $key=>$file) {
179
+					if(!isset($file['parent']))
174 180
 				$new_list[] = ($files[$key]);
181
+		}
175 182
 
176 183
 		return $new_list;
177 184
 	}
@@ -181,25 +188,28 @@  discard block
 block discarded – undo
181 188
 		$files = $this->get_backup_archives_list();
182 189
 		$total = 0;
183 190
 		
184
-		if(is_array($files))
185
-			foreach($files as $file)
191
+		if(is_array($files)) {
192
+					foreach($files as $file)
186 193
 				$total += $file['size'];
194
+		}
187 195
 				
188 196
 		return $total;		
189 197
 	}
190 198
 	
191 199
 	public function is_part($backup_name)
192 200
 	{
193
-		if(stristr($backup_name, "-part"))
194
-			return true;
201
+		if(stristr($backup_name, "-part")) {
202
+					return true;
203
+		}
195 204
 		
196 205
 		return false;	
197 206
 	}
198 207
 	
199 208
 	public function is_multipart($backup_name)
200 209
 	{
201
-		if(stristr($backup_name, "-multipart"))
202
-			return true;
210
+		if(stristr($backup_name, "-multipart")) {
211
+					return true;
212
+		}
203 213
 		
204 214
 		return false;	
205 215
 	}
@@ -210,8 +220,9 @@  discard block
 block discarded – undo
210 220
 		if($this->is_multipart($backup_name))
211 221
 		{
212 222
 			$backup_parts = $this->get_multipart_files($backup_name);
213
-			foreach($backup_parts as $part_file)
214
-				$backup_size += $this->get_storage_filesystem()->getSize($part_file);
223
+			foreach($backup_parts as $part_file) {
224
+							$backup_size += $this->get_storage_filesystem()->getSize($part_file);
225
+			}
215 226
 		}
216 227
 		
217 228
 		return $backup_size;
@@ -252,10 +263,11 @@  discard block
 block discarded – undo
252 263
 			}
253 264
 		}
254 265
 		
255
-		if($this->get_storage_filesystem()->delete($backup_name))
256
-			$return = true;
257
-		else
258
-			$return = false;
266
+		if($this->get_storage_filesystem()->delete($backup_name)) {
267
+					$return = true;
268
+		} else {
269
+					$return = false;
270
+		}
259 271
 			
260 272
 		return $return;	
261 273
 	}
@@ -273,8 +285,9 @@  discard block
 block discarded – undo
273 285
 	{
274 286
 		$list = array();
275 287
 		
276
-		if(method_exists($this->get_storage_filesystem(), "listContents"))
277
-			$list = $this->get_storage_filesystem()->listContents();
288
+		if(method_exists($this->get_storage_filesystem(), "listContents")) {
289
+					$list = $this->get_storage_filesystem()->listContents();
290
+		}
278 291
 
279 292
 		
280 293
 		$backup_files = array();
@@ -287,10 +300,11 @@  discard block
 block discarded – undo
287 300
 			if(isset($file_info['extension']) and $file_info['extension'] == "csv")
288 301
 			{
289 302
 				$lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($file_info['path']));
290
-				foreach($lines as $line)
291
-					if($line)
303
+				foreach($lines as $line) {
304
+									if($line)
292 305
 					{
293 306
 						$data = str_getcsv($line);
307
+				}
294 308
 						if(is_array($data)){
295 309
 							$parents[$data[0]] = $file_info['path'];
296 310
 							$file_info['childs'][] = $data;
@@ -300,14 +314,16 @@  discard block
 block discarded – undo
300 314
 						
301 315
 			}
302 316
 			
303
-			if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions))
304
-				$backup_files[$file_info['path']] = $file_info;
317
+			if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) {
318
+							$backup_files[$file_info['path']] = $file_info;
319
+			}
305 320
 		}
306 321
 		
307 322
 		foreach($backup_files as $key=>$file_info)
308 323
 		{
309
-			if(isset($parents[$file_info['path']]))
310
-				$backup_files[$key]['parent'] = $parents[$file_info['path']];
324
+			if(isset($parents[$file_info['path']])) {
325
+							$backup_files[$key]['parent'] = $parents[$file_info['path']];
326
+			}
311 327
 		}
312 328
 		
313 329
 		return $backup_files;
@@ -333,11 +349,11 @@  discard block
 block discarded – undo
333 349
 				if($counter < $this->folders_to_process_per_session){
334 350
 					$this->build_files_list($file);
335 351
 					$counter++;
336
-				}else{
352
+				} else{
337 353
 					$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n");
338 354
 				}
339 355
 			}
340
-		}else{
356
+		} else{
341 357
 			$this->build_files_list();
342 358
 		}
343 359
 		
@@ -379,8 +395,9 @@  discard block
 block discarded – undo
379 395
 	{
380 396
 		$return = array();
381 397
 		$return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler();
382
-		if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log'))
383
-			$return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
398
+		if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
399
+					$return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
400
+		}
384 401
 		
385 402
 		return $return;
386 403
 	}
@@ -392,9 +409,10 @@  discard block
 block discarded – undo
392 409
 		
393 410
 		$contents = $this->get_tmp_filesystem()->listContents();
394 411
 	
395
-		if(is_array($contents))
396
-		foreach($contents as $file_info)
412
+		if(is_array($contents)) {
413
+				foreach($contents as $file_info)
397 414
 			$this->get_tmp_filesystem()->delete($file_info['path']);
415
+		}
398 416
 			
399 417
 		@rmdir($this->xcloner_settings->get_xcloner_tmp_path());
400 418
 		
@@ -405,17 +423,21 @@  discard block
 block discarded – undo
405 423
 	{
406 424
 		$this->files_counter = 0;
407 425
 		
408
-		if(!$this->storage_filesystem->has("index.html"))	
409
-			$this->storage_filesystem->write("index.html","");
426
+		if(!$this->storage_filesystem->has("index.html")) {
427
+					$this->storage_filesystem->write("index.html","");
428
+		}
410 429
 		
411
-		if(!$this->tmp_filesystem->has("index.html"))	
412
-			$this->tmp_filesystem->write("index.html","");
430
+		if(!$this->tmp_filesystem->has("index.html")) {
431
+					$this->tmp_filesystem->write("index.html","");
432
+		}
413 433
 			
414
-		if($this->tmp_filesystem->has($this->get_included_files_handler()))
415
-			$this->tmp_filesystem->delete($this->get_included_files_handler());
434
+		if($this->tmp_filesystem->has($this->get_included_files_handler())) {
435
+					$this->tmp_filesystem->delete($this->get_included_files_handler());
436
+		}
416 437
 		
417
-		if($this->tmp_filesystem->has($this->get_temp_dir_handler()))	
418
-			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
438
+		if($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
439
+					$this->tmp_filesystem->delete($this->get_temp_dir_handler());
440
+		}
419 441
 	}
420 442
 	
421 443
 	public function get_scanned_files_num()
@@ -435,8 +457,9 @@  discard block
 block discarded – undo
435 457
 	
436 458
 	public function set_excluded_files($excluded_files = array())
437 459
 	{
438
-		if(!is_array($excluded_files))
439
-			$excluded_files = array();
460
+		if(!is_array($excluded_files)) {
461
+					$excluded_files = array();
462
+		}
440 463
 			
441 464
 		$this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
442 465
 		
@@ -470,21 +493,21 @@  discard block
 block discarded – undo
470 493
 				if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path']))
471 494
 				{
472 495
 					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE"));
473
-				}
474
-				elseif(!$matching_pattern = $this->is_excluded($file) ){
496
+				} elseif(!$matching_pattern = $this->is_excluded($file) ){
475 497
 					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE"));
476 498
 					$file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
477 499
 					$this->store_file($file);
478 500
 					$this->files_counter++;
479
-					if(isset($file['size']))
480
-						$this->files_size += $file['size'];
501
+					if(isset($file['size'])) {
502
+											$this->files_size += $file['size'];
503
+					}
481 504
 					
482
-				}else{
505
+				} else{
483 506
 					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE"));
484 507
 					}
485 508
 			}
486 509
 			
487
-		}catch(Exception $e){
510
+		} catch(Exception $e){
488 511
 			
489 512
 			$this->logger->error($e->getMessage());
490 513
 		
@@ -511,7 +534,7 @@  discard block
 block discarded – undo
511 534
 		
512 535
 			$this->tmp_filesystem->delete($tmp_file);
513 536
 		
514
-		}catch(Exception $e){
537
+		} catch(Exception $e){
515 538
 			
516 539
 			$this->logger->error($e->getMessage());
517 540
 			
@@ -532,12 +555,14 @@  discard block
 block discarded – undo
532 555
 		
533 556
 		$files = $this->storage_filesystem->listContents();
534 557
 		
535
-		if(is_array($files))
536
-			foreach($files as $file)
558
+		if(is_array($files)) {
559
+					foreach($files as $file)
537 560
 			{
538 561
 				if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions))
539 562
 				{
540
-					$_storage_size += $file['size']; //bytes
563
+					$_storage_size += $file['size'];
564
+		}
565
+		//bytes
541 566
 					$_backup_files_list[] = $file;
542 567
 				}
543 568
 			}
@@ -551,9 +576,11 @@  discard block
 block discarded – undo
551 576
 		{
552 577
 			//processing rule folder capacity
553 578
 			if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
554
-			$_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))	//bytes	
579
+			$_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) {
580
+				//bytes	
555 581
 			{
556 582
 				$this->storage_filesystem->delete($file['path']);
583
+			}
557 584
 				$_storage_size -= $file['size'];
558 585
 				$this->logger->info("Deleting backup ".$file['path']." matching rule", array("STORAGE SIZE LIMIT", $_storage_size." >= ".$set_storage_limit));
559 586
 			}
@@ -594,34 +621,37 @@  discard block
 block discarded – undo
594 621
 	
595 622
 	public function process_backup_name($name = "", $max_length=100)
596 623
 	{
597
-		if(!$name)
598
-			$name = $this->xcloner_settings->get_default_backup_name();
624
+		if(!$name) {
625
+					$name = $this->xcloner_settings->get_default_backup_name();
626
+		}
599 627
 		
600 628
 		foreach($this->backup_name_tags as $tag)
601 629
 		{
602
-			if($tag == '[time]')
603
-				$name = str_replace($tag, date("Y-m-d_H-i"),$name);
604
-			elseif($tag == '[hostname]')
605
-				$name = str_replace($tag, gethostname() ,$name);	
606
-			elseif($tag == '[domain]')
630
+			if($tag == '[time]') {
631
+							$name = str_replace($tag, date("Y-m-d_H-i"),$name);
632
+			} elseif($tag == '[hostname]') {
633
+							$name = str_replace($tag, gethostname() ,$name);
634
+			} elseif($tag == '[domain]')
607 635
 			{
608 636
 				$domain = parse_url(admin_url(), PHP_URL_HOST);
609 637
 				$name = str_replace($tag, $domain ,$name);	
610 638
 			}
611 639
 		}
612 640
 		
613
-		if($max_length)
614
-			$name = substr($name, 0, $max_length);
641
+		if($max_length) {
642
+					$name = substr($name, 0, $max_length);
643
+		}
615 644
 			
616 645
 		return $name;	
617 646
 	}
618 647
 	
619 648
 	public function sort_by( &$array, $field, $direction = 'asc')
620 649
 	{
621
-		if(strtolower($direction) == "desc" || $direction == SORT_DESC)
622
-			$direction = SORT_DESC;
623
-		else
624
-			$direction = SORT_ASC;
650
+		if(strtolower($direction) == "desc" || $direction == SORT_DESC) {
651
+					$direction = SORT_DESC;
652
+		} else {
653
+					$direction = SORT_ASC;
654
+		}
625 655
 					
626 656
 	   $array = $this->array_orderby($array, $field, $direction);
627 657
 	    
@@ -638,10 +668,11 @@  discard block
 block discarded – undo
638 668
 	            $tmp = array();
639 669
 	            foreach ($data as $key => $row)
640 670
 	            {
641
-					if(is_array($row))
642
-						$tmp[$key] = $row[$field];
643
-					else
644
-						$tmp[$key] = $row->$field;
671
+					if(is_array($row)) {
672
+											$tmp[$key] = $row[$field];
673
+					} else {
674
+											$tmp[$key] = $row->$field;
675
+					}
645 676
 				}
646 677
 	            $args[$n] = $tmp;
647 678
 	            }
@@ -659,28 +690,32 @@  discard block
 block discarded – undo
659 690
 		
660 691
 		if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb'))
661 692
 		{
662
-			if(isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb))
663
-				return "> ".$xcloner_exclude_files_larger_than_mb."MB";
693
+			if(isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) {
694
+							return "> ".$xcloner_exclude_files_larger_than_mb."MB";
695
+			}
664 696
 		}
665 697
 		
666
-		if(!sizeof($this->excluded_files))
667
-			$this->set_excluded_files();
698
+		if(!sizeof($this->excluded_files)) {
699
+					$this->set_excluded_files();
700
+		}
668 701
 				
669
-		if(is_array($this->excluded_files))
670
-		foreach($this->excluded_files as $excluded_file_pattern)
702
+		if(is_array($this->excluded_files)) {
703
+				foreach($this->excluded_files as $excluded_file_pattern)
671 704
 		{
672 705
 			if($excluded_file_pattern == "/")
673 706
 				$needle = "$";
674
-			else
675
-				$needle = "$".$excluded_file_pattern;
707
+		} else {
708
+							$needle = "$".$excluded_file_pattern;
709
+			}
676 710
 				
677 711
 			if(strstr("$".$file['path'], $needle)){
678 712
 				return $excluded_file_pattern;
679 713
 			}
680 714
 		}
681 715
 		
682
-		if( $regex = $this->is_excluded_regex($file))
683
-			return $regex;
716
+		if( $regex = $this->is_excluded_regex($file)) {
717
+					return $regex;
718
+		}
684 719
 		
685 720
 		return false;
686 721
 	}
@@ -734,13 +769,15 @@  discard block
 block discarded – undo
734 769
 			foreach($regex_patterns as $excluded_file_pattern)
735 770
 			{
736 771
 				
737
-				if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r")
738
-					$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1);
772
+				if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") {
773
+									$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1);
774
+				}
739 775
 					
740
-				if($file['path'] == "/")
741
-					$needle = "/";
742
-				else
743
-					$needle = "/".$file['path'];
776
+				if($file['path'] == "/") {
777
+									$needle = "/";
778
+				} else {
779
+									$needle = "/".$file['path'];
780
+				}
744 781
 				//echo $needle."---".$excluded_file_pattern."---\n";
745 782
 				
746 783
 				if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){
@@ -756,10 +793,12 @@  discard block
 block discarded – undo
756 793
 	{
757 794
 		$this->logger->debug(sprintf("Storing %s in the backup list", $file['path']));
758 795
 		
759
-		if(!isset($file['size']))
760
-			$file['size'] = 0;
761
-		if(!isset($file['visibility']))	
762
-			$file['visibility'] = "private";
796
+		if(!isset($file['size'])) {
797
+					$file['size'] = 0;
798
+		}
799
+		if(!isset($file['visibility'])) {
800
+					$file['visibility'] = "private";
801
+		}
763 802
 		
764 803
 		$line = '"'.addslashes($file['path']).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL;
765 804
 		
@@ -768,7 +807,7 @@  discard block
 block discarded – undo
768 807
 		try{
769 808
 			$this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
770 809
 		
771
-		}catch(Exception $e){
810
+		} catch(Exception $e){
772 811
 		
773 812
 			$this->logger->error($e->getMessage());	
774 813
 		}
@@ -776,7 +815,7 @@  discard block
 block discarded – undo
776 815
 		if($file['type'] == "dir"){
777 816
 			try{
778 817
 				$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n");
779
-			}catch(Exception $e){
818
+			} catch(Exception $e){
780 819
 				$this->logger->error($e->getMessage());	
781 820
 			}
782 821
 		}
@@ -789,35 +828,39 @@  discard block
 block discarded – undo
789 828
 	
790 829
 	public function get_filesystem($system = "")
791 830
 	{
792
-		if($system == "storage_filesystem_append")
793
-			return $this->storage_filesystem_append;
794
-		elseif($system == "tmp_filesystem_append")
795
-			return $this->tmp_filesystem_append;
796
-		elseif($system == "tmp_filesystem")
797
-			return $this->tmp_filesystem;
798
-		elseif($system == "storage_filesystem")
799
-			return $this->storage_filesystem;
800
-		else
801
-			return $this->start_filesystem;	
831
+		if($system == "storage_filesystem_append") {
832
+					return $this->storage_filesystem_append;
833
+		} elseif($system == "tmp_filesystem_append") {
834
+					return $this->tmp_filesystem_append;
835
+		} elseif($system == "tmp_filesystem") {
836
+					return $this->tmp_filesystem;
837
+		} elseif($system == "storage_filesystem") {
838
+					return $this->storage_filesystem;
839
+		} else {
840
+					return $this->start_filesystem;
841
+		}
802 842
 	}
803 843
 	
804 844
 	public function get_adapter($system)
805 845
 	{
806
-		if($system == "tmp_filesystem")
807
-			return $this->tmp_adapter;
808
-		elseif($system == "storage_filesystem")
809
-			return $this->storage_adapter;
810
-		else
811
-			return $this->start_adapter;	
846
+		if($system == "tmp_filesystem") {
847
+					return $this->tmp_adapter;
848
+		} elseif($system == "storage_filesystem") {
849
+					return $this->storage_adapter;
850
+		} else {
851
+					return $this->start_adapter;
852
+		}
812 853
 	}
813 854
 	
814 855
 	private function scan_finished()
815 856
 	{
816
-		if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler()))
817
-			return false;
857
+		if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) {
858
+					return false;
859
+		}
818 860
 		
819
-		if($this->tmp_filesystem->has($this->get_temp_dir_handler()))
820
-			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
861
+		if($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
862
+					$this->tmp_filesystem->delete($this->get_temp_dir_handler());
863
+		}
821 864
 		
822 865
 		$this->logger->debug(sprintf(("File scan finished")));
823 866
 			
Please login to merge, or discard this patch.