SelfUpdate   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 28
ccs 0
cts 21
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A execute() 0 15 2
1
<?php
2
3
namespace Releaser;
4
5
use Humbug\SelfUpdate\Updater;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class SelfUpdate extends Command
11
{
12
    const DISTRIBUTION_PREFIX = 'https://limit-zero.github.io/releaser/';
13
14
    protected function configure()
15
    {
16
        $this
17
            ->setName('self-update')
18
            ->setDescription('Updates releaser.phar to the latest version')
19
        ;
20
    }
21
22
    protected function execute(InputInterface $input, OutputInterface $output)
23
    {
24
        $updater = new Updater();
25
        $updater->getStrategy()->setPharUrl(sprintf('%s/releaser.phar', self::DISTRIBUTION_PREFIX));
26
        $updater->getStrategy()->setVersionUrl(sprintf('%s/releaser.phar.version', self::DISTRIBUTION_PREFIX));
27
28
        $result = $updater->update();
29
        if (!$result) {
30
            $output->writeln('You are already using the latest version!');
31
            return;
32
        }
33
        $new = $updater->getNewVersion();
34
        $old = $updater->getOldVersion();
35
        $output->writeln(sprintf('Updated from %s to %s', $old, $new));
36
    }
37
}
38