Test Failed
Push — master ( 30a29a...0ec979 )
by Federico
01:58
created

Debug::logStack()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
  // requireComponent("../functions/array.php");
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
3
  class Debug {
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...
4
    public static $stack;
5
    private static $initialized = false;
6
    private function __construct() {}
7
    private static function initialize() {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
8
      if (self::$initialized)
9
        return;
10
      self::$stack = [];
11
      self::$initialized = true;
12
    }
13
    private static function out( $_object ) {
14
      if(is_object($_object)) {
15
        echo "isObject";
16
      } else if(is_array($_object)) {
17
        arrayDump($_object, "Debug");
18
      } else {
19
        echo $_object;
20
      }
21
    }
22
    public static function log( $_object ) {
23
      self::out(["error" => $_object]);
24
    }
25
    public static function logln( $_object ) {
26
      self::log($_object);
27
      self::out("<br>");
28
    }
29
    public static function logStack( $_object ) {
30
      self::out([
31
        "position" => self::$stack,
32
        "error" => $_object
33
      ]);
34
      self::out("<br>");
35
    }
36
    public static function push() {
37
      $debugInfo = debug_backtrace();
38
      $debugInfo = [
39
        "file" => $debugInfo[1]["file"],
40
        "line" => $debugInfo[1]["line"],
41
        "function" => $debugInfo[1]["function"],
42
        "class" => $debugInfo[1]["class"]
43
      ];
44
      self::$stack[] = $debugInfo;
45
    }
46
    public static function pop() {
47
      if(count(self::$stack)>0)
48
        self::$stack = array_shift(self::$stack);
49
    }
50
    public static function emptyStack() {
51
      self::$stack = [];
52
    }
53
  }
54
?>
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...
55