IndexOf::call()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 15
ccs 8
cts 8
cp 1
crap 3
rs 10
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\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