Passed
Push — master ( 6ee3f7...8f2389 )
by Nico
01:24
created

StartsWith   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 14 2
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\TokenBool;
13
14
final class StartsWith extends CallableFunction
15
{
16 4
    public function call(?BaseToken ...$parameters): BaseToken
17
    {
18 4
        $needle = $this->parseParameter($parameters, 0);
19 4
        $offset = $this->parseParameter($parameters, 1);
20
21 4
        if ($offset) {
22 2
            $offset = $offset->getValue();
23
        } else {
24 4
            $offset = 0;
25
        }
26
27 4
        $value = strpos($this->token->getValue(), $needle->getValue(), $offset);
0 ignored issues
show
Bug introduced by
The method getValue() does not exist on null. ( Ignorable by Annotation )

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

27
        $value = strpos($this->token->/** @scrutinizer ignore-call */ getValue(), $needle->getValue(), $offset);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
29 4
        return new TokenBool($value === $offset);
30
    }
31
}
32