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

ApcCacheInfoFileCommand   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 15.38%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 9
c 3
b 1
f 1
lcom 1
cbo 4
dl 0
loc 72
ccs 6
cts 39
cp 0.1538
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
B execute() 0 27 2
A processFileList() 0 16 4
A processFilename() 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 CacheTool\Util\Formatter;
15
use Symfony\Component\Console\Helper\Table;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
class ApcCacheInfoFileCommand extends ApcCacheInfoCommand
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24 4
    protected function configure()
25
    {
26 4
        $this
27 4
            ->setName('apc:cache:info:file')
28 4
            ->setDescription('Shows APC file cache information')
29 4
            ->setHelp('');
30 4
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    protected function execute(InputInterface $input, OutputInterface $output)
36
    {
37
        $this->ensureExtensionLoaded('apc');
38
39
        $info = $this->getCacheTool()->apc_cache_info('system');
40
        $this->normalize($info);
41
42
        if (!$info) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $info of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
43
            throw new \RuntimeException("Could not fetch info from APC");
44
        }
45
46
        $header = array(
47
            'Hits',
48
            'Accessed',
49
            'Deleted',
50
            'Memory size',
51
            'Filename',
52
        );
53
54
        $table = new Table($output);
55
        $table
56
            ->setHeaders($header)
57
            ->setRows($this->processFilelist($info['cache_list']))
58
        ;
59
60
        $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...
61
    }
62
63
    protected function processFileList(array $cacheList)
64
    {
65
        $list = array();
66
67
        foreach ($cacheList as $item) {
68
            $list[] = array(
69
                number_format($item['num_hits']),
70
                $item['access_time'] > 0 ? 'Yes' : 'No',
71
                $item['deletion_time'] > 0 ? 'Yes' : 'No',
72
                Formatter::bytes($item['mem_size']),
73
                $this->processFilename($item['filename']),
74
            );
75
        }
76
77
        return $list;
78
    }
79
80
    protected function processFilename($filename)
81
    {
82
        $dir = getcwd();
83
84
        if (0 === strpos($filename, $dir)) {
85
            return "." . substr($filename, strlen($dir));
86
        }
87
88
        return $filename;
89
    }
90
}
91