All::execute()   B
last analyzed

Complexity

Conditions 6
Paths 24

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.439
c 0
b 0
f 0
cc 6
eloc 19
nc 24
nop 2
1
<?php
2
3
namespace Solr\Console\Command\Collection;
4
5
use GuzzleHttp\Exception\ClientException;
6
use GuzzleHttp\Exception\ConnectException;
7
use Symfony\Component\Console\Helper;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * List all collections.
13
 */
14
class All extends Command
15
{
16
    protected function configure()
17
    {
18
        $this->setName('collection:list')
19
             ->setDescription('Fetch the names of the collections in the cluster');
20
    }
21
22
    /**
23
     * Execute list command. Returns the collections Solr.
24
     *
25
     * @param Symfony\Component\Console\Input\InputInterface  $input
26
     * @param Symfony\Component\Console\Output\OutpuInterface $output
27
     *
28
     * @return int
29
     */
30
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32
        try {
33
            $result = $this->client
34
                           ->get('admin/collections?action=LIST&wt=json')
35
                           ->json();
36
37
            if (!isset($result['collections']) || count($result['collections']) === 0) {
38
                $output->writeln('<fg=yellow>No collections found</fg=yellow>');
39
40
                return 0;
41
            }
42
43
            $table = new Helper\Table($output);
44
            $table->setHeaders(['Collection']);
45
46
            foreach ($result['collections'] as $collection) {
47
                $table->addRow([$collection]);
48
            }
49
50
            $table->render($output);
0 ignored issues
show
Unused Code introduced by
The call to Table::render() has too many arguments starting with $output.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
51
        } catch (ClientException $e) {
52
            $output->writeln("<fg=red>{$e->getMessage()}</fg=red>");
53
54
            return 1;
55
        } catch (ConnectException $e) {
56
            $output->writeln('<fg=red>The connection failed for host</fg=red>');
57
58
            return 1;
59
        }
60
    }
61
}
62