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.
Passed
Push — master ( c538d5...8bac07 )
by Anton
02:32
created

src/Console/SshCommand.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\Host\Host;
12
use Deployer\Host\Localhost;
13
use Deployer\Task\Context;
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use Symfony\Component\Console\Question\ChoiceQuestion;
19
20
/**
21
 * @codeCoverageIgnore
22
 */
23
class SshCommand extends Command
24
{
25
    /**
26
     * @var Deployer
27
     */
28
    private $deployer;
29
30
    /**
31
     * SshCommand constructor.
32
     * @param Deployer $deployer
33
     */
34
    public function __construct(Deployer $deployer)
35
    {
36
        parent::__construct('ssh');
37
        $this->setDescription('Connect to host through ssh');
38
        $this->deployer = $deployer;
39
    }
40
41
    /**
42
     * Configures the command
43
     */
44
    protected function configure()
45
    {
46
        $this->addArgument(
47
            'hostname',
48
            InputArgument::OPTIONAL,
49
            'Hostname'
50
        );
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    protected function execute(InputInterface $input, OutputInterface $output)
57
    {
58
        $hostname = $input->getArgument('hostname');
59
        if (!empty($hostname)) {
60
            $host = $this->deployer->hosts->get($hostname);
0 ignored issues
show
It seems like $hostname defined by $input->getArgument('hostname') on line 58 can also be of type array<integer,string>; however, Deployer\Collection\Collection::get() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
61
        } else {
62
            $hostsTags = array_map(
63
                function (Host $host) {
64
                    return $host->tag();
65
                },
66
                $this->deployer->hosts->select(function ($host) {
67
                    return !($host instanceof Localhost);
68
                })
69
            );
70
71
            if (count($hostsTags) === 0) {
72
                $output->writeln('No remote hosts.');
73
                return 2; // Because there are no hosts.
74
            }
75
76
            if (count($hostsTags) === 1) {
77
                $host = $this->deployer->hosts->first();
78
            } else {
79
                $helper = $this->getHelper('question');
80
                $question = new ChoiceQuestion(
81
                    'Select host:',
82
                    $hostsTags
83
                );
84
                $question->setErrorMessage('There is no "%s" host.');
85
86
                $hostname = $helper->ask($input, $output, $question);
87
                $host = $this->deployer->hosts->get($hostname);
88
            }
89
        }
90
91
        $shell_path = 'exec $SHELL -l';
92
        if ($host->has('shell_path')) {
93
            $shell_path = 'exec ' . $host->get('shell_path') . ' -l';
94
        }
95
96
        Context::push(new Context($host, $input, $output));
97
        $options = $host->getSshArguments();
98
        $deployPath = $host->get('deploy_path', '~');
99
100
        passthru("ssh -t $options {$host->hostname()} 'cd '''$deployPath/current'''; $shell_path'");
101
        return 0;
102
    }
103
}
104