Completed
Push — master ( 859fd7...1e8f56 )
by Massimiliano
02:04
created

UninstallCommand::execute()   B

Complexity

Conditions 2
Paths 5

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 14
nc 5
nop 2
1
<?php
2
3
/*
4
 * This file is part of Bowerphp.
5
 *
6
 * (c) Massimiliano Arione <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Bowerphp\Command;
13
14
use Bowerphp\Installer\Installer;
15
use Bowerphp\Package\Package;
16
use Bowerphp\Util\PackageNameVersionExtractor;
17
use Bowerphp\Util\ZipArchive;
18
use Symfony\Component\Console\Input\InputArgument;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
/**
23
 * Uninstall
24
 */
25
class UninstallCommand extends Command
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function configure()
31
    {
32
        $this
33
            ->setName('uninstall')
34
            ->setDescription('Uninstalls a single specified package')
35
            ->addArgument('package', InputArgument::REQUIRED, 'Choose a package.')
36
            ->setHelp(<<<'EOT'
37
The <info>%command.name%</info> command uninstall a package.
38
39
  <info>php %command.full_name% packageName</info>
40
EOT
41
            )
42
        ;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    protected function execute(InputInterface $input, OutputInterface $output)
49
    {
50
        $this->setGithubToken($output);
51
52
        $packageName = $input->getArgument('package');
53
54
        $bowerphp = $this->getBowerphp($output);
55
56
        try {
57
            $installer = new Installer($this->filesystem, new ZipArchive(), $this->config);
58
59
            $packageNameVersion = PackageNameVersionExtractor::fromString($packageName);
60
61
            $package = new Package($packageNameVersion->name, $packageNameVersion->version);
62
            $bowerphp->uninstallPackage($package, $installer);
63
        } catch (\RuntimeException $e) {
64
            $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
65
66
            return 1;
67
        }
68
69
        $output->writeln('');
70
71
        return 0;
72
    }
73
}
74