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

CommandTemplate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 19
ccs 11
cts 11
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 17 3
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