• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tempestphp / tempest-framework / 14049246919

24 Mar 2025 09:42PM UTC coverage: 79.353% (-0.04%) from 79.391%
14049246919

push

github

web-flow
feat(support): support array parameters in string manipulations (#1073)

48 of 48 new or added lines in 2 files covered. (100.0%)

735 existing lines in 126 files now uncovered.

10492 of 13222 relevant lines covered (79.35%)

90.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

4.17
/src/Tempest/Console/src/Exceptions/ConsoleErrorHandler.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Console\Exceptions;
6

7
use Tempest\Console\Console;
8
use Tempest\Console\ExitCode;
9
use Tempest\Console\HasExitCode;
10
use Tempest\Console\Input\ConsoleArgumentBag;
11
use Tempest\Container\Tag;
12
use Tempest\Core\ErrorHandler;
13
use Tempest\Core\Kernel;
14
use Tempest\Highlight\Escape;
15
use Tempest\Highlight\Highlighter;
16
use Throwable;
17

18
final readonly class ConsoleErrorHandler implements ErrorHandler
19
{
20
    public function __construct(
172✔
21
        private Kernel $kernel,
22
        #[Tag('console')]
23
        private Highlighter $highlighter,
24
        private Console $console,
25
        private ConsoleArgumentBag $argumentBag,
26
    ) {}
172✔
27

UNCOV
28
    public function handleException(Throwable $throwable): void
×
29
    {
UNCOV
30
        ll(exception: $throwable->getMessage());
×
31

UNCOV
32
        $this->console
×
33
            ->writeln()
×
34
            ->error($throwable::class)
×
35
            ->when(
×
36
                condition: $throwable->getMessage(),
×
37
                callback: fn (Console $console) => $console->error($throwable->getMessage()),
×
38
            )
×
39
            ->writeln($this->getSnippet($throwable->getFile(), $throwable->getLine()))
×
40
            ->writeln()
×
41
            ->writeln('<u>' . $throwable->getFile() . ':' . $throwable->getLine() . '</u>')
×
42
            ->writeln();
×
43

UNCOV
44
        if ($this->argumentBag->get('-v') !== null) {
×
45
            foreach ($throwable->getTrace() as $i => $trace) {
×
46
                $this->console->writeln("<style='bold fg-blue'>#{$i}</style> " . $this->formatTrace($trace));
×
47
            }
48

UNCOV
49
            $this->console->writeln();
×
50
        } else {
UNCOV
51
            $firstLine = $throwable->getTrace()[0];
×
52

UNCOV
53
            $this->console
×
54
                ->writeln('<style="fg-blue bold">#0</style> ' . $this->formatTrace($firstLine))
×
55
                ->writeln()
×
56
                ->writeln('<em>-v</em> show more')
×
57
                ->writeln();
×
58
        }
59

UNCOV
60
        $exitCode = ($throwable instanceof HasExitCode) ? $throwable->getExitCode() : ExitCode::ERROR;
×
61

UNCOV
62
        $this->kernel->shutdown($exitCode->value);
×
63
    }
64

UNCOV
65
    public function handleError(int $errNo, string $errstr, string $errFile, int $errLine): void
×
66
    {
UNCOV
67
        ll(error: $errstr);
×
68

UNCOV
69
        $this->console
×
70
            ->writeln()
×
71
            ->error($errstr)
×
72
            ->writeln($this->getSnippet($errFile, $errLine));
×
73
    }
74

UNCOV
75
    private function getSnippet(string $file, int $lineNumber): string
×
76
    {
UNCOV
77
        $highlighter = $this->highlighter->withGutter();
×
78
        $code = Escape::terminal($highlighter->parse(file_get_contents($file), 'php'));
×
79
        $lines = explode(PHP_EOL, $code);
×
80

UNCOV
81
        $lines[$lineNumber - 1] = $lines[$lineNumber - 1] . ' <style="fg-red"><</style>';
×
82

UNCOV
83
        $excerptSize = 5;
×
84
        $start = max(0, ($lineNumber - $excerptSize) - 2);
×
85
        $lines = array_slice($lines, $start, $excerptSize * 2);
×
86

UNCOV
87
        return PHP_EOL . implode(PHP_EOL, $lines);
×
88
    }
89

UNCOV
90
    private function formatTrace(mixed $trace): string
×
91
    {
UNCOV
92
        if (isset($trace['file'])) {
×
93
            return '<u>' . $trace['file'] . ':' . $trace['line'] . '</u>';
×
94
        }
95

UNCOV
96
        if (isset($trace['class'])) {
×
97
            return $trace['class'] . $trace['type'] . $trace['function'];
×
98
        }
99

UNCOV
100
        return $trace['function'] . '()';
×
101
    }
102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc