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

tempestphp / tempest-framework / 11310141859

12 Oct 2024 06:15PM UTC coverage: 82.1% (-0.03%) from 82.134%
11310141859

push

github

web-flow
chore: local defined variables cleanup (#580)

1 of 1 new or added line in 1 file covered. (100.0%)

62 existing lines in 6 files now uncovered.

6770 of 8246 relevant lines covered (82.1%)

38.42 hits per line

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

0.0
/src/Tempest/Http/src/Exceptions/HttpExceptionHandler.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Http\Exceptions;
6

7
use Tempest\Container\Tag;
8
use Tempest\Core\ExceptionHandler;
9
use Tempest\Highlight\Highlighter;
10
use Throwable;
11

12
final class HttpExceptionHandler implements ExceptionHandler
13
{
14
    private ?Throwable $throwable = null;
15

16
    public function __construct(
×
17
        #[Tag('web')]
18
        private readonly Highlighter $highlighter,
19
    ) {
20
    }
×
21

22
    public function handle(Throwable $throwable): void
×
23
    {
24
        $this->throwable = $throwable;
×
25

26
        ob_start();
×
27

28
        ([$this, "getCodeSample"]); // unused
×
29

30
        include __DIR__ . '/exception.php';
×
31

32
        $contents = ob_get_clean();
×
33

34
        ob_start();
×
35

UNCOV
36
        if (! headers_sent()) {
×
UNCOV
37
            http_response_code(500);
×
38
        }
39

40
        echo $contents;
×
41

UNCOV
42
        ob_end_flush();
×
43
    }
44

45
    private function getCodeSample(): string
×
46
    {
47
        $code = $this->highlighter->parse(file_get_contents($this->throwable->getFile()), 'php');
×
UNCOV
48
        $lines = explode(PHP_EOL, $code);
×
49
        $excerptSize = 5;
×
50

UNCOV
51
        foreach ($lines as $i => $line) {
×
52
            $class = 'gutter';
×
53

54
            if ($i + 1 === $this->throwable->getLine()) {
×
UNCOV
55
                $class .= ' selected';
×
UNCOV
56
                $line = '<span class="error-line">' . $line . '</span>';
×
57
            }
58

59
            $lines[$i] = '<span class="' . $class . '">' . str_pad(
×
60
                string: (string) ($i + 1),
×
61
                length: 3,
×
UNCOV
62
                pad_type: STR_PAD_LEFT,
×
UNCOV
63
            ) . '</span>' . $line;
×
64
        }
65

UNCOV
66
        $start = max(0, $this->throwable->getLine() - $excerptSize);
×
UNCOV
67
        $lines = array_slice($lines, $start, $excerptSize * 2);
×
68

69

UNCOV
70
        return implode(PHP_EOL, $lines);
×
71
    }
72
}
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