Completed
Push — master ( ecc98d...289748 )
by recca
02:11
created

ArtisanTinker::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Recca0120\Terminal\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Symfony\Component\Console\Input\InputOption;
7
8
class ArtisanTinker extends Command
9
{
10
    /**
11
     * The console command name.
12
     *
13
     * @var string
14
     */
15
    protected $name = 'tinker';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'artisn tinker';
23
24
    /**
25
     * fire.
26
     */
27 6
    public function fire()
28
    {
29 6
        $command = $this->option('command');
30
31 6
        ob_start();
32 6
        $result = $this->executeCode(
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $this->executeCode(trim(...($command), ';') . ';') (which targets Recca0120\Terminal\Conso...anTinker::executeCode()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
33 6
            trim(trim($command), ';').';'
34 6
        );
35 6
        $output = ob_get_clean();
36
37 6
        if (empty($output) === false) {
38 2
            $this->line($output);
39 2
        }
40
41 6
        $this->getOutput()->write('=> ');
42 6
        switch (gettype($result)) {
43 6
            case 'object':
44 6
            case 'array':
45 2
                $this->line(var_export($result, true));
46 2
                break;
47 4
            case 'string':
48 1
                $this->comment($result);
49 1
                break;
50 3
            default:
51 3
                is_numeric($result) === true ? $this->info($result) : $this->line($result);
52 3
                break;
53 6
        }
54 6
    }
55
56 6
    protected function executeCode($code)
57
    {
58 6
        $result = null;
59 6
        if (strpos($code, 'echo') !== false || strpos($code, 'var_dump') !== false) {
60 2
            eval($code);
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
61 2
        } else {
62 4
            eval('$result = '.$code);
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
63
        }
64
65 6
        return $result;
66
    }
67
68
    /**
69
     * Get the console command options.
70
     *
71
     * @return array
72
     */
73 6
    protected function getOptions()
74
    {
75
        return [
76 6
            ['command', null, InputOption::VALUE_OPTIONAL],
77 6
        ];
78
    }
79
}
80