SelfUpdate::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 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