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.

Command::setManifestUri()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
nc 1
nop 1
dl 0
loc 3
c 0
b 0
f 0
cc 1
rs 10
ccs 0
cts 3
cp 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Deployer\Component\PharUpdate\Console;
6
7
use Deployer\Component\PharUpdate\Manager;
8
use LogicException;
9
use Symfony\Component\Console\Command\Command as Base;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
/**
15
 * Manages updating or upgrading the Phar.
16
 *
17
 * @author Kevin Herrera <[email protected]>
18
 */
19
class Command extends Base
20
{
21
    /**
22
     * Disable the ability to upgrade?
23
     *
24
     * @var boolean
25
     */
26
    private $disableUpgrade = false;
27
28
    /**
29
     * The manifest file URI.
30
     *
31
     * @var string
32
     */
33
    private $manifestUri;
34
35
    /**
36
     * The running file (the Phar that will be updated).
37
     *
38
     * @var string
39
     */
40
    private $runningFile;
41
42
    /**
43
     * @param string $name The command name.
44
     * @param boolean $disable Disable upgrading?
45
     */
46
    public function __construct(string $name, bool $disable = false)
47
    {
48
        $this->disableUpgrade = $disable;
49
50
        parent::__construct($name);
51
    }
52
53
    /**
54
     * Sets the manifest URI.
55
     *
56
     * @param string $uri The URI.
57
     */
58
    public function setManifestUri(string $uri)
59
    {
60
        $this->manifestUri = $uri;
61
    }
62
63
    /**
64
     * Sets the running file (the Phar that will be updated).
65
     *
66
     * @param string $file The file name or path.
67
     */
68
    public function setRunningFile(string $file): void
69
    {
70
        $this->runningFile = $file;
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    protected function configure()
77
    {
78
        $this->setDescription('Updates the application.');
79
        $this->addOption(
80
            'pre',
81
            'p',
82
            InputOption::VALUE_NONE,
83
            'Allow pre-release updates.',
84
        );
85
        $this->addOption(
86
            'redo',
87
            'r',
88
            InputOption::VALUE_NONE,
89
            'Redownload update if already using current version.',
90
        );
91
92
        if (false === $this->disableUpgrade) {
93
            $this->addOption(
94
                'upgrade',
95
                'u',
96
                InputOption::VALUE_NONE,
97
                'Upgrade to next major release, if available.',
98
            );
99
        }
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    protected function execute(InputInterface $input, OutputInterface $output)
106
    {
107
        if (null === $this->manifestUri) {
108
            throw new LogicException(
109
                'No manifest URI has been configured.',
110
            );
111
        }
112
113
        $output->writeln('Looking for updates...');
114
115
        /** @var Helper */
116
        $pharUpdate = $this->getHelper('phar-update');
117
        /** @var Manager $manager */
118
        $manager = $pharUpdate->getManager($this->manifestUri);
0 ignored issues
show
Bug introduced by
The method getManager() does not exist on Symfony\Component\Console\Helper\HelperInterface. It seems like you code against a sub-type of Symfony\Component\Console\Helper\HelperInterface such as Deployer\Component\PharUpdate\Console\Helper. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

118
        /** @scrutinizer ignore-call */ 
119
        $manager = $pharUpdate->getManager($this->manifestUri);
Loading history...
119
        $manager->setRunningFile($this->runningFile);
120
121
        if ($manager->update(
122
            $this->getApplication()->getVersion(),
123
            $this->disableUpgrade ?: (false === $input->getOption('upgrade')),
124
            $input->getOption('pre'),
125
        )) {
126
            $output->writeln('<info>Update successful!</info>');
127
        } else {
128
            $output->writeln('<comment>Already up-to-date.</comment>');
129
        }
130
131
        // Force exit to prevent warnings
132
        die(0);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
Bug Best Practice introduced by
The expression ImplicitReturnNode returns the type null which is incompatible with the return type mandated by Symfony\Component\Consol...mand\Command::execute() of integer.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
133
    }
134
}
135