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.
Passed
Push — master ( b0ac08...e58886 )
by Sergii
01:56
created

BadFunctionDefinitionException::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 14
cts 14
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 14
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Reflection\Validator\Exception;
4
5
/**
6
 * An exception for marking a definition of function/method as unacceptable.
7
 */
8
class BadFunctionDefinitionException extends \ReflectionException implements \ArrayAccess
9
{
10
    /**
11
     * Global tokens to replace in error messages.
12
     *
13
     * @var string[]
14
     */
15
    private $tokens = [];
16
    /**
17
     * A list of error messages.
18
     *
19
     * @var string[]
20
     */
21
    private $errors = [];
22
23
    /**
24
     * BadFunctionDefinitionException constructor.
25
     *
26
     * @param \ReflectionFunctionAbstract $function
27
     *   A function/method to collect violations for.
28
     *
29
     * @throws self
30
     *   When argument is not of "ReflectionMethod" or "ReflectionFunction" type.
31
     */
32 18
    public function __construct(\ReflectionFunctionAbstract $function)
33
    {
34 18
        parent::__construct();
35
36 18
        if ($function instanceof \ReflectionMethod) {
37 16
            $this->tokens['@function'] = sprintf('"%s::%s()" method', $function->class, $function->name);
38 2
        } elseif ($function instanceof \ReflectionFunction) {
39 1
            $this->tokens['@function'] = sprintf('"%s()" function', $function->name);
40
        } else {
41 1
            $this->message = sprintf(
42 1
                'The argument of the "%s()" must be of "%s" or "%s" type, "%s" given.',
43 1
                __METHOD__,
44 1
                \ReflectionMethod::class,
45 1
                \ReflectionFunction::class,
46 1
                get_class($function)
47
            );
48
49 1
            throw $this;
50
        }
51 17
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 2
    public function offsetExists($token)
57
    {
58 2
        return isset($this->tokens[$token]);
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 2
    public function offsetGet($token)
65
    {
66 2
        return $this->tokens[$token];
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 14
    public function offsetSet($token, $value)
73
    {
74 14
        $this->tokens[$token] = $value;
75 14
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80 2
    public function offsetUnset($token)
81
    {
82 2
        unset($this->tokens[$token]);
83 2
    }
84
85
    /**
86
     * Adds an error message to the list.
87
     *
88
     * @param string $message
89
     *   A message to add.
90
     * @param string[] $tokens
91
     *   An array of additional tokens to replace in a message.
92
     */
93 16
    public function addError(string $message, array $tokens = [])
94
    {
95 16
        $this->errors[] = strtr($message, $this->tokens + $tokens);
96 16
    }
97
98
    /**
99
     * Returns a list of error messages.
100
     *
101
     * @return string[]
102
     *   A list of error messages.
103
     */
104 17
    public function getErrors(): array
105
    {
106 17
        return $this->errors;
107
    }
108
109
    /**
110
     * Throws an instance of self in a case when errors list is not empty.
111
     *
112
     * @throws self
113
     */
114 17
    public function throwIfErrorsExist()
115
    {
116 17
        if (!empty($this->errors)) {
117 16
            $this->tokens = [];
118 16
            $this->message = implode(PHP_EOL, $this->errors);
119
120 16
            throw $this;
121
        }
122 3
    }
123
}
124