Passed
Push — master ( d71956...442876 )
by Felipe
07:09 queued 03:12
created

HelperTrait::statictrace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 16
rs 9.4285
1
<?php
2
namespace PHPPgAdmin;
1 ignored issue
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
4
trait HelperTrait
1 ignored issue
show
Coding Style introduced by
Missing class doc comment
Loading history...
5
{
6
7
    /**
8
     * Halts the execution of the program. It's like calling exit() but using builtin Slim Exceptions
9
     *
10
     * @param string  $msg  The message to show to the user
11
     *
12
     * @throws \Slim\Exception\SlimException  (description)
13
     */
14
    public function halt($msg = 'An error has happened')
15
    {
16
        $body = $this->container->responseobj->getBody();
17
        $body->write($msg);
18
        throw new \Slim\Exception\SlimException($this->container->requestobj, $this->container->responseobj);
19
    }
20
21
    /**
22
     * Receives N parameters and sends them to the console adding where was it called from
23
     * @return null
24
     */
25
    public function prtrace()
26
    {
27
        $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
28
29
        $btarray0 = ([
30
            /*'class0'    => $backtrace[3]['class'],
31
            'type0'     => $backtrace[3]['type'],
32
            'function0' => $backtrace[3]['function'],
33
            'spacer0'   => ' ',
34
            'line0'     => $backtrace[2]['line'],
35
36
            'spacer1'   => "\n",
37
38
            'class1'    => $backtrace[2]['class'],
39
            'type1'     => $backtrace[2]['type'],
40
            'function1' => $backtrace[2]['function'],
41
            'spacer2'   => ' ',
42
            'line1'     => $backtrace[1]['line'],
43
44
            'spacer3'   => "\n",*/
45
46
            'class2'    => $backtrace[1]['class'],
47
            'type2'     => $backtrace[1]['type'],
48
            'function2' => $backtrace[1]['function'],
49
            'spacer4'   => ' ',
50
            'line2'     => $backtrace[0]['line'],
51
        ]);
52
53
        $tag = implode('', $btarray0);
54
55
        \PC::debug(func_get_args(), $tag);
56
        return;
57
    }
58
59
    /**
60
     * Receives N parameters and sends them to the console adding where was it
61
     * called from
62
     * @return null
63
     */
64
    public static function statictrace()
65
    {
66
        $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
67
68
        $btarray0 = ([
69
            'class'    => $backtrace[1]['class'],
70
            'type'     => $backtrace[1]['type'],
71
            'function' => $backtrace[1]['function'],
72
            'spacer'   => ' ',
73
            'line'     => $backtrace[0]['line'],
74
        ]);
75
76
        $tag = implode('', $btarray0);
77
78
        \PC::debug(func_get_args(), $tag);
79
        return;
80
    }
81
82
    /**
83
     * Returns a string with html <br> variant replaced with a new line
84
     *
85
     * @param string  $msg  message to convert
86
     *
87
     * @return string  converted message
88
     */
89
    public static function br2ln(string $msg)
90
    {
91
        return str_replace(['<br>', '<br/>', '<br />'], "\n", $msg);
92
    }
93
}
94