Passed
Push — master ( 442876...4ec1bc )
by Felipe
15:55 queued 10:33
created

src/classes/HelperTrait.php (6 issues)

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