Completed
Push — master ( bff7dd...088f50 )
by Samuel
14:43 queued 05:36
created

PHPFileCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 40%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 32
ccs 6
cts 15
cp 0.4
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
A execute() 0 14 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\Input\InputArgument;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
class PHPFileCommand extends AbstractCommand
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23 20
    protected function configure()
24
    {
25
        $this
26 20
            ->setName('php:file')
27 20
            ->setDescription('Run a specified file')
28 20
            ->addArgument('file', InputArgument::REQUIRED)
29 20
            ->setHelp('');
30 20
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    protected function execute(InputInterface $input, OutputInterface $output): int
36
    {
37
        $file = $input->getArgument('file');
38
        if (!file_exists($file)) {
39
            throw new \RuntimeException("file not found");
40
            return 1;
0 ignored issues
show
Unused Code introduced by
return 1; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
41
        }
42
43
        $code = file_get_contents($file);
44
        $code = str_replace('<?php','',$code); 
45
        $success = $this->getCacheTool()->_eval($code);
46
        $output->writeln(sprintf("<comment>File Output:\n <info>%s</info></comment>", $success));
47
        return 0;
48
    }
49
}
50