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

SelfUpdateCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 54.55%

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 3
dl 0
loc 45
ccs 12
cts 22
cp 0.5455
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A configure() 0 10 1
A execute() 0 18 2
A getLocalPharName() 0 4 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