ErrorHandler::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 4
1
<?php
2
3
/*
4
 * This file is part of Bowerphp.
5
 *
6
 * (c) Massimiliano Arione <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Bowerphp\Util;
13
14
use ErrorException;
15
16
/**
17
 * Convert PHP errors into exceptions
18
 * Copied by Composer https://github.com/composer/composer
19
 */
20
class ErrorHandler
21
{
22
    /**
23
     * Error handler
24
     *
25
     * @param int    $level   Level of the error raised
26
     * @param string $message Error message
27
     * @param string $file    Filename that the error was raised in
28
     * @param int    $line    Line number the error was raised at
29
     *
30
     * @static
31
     * @throws \ErrorException
32
     */
33
    public static function handle($level, $message, $file, $line)
34
    {
35
        // respect error_reporting being disabled
36
        if (0 === error_reporting()) {
37
            return;
38
        }
39
40
        if (ini_get('xdebug.scream')) {
41
            $message .= "\n\nWarning: You have xdebug.scream enabled, the warning above may be" .
42
            "\na legitimately suppressed error that you were not supposed to see.";
43
        }
44
45
        throw new ErrorException($message, 0, $level, $file, $line);
46
    }
47
48
    /**
49
     * Register error handler
50
     *
51
     * @static
52
     */
53
    public static function register()
54
    {
55
        set_error_handler([__CLASS__, 'handle']);
56
    }
57
}
58