Completed
Push — master ( 390e4e...b0ec12 )
by Taosikai
12:57
created

ShowProxyHostsCommand::execute()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 8.8571
cc 5
eloc 14
nc 4
nop 2
1
<?php
2
/**
3
 * Spike library
4
 * @author Tao <[email protected]>
5
 */
6
namespace Spike\Client\Command;
7
8
use Spike\Tunnel\HttpTunnel;
9
use Symfony\Component\Console\Helper\Table;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class ShowProxyHostsCommand extends Command
14
{
15
    public function configure()
16
    {
17
        $this->setName('list-proxy')
18
            ->setDescription('Lists all supported proxy hosts by the client');
19
    }
20
21
    public function execute(InputInterface $input, OutputInterface $output)
22
    {
23
        $tunnels = $this->getClient()->getKernel()->getTunnels();
24
        if ($tunnels) {
25
            $table = new Table($output);
26
            $table->setHeaders(['Protocol', 'Server Port', 'Local Host', 'Proxy Host']);
27
            foreach ($tunnels as $tunnel) {
0 ignored issues
show
Bug introduced by
The expression $tunnels of type object<Spike\Tunnel\TunnelInterface> is not traversable.
Loading history...
28
                if ($tunnel instanceof HttpTunnel) {
29
                    foreach ($tunnel->getProxyHosts() as $proxyHost => $forwardHost) {
30
                        $table->addRow([$tunnel->getProtocol(), $tunnel->getServerPort(), $forwardHost, $proxyHost]);
31
                    }
32
                } else {
33
                    $table->addRow([$tunnel->getProtocol(), $tunnel->getServerPort(), $tunnel->getHost(), '-']);
34
                }
35
            }
36
            $table->render();
37
        } else {
38
            $output->writeln("<comment>Hi, there is no proxy host, you should create a configuration file first</comment>");
39
        }
40
    }
41
}