Completed
Pull Request — master (#38)
by Boris
04:23 queued 02:11
created

ApcRegexpDeleteCommand   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 18.92%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 8
c 2
b 0
f 1
lcom 0
cbo 5
dl 0
loc 54
ccs 7
cts 37
cp 0.1892
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
C execute() 0 36 7
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\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
class ApcRegexpDeleteCommand extends AbstractCommand
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24 4
    protected function configure()
25
    {
26 4
        $this
27 4
            ->setName('apc:regexp:delete')
28 4
            ->setDescription('Deletes all APC key matching a regexp')
29 4
            ->addArgument('regexp', InputArgument::REQUIRED)
30 4
            ->setHelp('');
31 4
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    protected function execute(InputInterface $input, OutputInterface $output)
37
    {
38
        $this->ensureExtensionLoaded('apc');
39
40
        $regexp = $input->getArgument('regexp');
41
42
        $user = $this->getCacheTool()->apc_cache_info('user');
43
44
        $keys = array();
45
        foreach ($user['cache_list'] as $key) {
46
            $string = $key['info'];
47
            if (preg_match('|' . $regexp . '|', $string)) {
48
                $keys[] = $key;
49
            }
50
        }
51
        $cpt = 0;
52
        $table = new Table($output);
53
        $table->setHeaders(array('Key', 'TTL', ));
54
        $table->setRows($keys);
55
        $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...
56
        foreach ($keys as $key) {
57
            $success = $this->getCacheTool()->apc_delete($key['info']);
58
            if ($output->isVerbose()) {
59
                if ($success) {
60
                    $output->writeln("<comment>APC key <info>{$key['info']}</info> was deleted</comment>");
61
                } else {
62
                    $output->writeln("<comment>APC key <info>{$key['info']}</info> could not be deleted.</comment>");
63
                }
64
            }
65
            $cpt ++;
66
        }
67
        if ($output->isVerbose()) {
68
            $output->writeln("<comment>APC key <info>{$cpt}</info> keys treated.</comment>");
69
        }
70
        return 1;
71
    }
72
}
73