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

PHPFileCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 9
cp 0
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
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