Passed
Push — master ( ce1e4f...1e5872 )
by Josh
04:31
created

RequireMODXPackages::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 25
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 30
rs 9.52
1
<?php
2
3
namespace LCI\MODX\Orchestrator\Console\Command;
4
5
use LCI\Blend\Transport\MODXPackages;
6
use LCI\MODX\Console\Command\BaseCommand;
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 RequireMODXPackages extends BaseCommand
13
{
14
    public $loadMODX = true;
15
16
    protected function configure()
17
    {
18
        $this
19
            ->setName('modx:package')
20
            ->setDescription('Require or Remove a MODX Extra Package')
21
            ->addArgument(
22
                'signature',
23
                InputArgument::REQUIRED,
24
                'Enter a valid package signature, like ace-1.8.0-pl. Multiple packages can separated by a comma.'
25
            )
26
            ->addOption(
27
                'provider',
28
                'p',
29
                InputOption::VALUE_OPTIONAL,
30
                'Transport provider name, default is modx.com. For more info see: https://docs.modx.com/revolution/2.x/developing-in-modx/advanced-development/package-management/providers',
31
                'modx.com'
32
            )
33
            ->addOption(
34
                'latest',
35
                'l',
36
                InputOption::VALUE_OPTIONAL,
37
                'Get the latest version of this extra.',
38
                true
39
            )
40
            ->addOption(
41
                'method',
42
                'm',
43
                InputOption::VALUE_OPTIONAL,
44
                'Options are install, remove or uninstall. Remove will uninstall and remove the package files. Uninstall will preserve',
45
                'install'
46
            );
47
    }
48
49
    /**
50
     * Runs the command.
51
     *
52
     * @param InputInterface $input
53
     * @param OutputInterface $output
54
     * @return int|null|void
55
     * @throws \LCI\Blend\Exception\TransportException
56
     * @throws \LCI\Blend\Exception\TransportNotFoundException
57
     */
58
    protected function execute(InputInterface $input, OutputInterface $output)
59
    {
60
        $signatures = explode(',', $input->getArgument('signature'));
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('signature') 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

60
        $signatures = explode(',', /** @scrutinizer ignore-type */ $input->getArgument('signature'));
Loading history...
61
        $provider_name = $input->getOption('provider');
62
        $latest = (bool)$input->getOption('latest');
63
        $method = $input->getOption('method');
64
65
        $modx = $this->console->loadMODX();
66
        $modxPackages = new MODXPackages($modx, $this->consoleUserInteractionHandler);
67
68
        foreach ($signatures as $signature) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
69
70
            switch (strtolower(trim($method))) {
0 ignored issues
show
Bug introduced by
It seems like $method can also be of type string[]; however, parameter $str of trim() 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

70
            switch (strtolower(trim(/** @scrutinizer ignore-type */ $method))) {
Loading history...
71
                case 'remove':
72
                    $output->writeln('### Orchestrator is attempting to remove the MODX Extra Package: ' . $signature . ' and for the provider: ' . $provider_name . '  ###');
73
                    // uninstall/remove
74
                    $modxPackages->removePackage($signature);
75
76
                break;
77
                case 'uninstall':
78
                    $output->writeln('### Orchestrator is attempting to uninstall the MODX Extra Package: ' . $signature . ' and for the provider: ' . $provider_name . '  ###');
79
                    // uninstall/remove
80
                    $modxPackages->unInstallPackage($signature);
81
                    break;
82
83
                default:
84
                $output->writeln('### Orchestrator is attempting to require the MODX Extra Package: ' . $signature . ' and for the provider: ' . $provider_name . '  ###');
85
86
                $modxPackages->requirePackage($signature, $latest, $provider_name);
0 ignored issues
show
Bug introduced by
It seems like $provider_name can also be of type string[]; however, parameter $provider_name of LCI\Blend\Transport\MODXPackages::requirePackage() 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

86
                $modxPackages->requirePackage($signature, $latest, /** @scrutinizer ignore-type */ $provider_name);
Loading history...
87
            }
88
        }
89
90
        $output->writeln($this->getRunStats());
91
    }
92
}
93