Completed
Push — master ( a66420...6394df )
by Steevan
08:32
created

DebugBacktraceConsole::dump()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 3
1
<?php
2
3
use \Symfony\Component\Console\Output\OutputInterface;
4
use \Symfony\Component\Console\Helper\Table;
5
6
class DebugBacktraceConsole extends \DebugBacktrace
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...
7
{
8
    /**
9
     * @param OutputInterface $output
10
     * @param int $offset
11
     * @param int|null $limit
12
     */
13
    public static function dump(OutputInterface $output, $offset = 0, $limit = null)
14
    {
15
        static::writeCaller($output);
16
17
        $table = new Table($output);
18
        $table->setHeaders(['#', 'file', 'line', 'call']);
19
        foreach (static::getBacktraces($offset, $limit) as $index => $backtrace) {
20
            static::writeBacktraceDump($table, $backtrace, $index);
21
        }
22
        $table->render();
23
    }
24
25
    /**
26
     * @param OutputInterface $output
27
     * @param int $offset
28
     * @param int|null $limit
29
     */
30
    public static function eDump(OutputInterface $output, $offset = 0, $limit = null)
31
    {
32
        static::dump($output, $offset + 1, $limit);
33
        exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The method eDump() 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...
34
    }
35
36
    /**
37
     * @param Table $table
38
     * @param array $backtrace
39
     * @param int $index
40
     */
41
    protected static function writeBacktraceDump(Table $table, array $backtrace, $index)
42
    {
43
        $table->addRow([
44
            $index + 1,
45
            static::getFilePath($backtrace['file']),
46
            $backtrace['line'],
47
            $backtrace['call']
48
        ]);
49
    }
50
51
    /** @param OutputInterface $output */
52
    protected static function writeCaller(OutputInterface $output)
53
    {
54
        $caller = static::getCaller();
55
56
        if (is_array($caller)) {
57
            $output->writeln(
58
                'From '
59
                . '<info>' . $caller['file'] . '</info>'
60
                . '<comment>#' . $caller['line'] . '</comment>'
61
            );
62
        } else {
63
            $output->writeln('<error>Unkonw caller</error>');
64
        }
65
    }
66
}
67