This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | $defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1; |
||
3 | |||
4 | /** |
||
5 | * This file defines the debug class used in this site to enable |
||
6 | * verbose deugging outout. |
||
7 | * @package debug |
||
8 | * @author Sebastian 'Seraph' Grewe |
||
9 | * @copyright Sebastian Grewe |
||
10 | * @version 1.0 |
||
11 | * */ |
||
12 | class Debug { |
||
13 | |||
14 | /** |
||
15 | * @var integer $DEBUG enable (1) or disable (0) debugging |
||
16 | */ |
||
17 | private $DEBUG; |
||
18 | |||
19 | /** |
||
20 | * @var array $debugInfo Data array with debugging information |
||
21 | */ |
||
22 | private $arrDebugInfo; |
||
23 | |||
24 | /** |
||
25 | * @var float $startTime Start time of our debugger |
||
26 | */ |
||
27 | private $floatStartTime; |
||
28 | |||
29 | /** |
||
30 | * Construct our class |
||
31 | * @param integer $DEBUG [optional] Enable (>=1) or disable (0) debugging |
||
32 | * @return none |
||
0 ignored issues
–
show
|
|||
33 | */ |
||
34 | function __construct($log, $DEBUG=0) { |
||
35 | $this->log = $log; |
||
36 | $this->DEBUG = $DEBUG; |
||
37 | if ($DEBUG >= 1) { |
||
38 | $this->floatStartTime = microtime(true); |
||
39 | $this->append("Debugging enabled", 1); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * If we want to set our debugging level in a child class this allows us to do so |
||
45 | * @param integer $DEBUG our debugging level |
||
46 | */ |
||
47 | function setDebug($DEBUG) { |
||
0 ignored issues
–
show
|
|||
48 | $this->DEBUG = $DEBUG; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * Return a backtrace strin |
||
53 | * @return string Full backtrace <file>:<line> but no refereces to debug class |
||
54 | */ |
||
55 | public function getBacktrace() { |
||
56 | $bth = debug_backtrace(); |
||
57 | while (strpos($bth[0]['file'], "classes/debug") != false) array_shift($bth); |
||
0 ignored issues
–
show
|
|||
58 | foreach ($bth as $x) { |
||
59 | $backtrace[] = array( |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$backtrace was never initialized. Although not strictly required by PHP, it is generally a good practice to add $backtrace = 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 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...
|
|||
60 | 'file' => substr($x['file'], strrpos($x['file'], '/') + 1), |
||
61 | 'line' => $x['line'], |
||
62 | 'function' => $x['function'], |
||
63 | ); |
||
64 | } |
||
65 | return $backtrace; |
||
0 ignored issues
–
show
The variable
$backtrace does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
66 | } |
||
67 | |||
68 | /** |
||
69 | * We fill our data array here |
||
70 | * @param string $msg Debug Message |
||
71 | * @param string $file [optional] File name |
||
72 | * @param integer $line [optional] Line inside the $file |
||
0 ignored issues
–
show
There is no parameter named
$line . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not.
Loading history...
|
|||
73 | * @param integer $debug [optional] Debugging level, default 1 |
||
74 | * @param string $class [optional] Class this is called from |
||
75 | * @param string $method [optional] Method this is called from |
||
0 ignored issues
–
show
There is no parameter named
$method . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not.
Loading history...
|
|||
76 | * @return none |
||
77 | */ |
||
78 | function append($msg, $debug=1) { |
||
0 ignored issues
–
show
|
|||
79 | if ($this->DEBUG >= $debug) { |
||
80 | $this->arrDebugInfo[] = array( |
||
81 | 'level' => $debug, |
||
82 | 'time' => round((microtime(true) - $this->floatStartTime) * 1000, 2), |
||
83 | 'backtrace' => $this->getBacktrace(), |
||
84 | 'message' => $msg, |
||
85 | ); |
||
86 | $this->log->log("debug", $msg); |
||
87 | } |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Return the created strDebugInfo array |
||
92 | * @return none |
||
93 | */ |
||
94 | public function getDebugInfo() { |
||
95 | return $this->arrDebugInfo; |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Directly print the debugging information, table formatted |
||
100 | * @return none |
||
101 | */ |
||
102 | function printDebugInfo() { |
||
0 ignored issues
–
show
|
|||
103 | echo "<table><tr><td>Timestamp</td><td>File</td><td>Line</td><td>Class</td><td>Method</td><td>Message</td></tr>"; |
||
104 | foreach ($this->getDebugInfo() as $content) { |
||
105 | echo "<tr><td>" . $content['time'] . "</td><td>" . $content['backtrace'] . "</td><td>" . $content['message'] . "</td></tr>"; |
||
106 | } |
||
107 | echo "</table>"; |
||
108 | } |
||
109 | |||
110 | } |
||
111 | |||
112 | // Instantiate this class |
||
113 | $debug = new Debug($log, $config['DEBUG']); |
||
114 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.