Completed
Push — symfony-console ( 505007...6e7652 )
by Arnaud
02:41 queued 10s
created

SelfUpdate::execute()   A

Complexity

Conditions 3
Paths 8

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 9.392
c 0
b 0
f 0
cc 3
nc 8
nop 2
1
<?php
2
/*
3
 * Copyright (c) Arnaud Ligny <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Cecil\Command;
10
11
use Humbug\SelfUpdate\Updater;
12
use Symfony\Component\Console\Input\InputArgument;
13
use Symfony\Component\Console\Input\InputDefinition;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
class SelfUpdate extends Command
18
{
19
    /**
20
     * @var string
21
     */
22
    protected $version;
23
    /**
24
     * @var Updater
25
     */
26
    protected $updater;
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected function configure()
32
    {
33
        $this
34
            ->setName('self-update')
35
            ->setDescription('Update Cecil to the latest version')
36
            ->setDefinition(
37
                new InputDefinition([
38
                    new InputArgument('path', InputArgument::OPTIONAL, 'If specified, use the given path as working directory'),
39
                ])
40
            )
41
            ->setHelp('The self-update command checks for a newer version, and, if found, downloads and installs the latest.');
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    protected function execute(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
48
    {
49
        $this->version = $this->getApplication()->getVersion();
50
51
        $this->updater = new Updater(null, false, Updater::STRATEGY_GITHUB);
52
        /* @var $strategy \Humbug\SelfUpdate\Strategy\GithubStrategy */
53
        $strategy = $this->updater->getStrategy();
54
        $strategy->setPackageName('cecil/cecil');
55
        $strategy->setPharName('cecil.phar');
56
        $strategy->setCurrentLocalVersion($this->version);
57
        $strategy->setStability('any');
58
59
        try {
60
            $output->writeln('Checks for updates...');
61
            $result = $this->updater->update();
62
            if ($result) {
63
                $new = $this->updater->getNewVersion();
64
                $old = $this->updater->getOldVersion();
65
                $output->writeln(sprintf('Updated from %s to %s.', $old, $new));
66
67
                return 0;
68
            }
69
            $output->writeln(sprintf('You are already using last version (%s).', $this->version));
70
71
            return 0;
72
        } catch (\Exception $e) {
73
            echo $e->getMessage();
74
75
            return 1;
76
        }
77
78
        return 0;
0 ignored issues
show
Unused Code introduced by
return 0; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
79
    }
80
}
81