IntegrationIpsCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
A execute() 0 18 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Incapsula\Command;
6
7
use Symfony\Component\Console\Helper\Table;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class IntegrationIpsCommand extends AbstractCommand
13
{
14
    protected function configure(): void
15
    {
16
        parent::configure();
17
18
        $this
19
            ->setName('integration:ips')
20
            ->addOption('json', null, InputOption::VALUE_NONE, 'Output as JSON')
21
            ->setDescription('List IP ranges')
22
        ;
23
    }
24
25
    protected function execute(InputInterface $input, OutputInterface $output): int
26
    {
27
        $resp = $this->client->integration()->ips();
28
        $data = array_merge($resp['ipRanges'], $resp['ipv6Ranges']);
29
30
        if (true === $input->getOption('json')) {
31
            $output->write(json_encode($data));
32
33
            return 0;
34
        }
35
36
        $table = new Table($output);
37
        foreach ($data as $range) {
38
            $table->addRow([$range]);
39
        }
40
        $table->render();
41
42
        return 0;
43
    }
44
}
45