CharAt   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 22
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 20 4
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\TokenInteger;
13
use nicoSWD\Rule\TokenStream\Token\TokenString;
14
15
final class CharAt extends CallableFunction
16
{
17 10
    public function call(?BaseToken ...$parameters): BaseToken
18
    {
19 10
        $tokenValue = $this->token->getValue();
0 ignored issues
show
Bug Best Practice introduced by
The property token does not exist on nicoSWD\Rule\Grammar\JavaScript\Methods\CharAt. Did you maybe forget to declare it?
Loading history...
20 10
        $offset = $this->parseParameter($parameters, numParam: 0);
21
22 10
        if (!$offset) {
23 2
            $offset = 0;
24 8
        } elseif (!$offset instanceof TokenInteger) {
25 2
            $offset = (int) $offset->getValue();
26
        } else {
27 6
            $offset = $offset->getValue();
28
        }
29
30 10
        if (!isset($tokenValue[$offset])) {
31 2
            $char = '';
32
        } else {
33 8
            $char = $tokenValue[$offset];
34
        }
35
36 10
        return new TokenString($char);
37
    }
38
}
39