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

WarningsIntoExceptions   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 27
ccs 13
cts 15
cp 0.8667
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A deactivate() 0 3 1
A activate() 0 5 1
A warningHandler() 0 7 1
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