Join::call()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 5
nop 1
dl 0
loc 21
ccs 11
cts 11
cp 1
crap 4
rs 9.9
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\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