Completed
Pull Request — 1.x (#35)
by
unknown
18:26
created

ApcCacheInfoFileCommand   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 9
c 3
b 1
f 1
lcom 1
cbo 3
dl 0
loc 72
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\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
class ApcCacheInfoFileCommand extends ApcCacheInfoCommand
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    protected function configure()
24
    {
25
        $this
26
            ->setName('apc:cache:info:file')
27
            ->setDescription('Shows APC file cache information')
28
            ->setHelp('');
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    protected function execute(InputInterface $input, OutputInterface $output)
35
    {
36
        $this->ensureExtensionLoaded('apc');
37
38
        $info = $this->getCacheTool()->apc_cache_info('system');
39
        $this->normalize($info);
40
41
        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...
42
            throw new \RuntimeException("Could not fetch info from APC");
43
        }
44
45
        $header = array(
46
            'Hits',
47
            'Accessed',
48
            'Deleted',
49
            'Memory size',
50
            'Filename',
51
        );
52
53
        $table = $this->getHelper('table');
54
        $table
55
            ->setHeaders($header)
56
            ->setRows($this->processFilelist($info['cache_list']))
57
        ;
58
59
        $table->render($output);
60
    }
61
62
    protected function processFileList(array $cacheList)
63
    {
64
        $list = array();
65
66
        foreach ($cacheList as $item) {
67
            $list[] = array(
68
                number_format($item['num_hits']),
69
                $item['access_time'] > 0 ? 'Yes' : 'No',
70
                $item['deletion_time'] > 0 ? 'Yes' : 'No',
71
                Formatter::bytes($item['mem_size']),
72
                $this->processFilename($item['filename']),
73
            );
74
        }
75
76
        return $list;
77
    }
78
79
    protected function processFilename($filename)
80
    {
81
        $dir = getcwd();
82
83
        if (0 === strpos($filename, $dir)) {
84
            return "." . substr($filename, strlen($dir));
85
        }
86
87
        return $filename;
88
    }
89
}
90