Completed
Push — github-actions ( 673aea...a81297 )
by Samuel
01:18
created

OpcacheConfigurationCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 3
dl 0
loc 44
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A execute() 0 16 1
A processDirectives() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of CacheTool.
5
 *
6
 * (c) Samuel Gordalina <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CacheTool\Command;
13
14
use Symfony\Component\Console\Helper\Table;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
class OpcacheConfigurationCommand extends AbstractCommand
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23 19
    protected function configure()
24
    {
25
        $this
26 19
            ->setName('opcache:configuration')
27 19
            ->setDescription('Get configuration information about the cache')
28 19
            ->setHelp('');
29 19
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 1
    protected function execute(InputInterface $input, OutputInterface $output)
35
    {
36 1
        $this->ensureExtensionLoaded('Zend OPcache');
37
38 1
        $info = $this->getCacheTool()->opcache_get_configuration();
39
40 1
        $output->writeln("<info>{$info['version']['opcache_product_name']}</info> <comment>{$info['version']['version']}</comment>");
41
42 1
        $table = new Table($output);
43
        $table
44 1
            ->setHeaders(['Directive', 'Value'])
45 1
            ->setRows($this->processDirectives($info['directives']))
46
        ;
47
48 1
        $table->render();
49 1
    }
50
51 1
    protected function processDirectives(array $directives)
52
    {
53 1
        $list = [];
54
55 1
        foreach ($directives as $name => $value) {
56 1
            $list[] = [$name, var_export($value, true)];
57
        }
58
59 1
        return $list;
60
    }
61
}
62