Completed
Push — master ( 17dfca...2f9de9 )
by Samuel
01:17
created

OpcacheCompileScriptCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 26.09%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 3
dl 0
loc 52
ccs 6
cts 23
cp 0.2609
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
A execute() 0 19 1
A processFileList() 0 13 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\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
class OpcacheCompileScriptCommand extends AbstractCommand
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24 19
    protected function configure()
25
    {
26
        $this
27 19
            ->setName('opcache:compile:script')
28 19
            ->setDescription('Compile a given script to the opcode cache')
29 19
            ->addArgument('path', InputArgument::REQUIRED)
30 19
            ->setHelp('');
31 19
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    protected function execute(InputInterface $input, OutputInterface $output): int
37
    {
38
        $this->ensureExtensionLoaded('Zend OPcache');
39
        $path = $input->getArgument('path');
40
        $splFiles = array($path);
41
42
        $table = new Table($output);
43
        $table
44
            ->setHeaders(array(
45
                'Compiled',
46
                'Filename'
47
            ))
48
            ->setRows($this->processFilelist($splFiles))
49
        ;
50
51
        $table->render();
52
53
        return 0;
54
    }
55
56
    protected function processFileList($splFiles)
57
    {
58
        $list = array();
59
60
        foreach ($splFiles as $file) {
61
            $list[] = array(
62
                $this->getCacheTool()->opcache_compile_file(realpath($file)),
63
                realpath($file)
64
            );
65
        }
66
67
        return $list;
68
    }
69
70
}
71