Completed
Push — master ( 7a93c2...74946f )
by Lucas
01:52
created

SelfUpdateCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 0
cbo 4
dl 0
loc 45
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
B execute() 0 25 3
1
<?php
2
3
namespace Kasifi\Gitaski\Command;
4
5
use Exception;
6
use Humbug\SelfUpdate\Strategy\ShaStrategy;
7
use Humbug\SelfUpdate\Updater;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\Console\Style\SymfonyStyle;
12
13
class SelfUpdateCommand extends Command
14
{
15
    /**
16
     * return void
17
     */
18
    protected function configure()
19
    {
20
        $this
21
            ->setName('self-update')
22
            ->setDescription('Self update of Gitaski binary.');
23
    }
24
25
    /**
26
     * @param InputInterface  $input
27
     * @param OutputInterface $output
28
     *
29
     * @return void
30
     * @throws Exception
31
     */
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        $io = new SymfonyStyle($input, $output);
35
36
        $updater = new Updater();
37
        $strategy = $updater->getStrategy();
38
39
        if ($strategy instanceof ShaStrategy) {
40
            $strategy->setPharUrl('http://lucascherifi.github.io/gitaski/gitaski.phar');
41
            $strategy->setVersionUrl('http://lucascherifi.github.io/gitaski/gitaski.phar.version');
42
        }
43
44
        $result = $updater->update();
45
        if (!$result) {
46
            $io = new SymfonyStyle($input, $output);
47
            $io->success('No update needed.');
48
49
            return;
50
        }
51
        $new = $updater->getNewVersion();
52
        $old = $updater->getOldVersion();
53
        $io->success(sprintf('Updated from %s to %s', $old, $new));
54
55
        return;
56
    }
57
}