StatisticsCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
A execute() 0 32 5
A __construct() 0 6 1
1
<?php
2
/**
3
 * This file is part of the InMemoryList package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 */
10
11
namespace InMemoryList\Command;
12
13
use Symfony\Component\Console\Helper\Table;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
class StatisticsCommand extends BaseCommand
18
{
19
    /**
20
     * StatisticsCommand constructor.
21
     *
22
     * @param null  $driver
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $driver is correct as it would always require null to be passed?
Loading history...
23
     * @param array $parameters
24
     */
25
    public function __construct($driver = null, array $parameters = [])
26
    {
27
        parent::__construct(
28
            'iml_cache_statistics',
29
            $driver,
30
            $parameters
31
        );
32
    }
33
34
    protected function configure()
35
    {
36
        $this
37
            ->setName('iml:cache:statistics')
38
            ->setDescription('Get the cache statistics.')
39
            ->setHelp('This command displays the cache statistics.')
40
        ;
41
    }
42
43
    protected function execute(InputInterface $input, OutputInterface $output)
44
    {
45
        $cache = $this->createClient($this->driver, $this->parameters);
46
        $statistics = $cache->getRepository()->getStatistics();
47
48
        $table = new Table($output);
49
        $table->setHeaders(['Key', 'Value']);
50
51
        $counter = 0;
52
        foreach ($statistics as $infoKey => $infoData) {
53
            $dataString = '';
54
55
            if (is_array($infoData)) {
56
                foreach ($infoData as $key => $value) {
57
                    $valueToDisplay = (is_array($value)) ? implode(',', $value) : $value;
58
                    $dataString .= '['.$key.']->'.$valueToDisplay."\xA";
59
                }
60
            } else {
61
                $dataString .= $infoData;
62
            }
63
64
            $table->setRow(
65
                $counter,
66
                [
67
                    $infoKey,
68
                    $dataString,
69
                ]
70
            );
71
            ++$counter;
72
        }
73
74
        $table->render();
75
    }
76
}
77