Completed
Push — master ( b72fb2...ff6b5c )
by Carlos C
16s queued 13s
created

CommandTemplate::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 10
c 0
b 0
f 0
nc 3
nop 2
dl 0
loc 17
ccs 11
cts 11
cp 1
crap 3
rs 9.9332
1
<?php
2
3
namespace CfdiUtils\Internals;
4
5
/**
6
 * Build a command array from a template
7
 *
8
 * NOTE: Changes will not be considering a bracking compatibility change since this utility is for internal usage only
9
 * @internal
10
 */
11
class CommandTemplate
12
{
13 18
    public function create(string $template, array $arguments): array
14
    {
15 18
        $command = [];
16 18
        $parts = array_filter(explode(' ', $template), function (string $part): bool {
17 18
            return ('' !== $part);
18
        });
19
20 18
        $argumentPosition = 0;
21 18
        foreach ($parts as $value) {
22 18
            if ('?' === $value) { // argument insert
23 17
                $value = $arguments[$argumentPosition] ?? '';
24 17
                $argumentPosition = $argumentPosition + 1;
25
            }
26 18
            $command[] = $value;
27
        }
28
29 18
        return $command;
30
    }
31
}
32