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\ConsoleOutput; |
||
| 4 | use Symfony\Component\Console\Output\OutputInterface; |
||
| 5 | use Symfony\Component\Console\Helper\Table; |
||
| 6 | |||
| 7 | class DebugBacktraceConsole extends \DebugBacktrace |
||
| 8 | { |
||
| 9 | /** @var ?string */ |
||
| 10 | protected static $callerRemoveFile = __FILE__; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @param OutputInterface $output |
||
| 14 | * @param int $offset |
||
| 15 | * @param int|null $limit |
||
| 16 | */ |
||
| 17 | public static function dump(OutputInterface $output = null, $offset = 0, $limit = null) |
||
| 18 | { |
||
| 19 | $output = static::getOutput($output); |
||
|
0 ignored issues
–
show
|
|||
| 20 | |||
| 21 | static::writeCaller($output); |
||
| 22 | |||
| 23 | $table = new Table($output); |
||
| 24 | $table->setHeaders(['#', 'file', 'line', 'call']); |
||
| 25 | foreach (static::getBacktraces($offset, $limit) as $index => $backtrace) { |
||
| 26 | static::writeBacktraceDump($table, $backtrace, $index); |
||
| 27 | } |
||
| 28 | $table->render(); |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param OutputInterface $output |
||
| 33 | * @param int $offset |
||
| 34 | * @param int|null $limit |
||
| 35 | */ |
||
| 36 | public static function eDump(OutputInterface $output = null, $offset = 0, $limit = null) |
||
| 37 | { |
||
| 38 | static::dump($output, $offset + 1, $limit); |
||
| 39 | exit(); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param Table $table |
||
| 44 | * @param array $backtrace |
||
| 45 | * @param int $index |
||
| 46 | */ |
||
| 47 | protected static function writeBacktraceDump(Table $table, array $backtrace, $index) |
||
| 48 | { |
||
| 49 | $table->addRow([ |
||
| 50 | $index + 1, |
||
| 51 | static::getFilePath($backtrace['file']), |
||
| 52 | $backtrace['line'], |
||
| 53 | $backtrace['call'] |
||
| 54 | ]); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** @param OutputInterface $output */ |
||
| 58 | protected static function writeCaller(OutputInterface $output) |
||
| 59 | { |
||
| 60 | $caller = static::getCaller(); |
||
| 61 | |||
| 62 | if (is_array($caller)) { |
||
| 63 | $output->writeln( |
||
| 64 | 'From ' |
||
| 65 | . '<info>' . $caller['file'] . '</info>' |
||
| 66 | . '<comment>#' . $caller['line'] . '</comment>' |
||
| 67 | ); |
||
| 68 | } else { |
||
| 69 | $output->writeln('<error>Unkonw caller</error>'); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | /** @eturn OutputInterface */ |
||
| 74 | protected static function getOutput(OutputInterface $output) |
||
| 75 | { |
||
| 76 | return $output instanceof OutputInterface ? $output : new ConsoleOutput(); |
||
|
0 ignored issues
–
show
The class
Symfony\Component\Console\Output\OutputInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?
This error could be the result of: 1. Missing dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in if ($x instanceof DoesNotExist) {
// Do something.
}
If you have not tested against this specific condition, such errors might go unnoticed. Loading history...
|
|||
| 77 | } |
||
| 78 | } |
||
| 79 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: