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 ( 411cd6...1a4d39 )
by Liuta
02:55
created

Xcloner_Logger::__construct()   C

Complexity

Conditions 9
Paths 64

Size

Total Lines 47
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 24
nc 64
nop 2
dl 0
loc 47
rs 5.2941
c 0
b 0
f 0
1
<?php
2
3
use Monolog\Logger;
4
use Monolog\Handler\StreamHandler;
5
use Monolog\Handler\RotatingFileHandler;
6
7
class Xcloner_Logger extends Logger{
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
	
9
	private $logger_path ;
10
	private $max_logger_files = 15;
11
	private $main_logger_url;
12
	
13
	public function __construct($logger_name = "xcloner_logger", $hash="")
14
	{
15
		$xcloner_settings 	= new Xcloner_Settings($hash);
16
		$logger_path 		= $xcloner_settings->get_xcloner_store_path().DS.$xcloner_settings->get_logger_filename();
17
		$logger_path_tmp 	= "";
18
		
19
		if($hash)
20
			$logger_path_tmp = $xcloner_settings->get_xcloner_tmp_path().DS.$xcloner_settings->get_logger_filename(1);
21
		
22
		
23
		$this->logger_path = $logger_path;
24
		//$this->logger_path_tmp = $logger_path_tmp;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
25
		
26
		if(!is_dir($xcloner_settings->get_xcloner_store_path()) or !is_writable($xcloner_settings->get_xcloner_store_path()))
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
27
		{
28
			$logger_path = "php://stderr";
29
			$logger_path_tmp = "";
30
		}
31
		
32
		if(!$xcloner_settings->get_xcloner_option('xcloner_enable_log'))
33
		{
34
			$logger_path = "php://stderr";
35
			$logger_path_tmp = "";
36
		}
37
		
38
		// create a log channel
39
		parent::__construct($logger_name);
40
		
41
		$debug_level = Logger::INFO;
42
		
43
		if(WP_DEBUG)
44
			$debug_level = Logger::DEBUG;
45
46
	
47
		if($logger_path)
48
		{
49
			$stream = new RotatingFileHandler($logger_path, $this->max_logger_files, $debug_level);
50
			$this->pushHandler($stream);
51
			
52
			$this->main_logger_url =  $stream->getUrl();
53
		}
54
			
55
		if($hash and $logger_path_tmp)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
56
			$this->pushHandler(new StreamHandler($logger_path_tmp, $debug_level));
57
		
58
		return $this;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
59
	}
60
	
61
	function get_main_logger_url()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
62
	{
63
		return $this->main_logger_url;
64
	}
65
	
66
	function getLastDebugLines($totalLines = 200) 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
67
	{
68
		$lines = array();
69
		
70
		//if(!file_exists($this->logger_path) or !is_readable($this->logger_path))
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
71
		if(!file_exists($this->main_logger_url) or !is_readable($this->main_logger_url))
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
72
			return false;
73
		
74
		//$fp = fopen($this->logger_path, 'r');
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
75
		$fp = fopen($this->main_logger_url, 'r');
76
		fseek($fp, -1, SEEK_END);
77
		$pos = ftell($fp);
78
		$lastLine = "";
79
		
80
		// Loop backword until we have our lines or we reach the start
81
		while($pos > 0 && count($lines) < $totalLines) {
82
		
83
		$C = fgetc($fp);
84
		if($C == "\n") {
85
		  // skip empty lines
86
		  if(trim($lastLine) != "") {
87
			$lines[] = $lastLine;
88
		  }
89
		  $lastLine = '';
90
		} else {
91
		  $lastLine = $C.$lastLine;
92
		}
93
		fseek($fp, $pos--);
94
		}
95
		
96
		$lines = array_reverse($lines);
97
		
98
		return $lines;
99
	}
100
}
101