Join   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 23
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 21 4
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\TokenStream\Token\BaseToken;
11
use nicoSWD\Rule\TokenStream\Token\TokenArray;
12
use nicoSWD\Rule\TokenStream\Token\TokenString;
13
use nicoSWD\Rule\TokenStream\TokenCollection;
14
use nicoSWD\Rule\Parser\Exception\ParserException;
15
use nicoSWD\Rule\Grammar\CallableFunction;
16
17
final class Join extends CallableFunction
18
{
19 18
    public function call(?BaseToken ...$parameters): BaseToken
20
    {
21 18
        if (!$this->token instanceof TokenArray) {
0 ignored issues
show
Bug Best Practice introduced by
The property token does not exist on nicoSWD\Rule\Grammar\JavaScript\Methods\Join. Did you maybe forget to declare it?
Loading history...
22 2
            throw new ParserException(sprintf('%s.join is not a function', $this->token->getValue()));
23
        }
24
25 16
        $glue = $this->parseParameter($parameters, numParam: 0);
26
27 16
        if ($glue) {
28 14
            $glue = $glue->getValue();
29
        } else {
30 2
            $glue = ',';
31
        }
32
33 16
        $array = $this->token->getValue();
34
35 16
        if ($array instanceof TokenCollection) {
36 14
            $array = $array->toArray();
37
        }
38
39 16
        return new TokenString(implode($glue, $array));
40
    }
41
}
42