Test Failed
Push — master ( 014002...9a5747 )
by Federico
01:51
created

Debug::fatal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
  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...
3
    public static $stack;
4
    private static $initialized = false;
5
    private function __construct() {}
6
    private static function initialize() {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
7
      if (self::$initialized)
8
        return;
9
      self::$stack = [];
10
      self::$initialized = true;
11
    }
12
    private static function out( $_object ) {
13
      if(is_object($_object)) {
14
        echo "isObject";
15
      } else if(is_array($_object)) {
16
        arrayDump($_object, "Debug");
17
      } else {
18
        echo $_object;
19
      }
20
    }
21
    public static function error( $_object ) {
22
      self::out(["Error" => $_object]);
23
    }
24
    public static function warning( $_object ) {
25
      self::out(["Warning" => $_object]);
26
    }
27
    public static function fatal( $_object ) {
28
      self::out(["Fatal error" => $_object]);
29
      exit(1);
0 ignored issues
show
Coding Style Compatibility introduced by
The method fatal() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
30
    }
31
    public static function logln( $_object ) {
32
      self::log($_object);
0 ignored issues
show
Bug introduced by
The method log() does not seem to exist on object<Debug>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
      self::out("<br>");
34
    }
35
    public static function logStack( $_object ) {
36
      self::out([
37
        "position" => self::$stack,
38
        "error" => $_object
39
      ]);
40
      self::out("<br>");
41
    }
42
    public static function push() {
43
      $debugInfo = debug_backtrace();
44
      $debugInfo = [
45
        "file" => $debugInfo[1]["file"],
46
        "line" => $debugInfo[1]["line"],
47
        "function" => $debugInfo[1]["function"],
48
        "class" => $debugInfo[1]["class"]
49
      ];
50
      self::$stack[] = $debugInfo;
51
    }
52
    public static function pop() {
53
      if(count(self::$stack)>0)
54
        array_shift(self::$stack);
55
    }
56
    public static function emptyStack() {
57
      self::$stack = [];
58
    }
59
  }
60
?>
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...
61