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.

ErrorException::getStringSeverity()   C
last analyzed

Complexity

Conditions 16
Paths 16

Size

Total Lines 36
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 32
c 1
b 0
f 0
dl 0
loc 36
rs 5.5666
cc 16
nc 16
nop 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
 * This file is part of the O2System Framework 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
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Spl\Exceptions;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Spl\Exceptions\Abstracts\AbstractException;
19
20
/**
21
 * Class ErrorException
22
 *
23
 * ErrorException is the wrapper class of the predefined exceptions PHP Error class.
24
 *
25
 * @see     http://php.net/manual/en/class.error.php
26
 *
27
 * @package O2System\Spl\Exceptions\Logic
28
 */
29
class ErrorException extends AbstractException
30
{
31
    /**
32
     * ErrorException::$severity
33
     *
34
     * The severity of the error exception.
35
     *
36
     * @var int
37
     */
38
    protected $severity;
39
40
    // ------------------------------------------------------------------------
41
42
    /**
43
     * ErrorException::__construct
44
     *
45
     * @param string          $message
46
     * @param array|int       $severity
47
     * @param string          $filename
48
     * @param int             $line
49
     * @param \Exception|null $previous
50
     */
51
    public function __construct(
52
        $message = '',
53
        $severity = 1,
54
        $filename = '',
55
        $line = 0,
56
        $context = []
57
    ) {
58
        $this->severity = $severity;
0 ignored issues
show
Documentation Bug introduced by
It seems like $severity can also be of type array. However, the property $severity is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
59
        $this->file = $filename;
60
        $this->line = $line;
61
62
        if (class_exists('O2System\Kernel', false)) {
63
            if (is_array($context)) {
64
                $message = language()->getLine($message, $context);
0 ignored issues
show
Bug introduced by
The function language was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
                $message = /** @scrutinizer ignore-call */ language()->getLine($message, $context);
Loading history...
65
            } else {
66
                $message = language()->getLine($message);
67
            }
68
        }
69
70
        parent::__construct($message, 0, []);
71
    }
72
73
    // ------------------------------------------------------------------------
74
75
    /**
76
     * ErrorException::getSeverity
77
     *
78
     * Gets the exception severity.
79
     *
80
     * @return int
81
     */
82
    public function getSeverity()
83
    {
84
        return $this->severity;
85
    }
86
87
    // ------------------------------------------------------------------------
88
89
    /**
90
     * ErrorException::getStringSeverity
91
     *
92
     * Gets the exception severity string.
93
     *
94
     * @return string
95
     */
96
    public function getStringSeverity()
97
    {
98
        switch ($this->severity) {
99
            case E_ERROR: // 1 //
100
                return 'E_ERROR';
101
            case E_WARNING: // 2 //
102
                return 'E_WARNING';
103
            case E_PARSE: // 4 //
104
                return 'E_PARSE';
105
            case E_NOTICE: // 8 //
106
                return 'E_NOTICE';
107
            case E_CORE_ERROR: // 16 //
108
                return 'E_CORE_ERROR';
109
            case E_CORE_WARNING: // 32 //
110
                return 'E_CORE_WARNING';
111
            case E_COMPILE_ERROR: // 64 //
112
                return 'E_COMPILE_ERROR';
113
            case E_COMPILE_WARNING: // 128 //
114
                return 'E_COMPILE_WARNING';
115
            case E_USER_ERROR: // 256 //
116
                return 'E_USER_ERROR';
117
            case E_USER_WARNING: // 512 //
118
                return 'E_USER_WARNING';
119
            case E_USER_NOTICE: // 1024 //
120
                return 'E_USER_NOTICE';
121
            case E_STRICT: // 2048 //
122
                return 'E_STRICT';
123
            case E_RECOVERABLE_ERROR: // 4096 //
124
                return 'E_RECOVERABLE_ERROR';
125
            case E_DEPRECATED: // 8192 //
126
                return 'E_DEPRECATED';
127
            case E_USER_DEPRECATED: // 16384 //
128
                return 'E_USER_DEPRECATED';
129
        }
130
131
        return '';
132
    }
133
}