Completed
Push — master ( 4fa5e5...5bda77 )
by Aleh
06:14 queued 02:58
created

PluginCommand::run()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 8.8571
cc 5
eloc 14
nc 5
nop 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A PluginCommand::configure() 0 14 1
1
<?php
2
3
namespace Padawan\Command;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Padawan\Framework\Application\CLI\Command as CliCommand;
9
use Padawan\Plugin\Package;
10
11
class PluginCommand extends CliCommand
12
{
13
    protected function configure()
14
    {
15
        $this->setName("plugin")
16
            ->setDescription("Manages plugins for your project")
17
            ->addArgument(
18
                "command_name",
19
                InputArgument::REQUIRED,
20
                "Command to execute. Can be add or remove"
21
            )->addArgument(
22
                "plugin_name",
23
                InputArgument::REQUIRED,
24
                "Plugin to work with"
25
            );
26
    }
27
    protected function execute(InputInterface $input, OutputInterface $output)
28
    {
29
        $commandName = $input->getArgument("command_name");
30
        $pluginName = $input->getArgument("plugin_name");
31
        /** @var \Padawan\Plugin\Package */
32
        $package = $this->getContainer()->get(Package::class);
33
        $plugins = $package->getPluginsList();
34
        if ($commandName === 'add') {
35
            if (array_key_exists($pluginName, $plugins)) {
36
                return;
37
            }
38
            $plugins[] = $pluginName;
39
        } elseif ($commandName === 'remove') {
40
            if (!array_key_exists($pluginName, $plugins)) {
41
                return;
42
            }
43
            unset($plugins[$pluginName]);
44
        }
45
        $package->writePluginsList($plugins);
46
    }
47
}
48