SelfUpdateCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 52.17%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 46
ccs 12
cts 23
cp 0.5217
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 19 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 6
    public function __construct(Updater $updater)
19
    {
20 6
        parent::__construct('self-update');
21 6
        $this->updater = $updater;
22 6
    }
23
24 6
    protected function configure(): void
25
    {
26
        $this
27 6
            ->setDescription(sprintf(
28 6
                'Update %s to most recent stable build.',
29 6
                $this->getLocalPharName()
30
            ))
31 6
            ->setAliases(['selfupdate'])
32
        ;
33 6
    }
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
                '%s has been updated from "%s" to "%s".',
44
                $this->getLocalPharName(),
45
                $this->updater->getOldVersion(),
46
                $this->updater->getNewVersion()
47
            ));
48
        } else {
49
            $styledOutput->success(sprintf('%s is already up to date.', $this->getLocalPharName()));
50
        }
51
52
        return 0;
53
    }
54
55 6
    private function getLocalPharName(): string
56
    {
57 6
        return basename(Phar::running());
58
    }
59
}
60