Completed
Push — master ( a26615...ffffde )
by Nico
01:34
created

CharAt   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 27
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 20 4
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @license     http://opensource.org/licenses/mit-license.php MIT
7
 * @link        https://github.com/nicoSWD
8
 * @author      Nicolas Oelgart <[email protected]>
9
 */
10
namespace nicoSWD\Rule\Grammar\JavaScript\Methods;
11
12
use nicoSWD\Rule\Grammar\CallableFunction;
13
use nicoSWD\Rule\TokenStream\Token\BaseToken;
14
use nicoSWD\Rule\TokenStream\Token\TokenInteger;
15
use nicoSWD\Rule\TokenStream\Token\TokenString;
16
17
final class CharAt extends CallableFunction
18
{
19
    /**
20
     * @param BaseToken $offset
21
     * @return BaseToken
22
     */
23 10
    public function call($offset = null): BaseToken
24
    {
25 10
        $tokenValue = $this->token->getValue();
26
27 10
        if (!$offset) {
28 2
            $offset = 0;
29 8
        } elseif (!$offset instanceof TokenInteger) {
30 2
            $offset = (int) $offset->getValue();
31
        } else {
32 6
            $offset = $offset->getValue();
33
        }
34
35 10
        if (!isset($tokenValue[$offset])) {
36 2
            $char = '';
37
        } else {
38 8
            $char = $tokenValue[$offset];
39
        }
40
41 10
        return new TokenString($char);
42
    }
43
}
44