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

letsdrink / ouzo / 7170637656

11 Dec 2023 04:47PM UTC coverage: 85.672% (-0.3%) from 85.99%
7170637656

push

github

web-flow
Refactored exception/error handlers. (#322)

14 of 30 new or added lines in 6 files covered. (46.67%)

2 existing lines in 1 file now uncovered.

4963 of 5793 relevant lines covered (85.67%)

67.63 hits per line

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

64.71
/src/Ouzo/Core/ExceptionHandling/ErrorHandler.php
1
<?php
2
/*
3
 * Copyright (c) Ouzo contributors, https://github.com/letsdrink/ouzo
4
 * This file is made available under the MIT License (view the LICENSE file for more information).
5
 */
6

7
namespace Ouzo\ExceptionHandling;
8

9
use ErrorException;
10
use Throwable;
11

12
class ErrorHandler
13
{
14
    public function __construct(private readonly ExceptionHandler $exceptionHandler)
15
    {
16
    }
12✔
17

18
    public function register(): void
19
    {
20
        set_exception_handler(fn(Throwable $exception) => $this->handleException($exception));
9✔
21
        set_error_handler(fn(...$args) => $this->handleError(...$args), E_ALL & ~E_DEPRECATED & ~E_STRICT);
12✔
22
        register_shutdown_function(fn() => $this->handleShutdown());
9✔
23
    }
24

25
    public function handleException(Throwable $exception): void
26
    {
27
        $this->exceptionHandler->handleException($exception);
3✔
28
    }
29

30
    public function handleError(int $errorNumber, string $errorString, string $errorFile, int $errorLine): void
31
    {
32
        if ($this->stopsExecution($errorNumber)) {
3✔
NEW
33
            $this->handleException(new ErrorException($errorString, $errorNumber, $errorNumber, $errorFile, $errorLine));
×
34
        } else {
35
            throw new ErrorException($errorString, $errorNumber, $errorNumber, $errorFile, $errorLine);
3✔
36
        }
37
    }
38

39
    public function stopsExecution($errno): bool
40
    {
41
        return match ($errno) {
3✔
42
            E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR => true,
3✔
43
            default => false
3✔
44
        };
3✔
45
    }
46

47
    public function handleShutdown(): void
48
    {
49
        $error = error_get_last();
×
50

NEW
51
        if (!$this->exceptionHandler->lastErrorHandled() && $error && $error['type'] & (E_ERROR | E_USER_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR)) {
×
52
            $stackTrace = new StackTrace($error['file'], $error['line']);
×
53
            $exceptionData = new OuzoExceptionData(500, [new Error(0, $error['message'])], $stackTrace, [], null, $error['type']);
×
NEW
54
            $this->exceptionHandler->handleExceptionData($exceptionData);
×
55
        }
56
    }
57
}
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