Passed
Push — master ( 756bbe...4609d0 )
by Josh
04:10
created

UninstallPackages::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LCI\MODX\Orchestrator\Console\Command;
4
5
use LCI\MODX\Console\Command\BaseCommand;
6
use LCI\MODX\Orchestrator\Orchestrator;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class UninstallPackages extends BaseCommand
13
{
14
    public $loadMODX = true;
15
16
    protected function configure()
17
    {
18
        $this
19
            ->setName('orchestrator:remove')
20
            ->setAliases(['orch-remove'])
21
            ->setDescription('Uninstall Package, this will run migrations down for related packages');
22
23
        $this->addArgument(
24
            'package',
25
            InputArgument::REQUIRED,
26
            'Enter a valid package name, like lci/stockpile. Multiple packages can separated by a comma.'
27
            )
28
            ->addOption(
29
            'type',
30
            't',
31
            InputOption::VALUE_OPTIONAL,
32
            'Server type passed to run migrations, default is master. Possible master, staging, dev and local',
33
            'master'
34
            );
35
    }
36
37
    /**
38
     * Runs the command.
39
     *
40
     * @param InputInterface $input
41
     * @param OutputInterface $output
42
     * @return int|null|void
43
     * @throws \LCI\Blend\Exception\MigratorException
44
     */
45
    protected function execute(InputInterface $input, OutputInterface $output)
46
    {
47
        $packages = explode(',', $input->getArgument('package'));
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('package') can also be of type string[]; however, parameter $string of explode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

47
        $packages = explode(',', /** @scrutinizer ignore-type */ $input->getArgument('package'));
Loading history...
48
        $type = $input->getOption('type');
49
50
        foreach ($packages as $package) {
51
            $output->writeln('### Orchestrator::uninstallComposerPackage() for '.$package.' and type: '.$type.'  ###');
52
            Orchestrator::uninstallComposerPackage($package, $type);
0 ignored issues
show
Bug introduced by
It seems like $type can also be of type string[]; however, parameter $type of LCI\MODX\Orchestrator\Or...nstallComposerPackage() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

52
            Orchestrator::uninstallComposerPackage($package, /** @scrutinizer ignore-type */ $type);
Loading history...
53
        }
54
    }
55
}
56