Substr::call()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 4
nop 1
dl 0
loc 20
ccs 11
cts 11
cp 1
crap 3
rs 9.9
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * @license     http://opensource.org/licenses/mit-license.php MIT
5
 * @link        https://github.com/nicoSWD
6
 * @author      Nicolas Oelgart <[email protected]>
7
 */
8
namespace nicoSWD\Rule\Grammar\JavaScript\Methods;
9
10
use nicoSWD\Rule\Grammar\CallableFunction;
11
use nicoSWD\Rule\TokenStream\Token\BaseToken;
12
use nicoSWD\Rule\TokenStream\Token\TokenString;
13
14
final class Substr extends CallableFunction
15
{
16 12
    public function call(?BaseToken ...$parameters): BaseToken
17
    {
18 12
        $params = [];
19 12
        $start = $this->parseParameter($parameters, numParam: 0);
20
21 12
        if (!$start) {
22 2
            $params[] = 0;
23
        } else {
24 10
            $params[] = (int) $start->getValue();
25
        }
26
27 12
        $offset = $this->parseParameter($parameters, numParam: 1);
28
29 12
        if ($offset) {
30 4
            $params[] = (int) $offset->getValue();
31
        }
32
33 12
        $value = substr($this->token->getValue(), ...$params);
0 ignored issues
show
Bug introduced by
$params is expanded, but the parameter $offset of substr() does not expect variable arguments. ( Ignorable by Annotation )

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

33
        $value = substr($this->token->getValue(), /** @scrutinizer ignore-type */ ...$params);
Loading history...
Bug Best Practice introduced by
The property token does not exist on nicoSWD\Rule\Grammar\JavaScript\Methods\Substr. Did you maybe forget to declare it?
Loading history...
34
35 12
        return new TokenString((string) $value);
36
    }
37
}
38