UpdateCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 7

Importance

Changes 0
Metric Value
wmc 4
cbo 7
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 20 1
A execute() 0 19 3
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\ZipArchive;
17
use RuntimeException;
18
use Symfony\Component\Console\Input\InputArgument;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
/**
23
 * Inspired by Composer https://github.com/composer/composer
24
 */
25
class UpdateCommand extends Command
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function configure()
31
    {
32
        $this
33
            ->setName('update')
34
            ->setDescription('Update the project dependencies from the bower.json file or a single specified package')
35
            ->addArgument('package', InputArgument::OPTIONAL, 'Choose a package.')
36
            ->setHelp(<<<'EOT'
37
The <info>%command.name%</info> command reads the bower.json file from
38
the current directory, processes it, and downloads and installs all the
39
libraries and dependencies outlined in that file.
40
41
  <info>php %command.full_name%</info>
42
43
If an optional package name is passed, only that package is updated.
44
45
  <info>php %command.full_name% packageName</info>
46
47
EOT
48
            );
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    protected function execute(InputInterface $input, OutputInterface $output)
55
    {
56
        $this->setGithubToken($output);
57
58
        $packageName = $input->getArgument('package');
59
        $installer = new Installer($this->filesystem, new ZipArchive(), $this->config);
60
61
        try {
62
            $bowerphp = $this->getBowerphp($output);
63
            if (is_null($packageName)) {
64
                $bowerphp->updatePackages($installer);
65
            } else {
66
                $bowerphp->updatePackage(new Package($packageName), $installer);
67
            }
68
        } catch (RuntimeException $e) {
69
            throw new RuntimeException($e->getMessage());
70
        }
71
        $output->writeln('');
72
    }
73
}
74