Completed
Push — master ( 7241be...b64a8e )
by Steevan
02:12
created

DebugBacktraceConsole::writeCaller()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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