Join::the()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Parser\Helpers;
4
5
use Stratadox\Parser\Parser;
6
use Stratadox\Parser\Parsers\Map;
7
use function implode;
8
use function is_array;
9
10
/**
11
 * Join
12
 *
13
 * Implodes the array result into a string.
14
 */
15
final class Join
16
{
17
    public static function the(Parser|string $parser): Parser
18
    {
19
        return Join::with('', $parser);
20
    }
21
22
    public static function with(string $glue, Parser|string $parser): Parser
23
    {
24
        return Map::the($parser, fn($x) => is_array($x) ? implode($glue, $x) : $x);
25
    }
26
}
27