steevanb /
php-backtrace
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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
|
|||
| 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
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 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 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.