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

valkyrjaio / valkyrja / 16185661246

10 Jul 2025 03:48AM UTC coverage: 43.558% (-0.2%) from 43.747%
16185661246

push

github

MelechMizrachi
Http Routing: Updating ListCommand.

0 of 21 new or added lines in 1 file covered. (0.0%)

2913 existing lines in 212 files now uncovered.

3925 of 9011 relevant lines covered (43.56%)

11.07 hits per line

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

9.09
/src/Valkyrja/Exception/ErrorHandler.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <melechmizrachi@gmail.com>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13

14
namespace Valkyrja\Exception;
15

16
use Override;
17
use Throwable;
18
use Valkyrja\Exception\Contract\ErrorHandler as Contract;
19
use Whoops\Handler\JsonResponseHandler;
20
use Whoops\Handler\PrettyPageHandler;
21
use Whoops\Run;
22
use Whoops\Util\Misc;
23

24
use const E_ALL;
25

26
/**
27
 * Class ErrorHandler.
28
 *
29
 * @author Melech Mizrachi
30
 */
31
class ErrorHandler implements Contract
32
{
33
    /**
34
     * Whether debug is enabled or not.
35
     *
36
     * @var bool
37
     */
38
    public static bool $enabled = false;
39

40
    /**
41
     * Enable debug mode.
42
     *
43
     * @param int  $errorReportingLevel [optional] The error reporting level
44
     * @param bool $displayErrors       [optional] Whether to display errors
45
     *
46
     * @return void
47
     */
48
    #[Override]
49
    public static function enable(int $errorReportingLevel = E_ALL, bool $displayErrors = false): void
50
    {
51
        // If debug is already enabled
52
        if (static::$enabled) {
×
53
            // Don't do things twice
UNCOV
54
            return;
×
55
        }
56

57
        // Debug is enabled
58
        static::$enabled = true;
×
59

UNCOV
60
        $run = new Run();
×
61

62
        // We want the error page to be shown by default, if this is a
63
        // regular request, so that's the first thing to go into the stack:
UNCOV
64
        $run->pushHandler(new PrettyPageHandler());
×
65

66
        // Now, we want a second handler that will run before the error page,
67
        // and immediately return an error message in JSON format, if something
68
        // goes awry.
UNCOV
69
        if (Misc::isAjaxRequest()) {
×
UNCOV
70
            $jsonHandler = new JsonResponseHandler();
×
71

72
            // You can also tell JsonResponseHandler to give you a full stack trace:
73
            // $jsonHandler->addTraceToOutput(true);
74

75
            // You can also return a result compliant to the json:api spec
76
            // re: http://jsonapi.org/examples/#error-objects
77
            // tl;dr: error[] becomes errors[[]]
UNCOV
78
            $jsonHandler->setJsonApi(true);
×
79

80
            // And push it into the stack:
UNCOV
81
            $run->pushHandler($jsonHandler);
×
82
        }
83

84
        // That's it! Register Whoops and throw a dummy exception:
UNCOV
85
        $run->register();
×
86
    }
87

88
    /**
89
     * Get trace code for a throwable/exception.
90
     *
91
     * @param Throwable $exception The exception/throwable
92
     *
93
     * @return string
94
     */
95
    #[Override]
96
    public static function getTraceCode(Throwable $exception): string
97
    {
98
        return md5($exception->getTraceAsString());
2✔
99
    }
100
}
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