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.

Issues (3)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/BigInteger.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace PHP\Math\BigInteger;
4
5
use GMP;
6
use InvalidArgumentException;
7
use RuntimeException;
8
9
/**
10
 * A big integer value.
11
 */
12
class BigInteger
13
{
14
    /**
15
     * The value represented as a string.
16
     *
17
     * @var string
18
     */
19
    private $value;
20
21
    /**
22
     * A flag that indicates whether or not the state of this object can be changed.
23
     *
24
     * @var bool
25
     */
26
    private $mutable;
27
28
    /**
29
     * Initializes a new instance of this class.
30
     *
31
     * @param string|int|BigInteger $value The value to set.
32
     * @param bool $mutable Whether or not the state of this object can be changed.
33
     */
34 67
    public function __construct($value = 0, $mutable = true)
35
    {
36 67
        $this->internalSetValue($value);
37
38 66
        $this->mutable = $mutable;
39 66
    }
40
41
    /**
42
     * Gets the value of the big integer.
43
     *
44
     * @return string
45
     */
46 52
    public function getValue()
47
    {
48 52
        return gmp_strval($this->value);
49
    }
50
51
    /**
52
     * Sets the value.
53
     *
54
     * @param string $value The value to set.
55
     * @return BigInteger
56
     */
57 5
    public function setValue($value)
58
    {
59 5
        if (!$this->isMutable()) {
60 1
            throw new RuntimeException('Cannot set the value since the number is immutable.');
61
        }
62
63 4
        return $this->internalSetValue($value);
64
    }
65
66
    /**
67
     * Converts the value to an absolute number.
68
     *
69
     * @return BigInteger
70
     */
71 5
    public function abs()
72
    {
73 5
        $value = gmp_abs($this->value);
74
75 5
        return $this->assignValue($value);
76
    }
77
78
    /**
79
     * Adds the given value to this value.
80
     *
81
     * @param string $value The value to add.
82
     * @return BigInteger
83
     */
84 6
    public function add($value)
85
    {
86 6
        $this->checkValue($value);
87
88 5
        $gmp = gmp_init($value);
89
90 5
        $calculatedValue = gmp_add($this->value, $gmp);
91
92 5
        return $this->assignValue($calculatedValue);
93
    }
94
95
    /**
96
     * Compares this number and the given number.
97
     *
98
     * @return int Returns -1 is the number is less than this number. 0 if equal and 1 when greater.
99
     */
100 4
    public function cmp($value)
101
    {
102 4
        $this->checkValue($value);
103
104 3
        $result = gmp_cmp($this->value, $value);
105
106
        // It could happpen that gmp_cmp returns a value greater than one (e.g. gmp_cmp('123', '-123')). That's why
107
        // we do an additional check to make sure to return the correct value.
108
109 3
        if ($result > 0) {
110 1
            return 1;
111 2
        } elseif ($result < 0) {
112 1
            return -1;
113
        }
114
115 1
        return 0;
116
    }
117
118
    /**
119
     * Divides this value by the given value.
120
     *
121
     * @param string $value The value to divide by.
122
     * @return BigInteger
123
     */
124 9
    public function divide($value)
125
    {
126 9
        $this->checkValue($value);
127
128 8
        $gmp = gmp_init($value);
129
130 8
        $calculatedValue = gmp_div($this->value, $gmp, false);
131
132 8
        return $this->assignValue($calculatedValue);
133
    }
134
135
    /**
136
     * Calculates factorial of this value.
137
     *
138
     * @return BigInteger
139
     */
140 3
    public function factorial()
141
    {
142 3
        $calculatedValue = gmp_fact($this->getValue());
143
144 3
        return $this->assignValue($calculatedValue);
145
    }
146
147
    /**
148
     * Performs a modulo operation with the given number.
149
     *
150
     * @param string $value The value to perform a modulo operation with.
151
     * @return BigInteger
152
     */
153 6
    public function mod($value)
154
    {
155 6
        $this->checkValue($value);
156
157 5
        $gmp = gmp_init($value);
158
159 5
        $calculatedValue = gmp_mod($this->value, $gmp);
160
161 5
        return $this->assignValue($calculatedValue);
162
    }
163
164
    /**
165
     * Multiplies the given value with this value.
166
     *
167
     * @param string $value The value to multiply with.
168
     * @return BigInteger
169
     */
170 6
    public function multiply($value)
171
    {
172 6
        $this->checkValue($value);
173
174 5
        $gmp = gmp_init($value);
175
176 5
        $calculatedValue = gmp_mul($this->value, $gmp);
177
178 5
        return $this->assignValue($calculatedValue);
179
    }
180
181
    /**
182
     * Negates the value.
183
     *
184
     * @return BigInteger
185
     */
186 3
    public function negate()
187
    {
188 3
        $calculatedValue = gmp_neg($this->value);
189
190 3
        return $this->assignValue($calculatedValue);
191
    }
192
193
    /**
194
     * Performs a power operation with the given number.
195
     *
196
     * @param string $value The value to perform a power operation with.
197
     * @return BigInteger
198
     */
199 6
    public function pow($value)
200
    {
201 6
        $this->checkValue($value);
202
203 5
        $calculatedValue = gmp_pow($this->value, (string)$value);
204
205 5
        return $this->assignValue($calculatedValue);
206
    }
207
208
    /**
209
     * Subtracts the given value from this value.
210
     *
211
     * @param string $value The value to subtract.
212
     * @return BigInteger
213
     */
214 6
    public function subtract($value)
215
    {
216 6
        $this->checkValue($value);
217
218 5
        $gmp = gmp_init($value);
219
220 5
        $calculatedValue = gmp_sub($this->value, $gmp);
221
222 5
        return $this->assignValue($calculatedValue);
223
    }
224
225
    /**
226
     * Checks if this object is mutable.
227
     *
228
     * @return bool
229
     */
230 52
    public function isMutable()
231
    {
232 52
        return $this->mutable;
233
    }
234
235
    /**
236
     * Converts this class to a string.
237
     *
238
     * @return string
239
     */
240 11
    public function toString()
241
    {
242 11
        return $this->getValue();
243
    }
244
245
    /**
246
     * Converts this class to a string.
247
     *
248
     * @return string
249
     */
250 11
    public function __toString()
251
    {
252 11
        return $this->toString();
253
    }
254
255
    /**
256
     * A helper method to assign the given value.
257
     *
258
     * @param int|string|BigInteger $value The value to assign.
259
     * @return BigInteger
260
     */
261 44
    private function assignValue($value)
262
    {
263 44
        $result = null;
0 ignored issues
show
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
264
265 44
        if ($this->isMutable()) {
266 35
            $result = $this->internalSetValue($value);
267 35
        } else {
268 9
            $result = new BigInteger($value, false);
269
        }
270
271 44
        return $result;
272
    }
273
274
    /**
275
     * A helper method to set the value on this class.
276
     *
277
     * @param int|string|BigInteger $value The value to assign.
278
     * @return BigInteger
279
     */
280 67
    private function internalSetValue($value)
281
    {
282 67
        $this->checkValue($value);
283
284 66
        $this->value = gmp_init($value);
285
286 66
        return $this;
287
    }
288
289
    /**
290
     * Checks if the given value is valid.
291
     *
292
     * @param int|string $value The value to check.
293
     * @throws InvalidArgumentException Thrown when the value is invalid.
294
     */
295 67
    private function checkValue(&$value)
296
    {
297 67
        if ($value instanceof GMP || is_resource($value)) {
298 44
            $value = gmp_strval($value);
299 44
        } else {
300 67
            $value = (string)$value;
301
        }
302
303 67
        if (!preg_match('/^(-|\+)?[0-9]+$/', $value)) {
304 8
            throw new InvalidArgumentException('Invalid number provided: ' . $value);
305
        }
306 66
    }
307
}
308