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

tempestphp / tempest-framework / 11293799095

11 Oct 2024 02:04PM UTC coverage: 82.102% (-0.03%) from 82.134%
11293799095

Pull #556

github

web-flow
Merge a4adeb52f into c1233aa56
Pull Request #556: fix(phpstan): fix phpstan issues

5 of 9 new or added lines in 3 files covered. (55.56%)

1 existing line in 1 file now uncovered.

6757 of 8230 relevant lines covered (82.1%)

38.47 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

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

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

32
        $contents = ob_get_clean();
×
33

34
        ob_start();
×
35

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

40
        echo $contents;
×
41

42
        ob_end_flush();
×
43
    }
44

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

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

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

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

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

69

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

© 2025 Coveralls, Inc