Completed
Push — master ( 5f5fca...2fa1e0 )
by Bjørn
12:28 queued 02:24
created

WarningsIntoExceptions::deactivate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WebPConvert\Helpers;
4
5
use WebPConvert\Exceptions\WarningException;
6
7
abstract class WarningsIntoExceptions
8
{
9
10 2
    public static function warningHandler($errno, $errstr, $errfile, $errline)
11
    {
12 2
        throw new WarningException(
13 2
            'A warning was issued',
14 2
            'A warning was issued: ' . ': ' . $errstr . ' in ' . $errfile . ', line ' . $errline .
15 2
                ', PHP ' . PHP_VERSION .
16 2
                ' (' . PHP_OS . ')'
17 2
        );
18
19
        /* Don't execute PHP internal error handler */
20
        // return true;     // commented out (unreachable)
21
    }
22
23 2
    public static function activate()
24
    {
25 2
        set_error_handler(
26 2
            array('\\WebPConvert\\Helpers\\WarningsIntoExceptions', "warningHandler"),
27 2
            E_WARNING | E_USER_WARNING
28 2
        );   // E_USER_WARNING  E_ALL
29 2
    }
30
31
    public static function deactivate()
32
    {
33
        restore_error_handler();
34
    }
35
}
36