-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathJoin.php
More file actions
36 lines (28 loc) · 969 Bytes
/
Join.php
File metadata and controls
36 lines (28 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/**
* @license http://opensource.org/licenses/mit-license.php MIT
* @link https://github.com/nicoSWD
* @author Nicolas Oelgart <hello@nico.es>
*/
declare(strict_types=1);
namespace nicoSWD\Rule\Grammar\JavaScript\Methods;
use nicoSWD\Rule\Grammar\CallableFunction;
use nicoSWD\Rule\Parser\Exception\ParserException;
use nicoSWD\Rule\TokenStream\Token\GenericToken;
use nicoSWD\Rule\TokenStream\Token\TokenKind;
final class Join extends CallableFunction
{
public function call(mixed ...$parameters): GenericToken
{
if (!is_array($this->token)) {
throw new ParserException(sprintf('%s.join is not a function', $this->token));
}
$glue = $this->parseParameter($parameters, numParam: 0);
if ($glue !== null) {
$glue = (string) $glue;
} else {
$glue = ',';
}
return new GenericToken(TokenKind::STRING, implode($glue, $this->token));
}
}