Passed
Pull Request — master (#4583)
by Owen
12:05
created

suppressPhp85()   C

Complexity

Conditions 12
Paths 7

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 12
eloc 12
nc 7
nop 3
dl 0
loc 21
rs 6.9666
c 1
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
setlocale(LC_ALL, 'en_US.utf8');
6
7
function phpunit10ErrorHandler(int $errno, string $errstr, string $filename, int $lineno): bool
8
{
9
    if ($errno === E_DEPRECATED && suppressPhp85(PHP_VERSION_ID, $filename, $lineno)) {
10
        return true;
11
    }
12
    $x = error_reporting() & $errno;
13
    if (
14
        in_array(
15
            $errno,
16
            [
17
                E_DEPRECATED,
18
                E_WARNING,
19
                E_NOTICE,
20
                E_USER_DEPRECATED,
21
                E_USER_NOTICE,
22
                E_USER_WARNING,
23
            ],
24
            true
25
        )
26
    ) {
27
        if (0 === $x) {
28
            return true; // message suppressed - stop error handling
29
        }
30
31
        throw new Exception("$errstr $filename $lineno");
32
    }
33
34
    return false; // continue error handling
35
}
36
37
function suppressPhp85(int $version, string $filename, int $lineno): bool
38
{
39
    if ($version >= 80500) {
40
        if (str_ends_with($filename, 'jpgraph.php') && $lineno === 1408) {
41
            return true;
42
        }
43
        if (str_ends_with($filename, 'jpgraph_legend.inc.php') && $lineno === 174) {
44
            return true;
45
        }
46
        if (str_ends_with($filename, 'jpgraph_regstat.php') && in_array($lineno, [155, 185, 198, 202], true)) {
47
            return true;
48
        }
49
        if (str_ends_with($filename, 'AttributeTranslator.php') && $lineno === 506) {
50
            return true;
51
        }
52
        if (str_ends_with($filename, 'functions.php') && $lineno === 300) {
53
            return true;
54
        }
55
    }
56
57
    return false;
58
}
59
60
if (!method_exists(PHPUnit\Framework\TestCase::class, 'setOutputCallback')) {
61
    set_error_handler('phpunit10ErrorHandler');
62
}
63