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.

ErrorCollectorTrait::getLatestErrorCode()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
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\Traits\Collectors;
15
16
// ------------------------------------------------------------------------
17
18
/**
19
 * Trait ErrorCollectorTrait
20
 * @package O2System\Spl\Traits\Collectors
21
 */
22
trait ErrorCollectorTrait
23
{
24
    /**
25
     * ErrorCollectorTrait::$errors
26
     *
27
     * List of errors.
28
     *
29
     * @var array
30
     */
31
    protected $errors = [];
32
33
    // ------------------------------------------------------------------------
34
35
    /**
36
     * ErrorCollectorTrait::getErrors
37
     *
38
     * Gets errors.
39
     *
40
     * @return array
41
     */
42
    public function getErrors()
43
    {
44
        return $this->errors;
45
    }
46
47
    // ------------------------------------------------------------------------
48
49
    /**
50
     * ErrorCollectorTrait::setErrors
51
     *
52
     * Sets errors.
53
     *
54
     * @param array $errors
55
     */
56
    public function setErrors(array $errors)
57
    {
58
        $this->errors = $errors;
59
    }
60
61
    // ------------------------------------------------------------------------
62
63
    /**
64
     * ErrorCollectorTrait::hasErrors
65
     *
66
     * @return bool
67
     */
68
    public function hasErrors()
69
    {
70
        return (bool)count($this->errors) ? true : false;
71
    }
72
73
    // ------------------------------------------------------------------------
74
75
    /**
76
     * ErrorCollectorTrait::getLatestErrorMessage
77
     *
78
     * Returns latest error message.
79
     *
80
     * @return string|bool Returns FALSE if Failed.
81
     */
82
    public function getLatestErrorMessage()
83
    {
84
        if (count($this->errors)) {
85
            return end($this->errors);
86
        }
87
88
        return false;
89
    }
90
91
    // ------------------------------------------------------------------------
92
93
    /**
94
     * ErrorCollectorTrait::getLatestErrorCode
95
     *
96
     * Returns latest error code.
97
     *
98
     * @return int|bool Returns FALSE if Failed.
99
     */
100
    public function getLatestErrorCode()
101
    {
102
        if (count($this->errors)) {
103
            end($this->errors);
104
105
            return key($this->errors);
0 ignored issues
show
Bug Best Practice introduced by
The expression return key($this->errors) also could return the type string which is incompatible with the documented return type boolean|integer.
Loading history...
106
        }
107
108
        return false;
109
    }
110
111
    // ------------------------------------------------------------------------
112
113
    /**
114
     * ErrorCollectorTrait::addErrors
115
     *
116
     * Adds errors.
117
     *
118
     * @param array $errors
119
     */
120
    public function addErrors(array $errors)
121
    {
122
        foreach ($errors as $code => $message) {
123
            $this->addError($code, $message);
124
        }
125
    }
126
127
    // ------------------------------------------------------------------------
128
129
    /**
130
     * ErrorCollectorTrait::addError
131
     *
132
     * Add error.
133
     *
134
     * @param int    $code    Error code.
135
     * @param string $message Error message.
136
     */
137
    public function addError($code, $message)
138
    {
139
        if(class_exists('\O2System\Kernel')) {
140
            $this->errors[ $code ] = language($message);
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

140
            $this->errors[ $code ] = /** @scrutinizer ignore-call */ language($message);
Loading history...
141
        } else {
142
            $this->errors[ $code ] = $message;
143
        }
144
    }
145
}