GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SelfUpdateCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 7
Bugs 0 Features 1
Metric Value
wmc 5
c 7
b 0
f 1
lcom 2
cbo 5
dl 0
loc 74
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
B execute() 0 26 3
A getNewVersion() 0 19 1
1
<?php
2
3
namespace CL\SlackCli\Command;
4
5
use Herrera\Phar\Update\Manager;
6
use Herrera\Phar\Update\Manifest;
7
use Herrera\Version\Parser;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class SelfUpdateCommand extends AbstractCommand
12
{
13
    const MANIFEST_FILE = 'http://cleentfaar.github.io/slack-cli/manifest.json';
14
15
    /**
16
     * {@inheritdoc}
17
     */
18
    protected function configure()
19
    {
20
        parent::configure();
21
22
        $this->setName('self:update');
23
        $this->setDescription('Updates slack.phar to the latest version');
24
        $this->setAliases(['self.update']);
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32
        $currentVersion  = $this->getApplication()->getVersion();
33
        $manager         = new Manager(Manifest::loadFile(self::MANIFEST_FILE));
34
        $lockMajor       = false;
35
        $allowPreRelease = false;
36
37
        if (substr($currentVersion, 0, 1) == 0) {
38
            $allowPreRelease = true;
39
        }
40
41
        if ($manager->update($currentVersion, $lockMajor, $allowPreRelease)) {
42
            $newVersion = $this->getNewVersion($currentVersion, $manager, $lockMajor, $allowPreRelease);
43
44
            $this->output->writeln(sprintf(
45
                '<info>Updated Slack CLI from <fg=yellow>%s</fg=yellow> to <fg=yellow>%s</fg=yellow></info>',
46
                $currentVersion,
47
                $newVersion
48
            ));
49
        } else {
50
            $this->output->writeln(sprintf(
51
                '<comment>You are already using the latest version (%s)</comment>',
52
                $currentVersion
53
            ));
54
        }
55
    }
56
57
    /**
58
     * @param string  $currentVersion
59
     * @param Manager $manager
60
     * @param bool    $lockMajor
61
     * @param bool    $allowPreRelease
62
     *
63
     * @return string
64
     */
65
    private function getNewVersion($currentVersion, Manager $manager, $lockMajor = false, $allowPreRelease = false)
66
    {
67
        $newVersionObject = $manager->getManifest()->findRecent(
68
            Parser::toVersion($currentVersion),
69
            $lockMajor,
70
            $allowPreRelease
71
        )->getVersion();
72
73
        $newVersion = sprintf(
74
            '%s.%s',
75
            $newVersionObject->getMajor(),
76
            implode('.', array_filter([
77
                $newVersionObject->getMinor(),
78
                $newVersionObject->getPatch(),
79
            ]))
80
        );
81
82
        return $newVersion;
83
    }
84
}
85