Completed
Push — master ( 3b8df9...2f57f8 )
by Marius
04:00
created

SelfUpdateCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Paysera\PhpStormHelper\Command;
6
7
use Humbug\SelfUpdate\Updater;
8
use Phar;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Symfony\Component\Console\Style\SymfonyStyle;
13
14
class SelfUpdateCommand extends Command
15
{
16
    private $updater;
17
18 5
    public function __construct(Updater $updater)
19
    {
20 5
        parent::__construct('self-update');
21 5
        $this->updater = $updater;
22 5
    }
23
24 5
    protected function configure(): void
25
    {
26
        $this
27 5
            ->setDescription(sprintf(
28 5
                'Update %s to most recent stable build.',
29 5
                $this->getLocalPharName()
30
            ))
31 5
            ->setAliases(['selfupdate'])
32
        ;
33 5
    }
34
35
    protected function execute(InputInterface $input, OutputInterface $output): int
36
    {
37
        $styledOutput = new SymfonyStyle($input, $output);
38
39
        $result = $this->updater->update();
40
41
        if ($result) {
42
            $styledOutput->success(sprintf(
43
                'Your PHAR has been updated from "%s" to "%s".',
44
                $this->updater->getOldVersion(),
45
                $this->updater->getNewVersion()
46
            ));
47
        } else {
48
            $styledOutput->success('Your PHAR is already up to date.');
49
        }
50
51
        return 0;
52
    }
53
54 5
    private function getLocalPharName(): string
55
    {
56 5
        return basename(Phar::running());
57
    }
58
}
59