EndsWith   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 17 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\Parser\Exception\ParserException;
12
use nicoSWD\Rule\TokenStream\Token\BaseToken;
13
use nicoSWD\Rule\TokenStream\Token\TokenBool;
14
use nicoSWD\Rule\TokenStream\Token\TokenString;
15
16
final class EndsWith extends CallableFunction
17
{
18 8
    public function call(?BaseToken ...$parameters): BaseToken
19
    {
20 8
        if (!$this->token instanceof TokenString) {
0 ignored issues
show
Bug Best Practice introduced by
The property token does not exist on nicoSWD\Rule\Grammar\JavaScript\Methods\EndsWith. Did you maybe forget to declare it?
Loading history...
21 2
            throw new ParserException('Call to undefined method "endsWith" on non-string');
22
        }
23
24 6
        $needle = $this->parseParameter($parameters, numParam: 0);
25 6
        $haystack = $this->token->getValue();
26
27 6
        if (!$needle) {
28 2
            $result = false;
29
        } else {
30 4
            $needle = $needle->getValue();
31 4
            $result = str_ends_with($haystack, $needle);
32
        }
33
34 6
        return TokenBool::fromBool($result);
35
    }
36
}
37