Passed
Push — master ( 87c986...d487cc )
by Adrian Florin
02:23
created

ErrorHandler::restoreErrorHandler()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of the NeedleProject\FileIo package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
namespace NeedleProject\FileIo\Util;
9
10
use NeedleProject\FileIo\Exception\IOException;
11
12
/**
13
 * Class ErrorHandler
14
 *
15
 * @package NeedleProject\FileIo\Util
16
 * @author Adrian Tilita <[email protected]>
17
 * @copyright 2016-2017 Adrian Tilita
18
 * @license https://opensource.org/licenses/MIT MIT Licence
19
 */
20
class ErrorHandler
0 ignored issues
show
Coding Style introduced by
ErrorHandler does not seem to conform to the naming convention (Utils?$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
21
{
22
    /**
23
     * States that the current object is the current error handler
24
     * @var bool
25
     */
26
    protected static $isHandledLocal = false;
27
28
    /**
29
     * @param int|null $level   The error level to be handled
30
     */
31 4
    public static function convertErrorsToExceptions(int $level = null)
32
    {
33 4
        static::$isHandledLocal = true;
34 4
        if (is_null($level)) {
35 4
            $level = E_ALL;
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $level. This often makes code more readable.
Loading history...
36
        }
37 4
        set_error_handler(function ($errorNumber, $errorMessage, $errorFile, $errorLine, $errorContext) {
0 ignored issues
show
Unused Code introduced by
The parameter $errorFile is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $errorLine is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $errorContext is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38 1
            throw new IOException($errorMessage, $errorNumber);
39 4
        }, $level);
40 4
    }
41
42
    /**
43
     * Restore predefined error handlers
44
     */
45 3
    public static function restoreErrorHandler()
46
    {
47 3
        if (true === static::$isHandledLocal) {
48 3
            \restore_error_handler();
49
        }
50 3
    }
51
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
52