IndexOf   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 17
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 15 3
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
14
final class IndexOf extends CallableFunction
15
{
16 6
    public function call(?BaseToken ...$parameters): BaseToken
17
    {
18 6
        $needle = $this->parseParameter($parameters, numParam: 0);
19
20 6
        if (!$needle) {
21 2
            $value = -1;
22
        } else {
23 4
            $value = strpos($this->token->getValue(), $needle->getValue());
0 ignored issues
show
Bug Best Practice introduced by
The property token does not exist on nicoSWD\Rule\Grammar\JavaScript\Methods\IndexOf. Did you maybe forget to declare it?
Loading history...
24
25 4
            if ($value === false) {
26 2
                $value = -1;
27
            }
28
        }
29
30 6
        return new TokenInteger($value);
31
    }
32
}
33