Passed
Push — master ( 90d55d...0e16d5 )
by Carlos C
03:42 queued 10s
created

ShellExecTemplate   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 17 4
1
<?php
2
namespace CfdiUtils\Utils\Internal;
3
4
/**
5
 * Build a command array from a template
6
 *
7
 * NOTE: Changes on this file will not be considering a BC since this utility class is for internal usage only
8
 *
9
 * @internal
10
 */
11
class ShellExecTemplate
12
{
13 19
    public function create(string $template, array $arguments): array
14
    {
15 19
        $command = [];
16
        $parts = array_filter(explode(' ', $template) ?: [], function (string $part): bool {
17 19
            return ('' !== $part);
18 19
        });
19
20 19
        $argumentPosition = 0;
21 19
        foreach ($parts as $value) {
22 19
            if ('?' === $value) { // argument insert
23 18
                $value = $arguments[$argumentPosition] ?? '';
24 18
                $argumentPosition = $argumentPosition + 1;
25
            }
26 19
            $command[] = $value;
27
        }
28
29 19
        return $command;
30
    }
31
}
32