GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#1)
by Šimon
29:17 queued 25:57
created

Warning::warnOnce()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 5.583

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 7
cp 0.7143
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 6
nc 3
nop 3
crap 5.583
1
<?php
2
3
namespace GraphQL\Error;
4
5
/**
6
 * Encapsulates warnings produced by the library.
7
 *
8
 * Warnings can be suppressed (individually or all) if required.
9
 * Also it is possible to override warning handler (which is **trigger_error()** by default)
10
 */
11
final class Warning
12
{
13
    const WARNING_ASSIGN             = 2;
14
    const WARNING_CONFIG             = 4;
15
    const WARNING_FULL_SCHEMA_SCAN   = 8;
16
    const WARNING_CONFIG_DEPRECATION = 16;
17
    const WARNING_NOT_A_TYPE         = 32;
18
    const ALL                        = 63;
19
20
    static $enableWarnings = self::ALL;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $enableWarnings.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
21
22
    static $warned = [];
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $warned.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
23
24
    static private $warningHandler;
25
26
    /**
27
     * Sets warning handler which can intercept all system warnings.
28
     * When not set, trigger_error() is used to notify about warnings.
29
     *
30
     * @api
31
     * @param callable|null $warningHandler
32
     */
33
    public static function setWarningHandler(callable $warningHandler = null)
34
    {
35
        self::$warningHandler = $warningHandler;
36
    }
37
38
    /**
39
     * Suppress warning by id (has no effect when custom warning handler is set)
40
     *
41
     * Usage example:
42
     * Warning::suppress(Warning::WARNING_NOT_A_TYPE)
43
     *
44
     * When passing true - suppresses all warnings.
45
     *
46
     * @api
47
     * @param bool|int $suppress
48
     */
49 68
    static function suppress($suppress = true)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
50
    {
51 68
        if (true === $suppress) {
52
            self::$enableWarnings = 0;
53 68
        } elseif (false === $suppress) {
54
            self::$enableWarnings = self::ALL;
55
        } else {
56 68
            $suppress             = (int) $suppress;
57 68
            self::$enableWarnings &= ~$suppress;
58
        }
59 68
    }
60
61
    /**
62
     * Re-enable previously suppressed warning by id
63
     *
64
     * Usage example:
65
     * Warning::suppress(Warning::WARNING_NOT_A_TYPE)
66
     *
67
     * When passing true - re-enables all warnings.
68
     *
69
     * @api
70
     * @param bool|int $enable
71
     */
72 68
    public static function enable($enable = true)
73
    {
74 68
        if (true === $enable) {
75
            self::$enableWarnings = self::ALL;
76 68
        } elseif (false === $enable) {
77
            self::$enableWarnings = 0;
78
        } else {
79 68
            $enable               = (int) $enable;
80 68
            self::$enableWarnings |= $enable;
81
        }
82 68
    }
83
84 5
    static function warnOnce($errorMessage, $warningId, $messageLevel = null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
85
    {
86 5
        if (self::$warningHandler) {
87
            $fn = self::$warningHandler;
88
            $fn($errorMessage, $warningId);
89 5
        } elseif ((self::$enableWarnings & $warningId) > 0 && ! isset(self::$warned[$warningId])) {
90 1
            self::$warned[$warningId] = true;
91 1
            trigger_error($errorMessage, $messageLevel ?: E_USER_WARNING);
92
        }
93 5
    }
94
95
    static function warn($errorMessage, $warningId, $messageLevel = null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
96
    {
97
        if (self::$warningHandler) {
98
            $fn = self::$warningHandler;
99
            $fn($errorMessage, $warningId);
100
        } elseif ((self::$enableWarnings & $warningId) > 0) {
101
            trigger_error($errorMessage, $messageLevel ?: E_USER_WARNING);
102
        }
103
    }
104
}
105