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.

SelectCommand   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 31
dl 0
loc 54
c 1
b 0
f 0
rs 10
ccs 30
cts 32
cp 0.9375
wmc 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A configure() 0 3 1
B selectHosts() 0 39 8
1
<?php
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Console;
9
10
use Deployer\Deployer;
11
use Deployer\Exception\Exception;
12
use Deployer\Exception\GracefulShutdownException;
13
use Deployer\Executor\Planner;
14
use Deployer\Host\Host;
15
use Deployer\Host\Localhost;
16
use Symfony\Component\Console\Command\Command;
17
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
18
use Symfony\Component\Console\Helper\QuestionHelper;
19
use Symfony\Component\Console\Helper\Table;
20
use Symfony\Component\Console\Input\InputArgument;
21
use Symfony\Component\Console\Input\InputInterface as Input;
22
use Symfony\Component\Console\Input\InputOption as Option;
23
use Symfony\Component\Console\Output\OutputInterface as Output;
24
use Symfony\Component\Console\Question\ChoiceQuestion;
25
26
abstract class SelectCommand extends Command
27
{
28
    protected $deployer;
29
30 12
    public function __construct(string $name, Deployer $deployer)
31
    {
32 12
        $this->deployer = $deployer;
33 12
        parent::__construct($name);
34 12
    }
35
36 12
    protected function configure()
37
    {
38 12
        $this->addOption('select', 's', Option::VALUE_OPTIONAL, 'Host selector');
39 12
    }
40
41 12
    protected function selectHosts(Input $input, Output $output)
42
    {
43 12
        $output->getFormatter()->setStyle('success', new OutputFormatterStyle('green'));
44 12
        if (!$output->isDecorated() && !defined('NO_ANSI')) {
45 1
            define('NO_ANSI', 'true');
46
        }
47 12
        $selectExpression = $input->getOption('select');
48
49 12
        if (empty($selectExpression)) {
50 2
            if (count($this->deployer->hosts) === 1) {
51
                $hosts = $this->deployer->hosts->all();
52 2
            } else if ($input->isInteractive()) {
53 2
                $hostsAliases = [];
54 2
                foreach ($this->deployer->hosts as $host) {
55 2
                    $hostsAliases[] = $host->getAlias();
56
                }
57
                /** @var QuestionHelper $helper */
58 2
                $helper = $this->getHelper('question');
59 2
                $question = new ChoiceQuestion(
60 2
                    '<question>Select hosts:</question> (comma separated)',
61
                    $hostsAliases
62
                );
63 2
                $question->setMultiselect(true);
64 2
                $question->setErrorMessage('There is no "%s" host.');
65 2
                $answer = $helper->ask($input, $output, $question);
66 2
                $answer = array_unique($answer);
0 ignored issues
show
Bug introduced by
It seems like $answer can also be of type boolean and null and string; however, parameter $array of array_unique() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

66
                $answer = array_unique(/** @scrutinizer ignore-type */ $answer);
Loading history...
67
                $hosts = $this->deployer->hosts->select(function (Host $host) use ($answer) {
68 2
                    return in_array($host->getAlias(), $answer, true);
69 2
                });
70
            }
71
        } else {
72 10
            $hosts = $this->deployer->selector->selectHosts($selectExpression);
73
        }
74
75 12
        if (empty($hosts)) {
76
            throw new Exception('No host selected');
77
        }
78
79 12
        return $hosts;
80
    }
81
}
82