BaseComposerCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 0
cbo 5
dl 0
loc 62
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getOptions() 0 18 4
A createProcess() 0 22 2
1
<?php
2
3
namespace Geekish\Crap\Command;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Process\Process;
7
use Symfony\Component\Process\ProcessBuilder;
8
9
/**
10
 * Class BaseComposerCommand
11
 * @package Geekish\Crap\Command
12
 */
13
abstract class BaseComposerCommand extends BaseCommand
14
{
15
    /**
16
     * Return options that are NOT default
17
     * We don't want to call Composer commands with every possible option set...
18
     * @codeCoverageIgnore
19
     *
20
     * @param InputInterface $input
21
     * @param bool $decorated
22
     * @return array
23
     */
24
    protected function getOptions(InputInterface $input, $decorated = true)
25
    {
26
        $inputOptions = $input->getOptions();
27
        $options = [];
28
29
        foreach ($this->getDefinition()->getOptions() as $option) {
30
            $name = $option->getName();
31
            if ($inputOptions[$name] !== $option->getDefault()) {
32
                $options[] = $name;
33
            }
34
        }
35
36
        if ($decorated) {
37
            $options[] = 'ansi';
38
        }
39
40
        return $options;
41
    }
42
43
    /**
44
     * Create Process for Composer command
45
     * @codeCoverageIgnore
46
     *
47
     * @param $command
48
     * @param array $packages
49
     * @param array $options
50
     * @return Process
51
     */
52
    protected function createProcess($command, array $packages, array $options)
53
    {
54
        $arguments = [];
55
56
        $arguments[] = $command;
57
58
        if (count($options) > 0) {
59
            $options = array_map(function ($value) {
60
                return str_pad($value, strlen($value) + 2, '-', STR_PAD_LEFT);
61
            }, $options);
62
63
            array_push($arguments, ...$options);
64
        }
65
66
        array_push($arguments, ...$packages);
67
68
        return (new ProcessBuilder)
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\Process\ProcessBuilder has been deprecated with message: since version 3.4, to be removed in 4.0. Use the Process class instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
69
            ->setPrefix('composer')
70
            ->setArguments($arguments)
71
            ->setTimeout(null)
72
            ->getProcess();
73
    }
74
}
75