CLI   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execCommand() 0 9 1
A execOptions() 0 12 2
1
<?php
2
namespace PressCLI\WPCLI;
3
4
class CLI
5
{
6
    /**
7
     * Executes a WP CLI command.
8
     *
9
     * @param  string $command   The command to execute.
10
     * @param  array  $arguments Optional, command arguments. Default none.
11
     * @param  array  $options   Optional, command options. Default none.
12
     *
13
     * @return string The output from the executed command or NULL if an error occurred or the command produces no output.
14
     */
15
    public static function execCommand($command, $arguments = [], $options = [])
16
    {
17
        $arguments = trim(implode(' ', $arguments));
18
        $options = self::execOptions($options);
19
        $command = trim(PRESS_CLI_WP_EXEC . " {$command}");
20
        $command = implode(' ', array_filter([$command, $arguments, $options]));
21
22
        return system($command);
23
    }
24
25
    /**
26
     * Execution options.
27
     *
28
     * @param  array $options Command options.
29
     *
30
     * @return string         The execution command options.
31
     */
32
    protected static function execOptions($options)
33
    {
34
        $options = array_map(function ($key, $value) {
35
            if ($value) {
36
                return "--{$key}='{$value}'";
37
            }
38
39
            return "--{$key}";
40
        }, array_keys($options), $options);
41
42
        return trim(implode(' ', $options));
43
    }
44
}
45