Completed
Push — master ( 166bd7...2a4290 )
by Nico
01:28
created

IndexOf   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 30
ccs 10
cts 12
cp 0.8333
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A call() 0 18 3
A getName() 0 4 1
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\Rules\Grammar\JavaScript\Methods;
11
12
use nicoSWD\Rules\Core\CallableFunction;
13
use nicoSWD\Rules\Tokens\BaseToken;
14
use nicoSWD\Rules\Tokens\TokenInteger;
15
16
final class IndexOf extends CallableFunction
17
{
18
    /**
19
     * @param BaseToken $needle
20
     * @return BaseToken
21
     */
22 6
    public function call($needle = null): BaseToken
23
    {
24 6
        if (!$needle) {
25 2
            $value = -1;
26
        } else {
27 4
            $value = strpos($this->token->getValue(), $needle->getValue());
28
29 4
            if ($value === false) {
30 2
                $value = -1;
31
            }
32
        }
33
34 6
        return new TokenInteger(
35 6
            $value,
36 6
            $this->token->getOffset(),
37 6
            $this->token->getStack()
38
        );
39
    }
40
41
    public function getName(): string
42
    {
43
        return 'indexOf';
44
    }
45
}
46