Completed
Push — master ( a26615...ffffde )
by Nico
01:34
created

Join   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 28
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 20 4
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\Rule\Grammar\JavaScript\Methods;
11
12
use nicoSWD\Rule\TokenStream\Token\BaseToken;
13
use nicoSWD\Rule\TokenStream\Token\TokenArray;
14
use nicoSWD\Rule\TokenStream\Token\TokenString;
15
use nicoSWD\Rule\TokenStream\TokenCollection;
16
use nicoSWD\Rule\Parser\Exception\ParserException;
17
use nicoSWD\Rule\Grammar\CallableFunction;
18
19
final class Join extends CallableFunction
20
{
21
    /**
22
     * @param BaseToken $glue
23
     * @return BaseToken
24
     * @throws ParserException
25
     */
26 18
    public function call($glue = null): BaseToken
27
    {
28 18
        if (!$this->token instanceof TokenArray) {
29 2
            throw new ParserException(sprintf('%s.join is not a function', $this->token->getValue()));
30
        }
31
32 16
        if ($glue) {
33 14
            $glue = $glue->getValue();
34
        } else {
35 2
            $glue = ',';
36
        }
37
38 16
        $array = $this->token->getValue();
39
40 16
        if ($array instanceof TokenCollection) {
41 14
            $array = $array->toArray();
42
        }
43
44 16
        return new TokenString(implode($glue, $array));
45
    }
46
}
47