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