ClosureCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 42.11%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 61
ccs 8
cts 19
cp 0.4211
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A execute() 0 16 3
A describe() 0 6 1
1
<?php
2
3
namespace ElfSundae\Console;
4
5
use Closure;
6
use ReflectionFunction;
7
use Illuminate\Console\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * Steal `Illuminate\Foundation\Console\ClosureCommand`.
13
 */
14
class ClosureCommand extends Command
15
{
16
    /**
17
     * The command callback.
18
     *
19
     * @var \Closure
20
     */
21
    protected $callback;
22
23
    /**
24
     * Create a new command instance.
25
     *
26
     * @param  string  $signature
27
     * @param  \Closure  $callback
28
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
29
     */
30 1
    public function __construct($signature, Closure $callback)
31
    {
32 1
        $this->callback = $callback;
33 1
        $this->signature = $signature;
34
35 1
        parent::__construct();
36 1
    }
37
38
    /**
39
     * Execute the console command.
40
     *
41
     * @param  \Symfony\Component\Console\Input\InputInterface  $input
42
     * @param  \Symfony\Component\Console\Output\OutputInterface  $output
43
     * @return mixed
44
     */
45
    protected function execute(InputInterface $input, OutputInterface $output)
46
    {
47
        $inputs = array_merge($input->getArguments(), $input->getOptions());
48
49
        $parameters = [];
50
51
        foreach ((new ReflectionFunction($this->callback))->getParameters() as $parameter) {
52
            if (isset($inputs[$parameter->name])) {
53
                $parameters[$parameter->name] = $inputs[$parameter->name];
54
            }
55
        }
56
57
        return $this->laravel->call(
58
            $this->callback->bindTo($this, $this), $parameters
59
        );
60
    }
61
62
    /**
63
     * Set the description for the command.
64
     *
65
     * @param  string  $description
66
     * @return $this
67
     */
68 1
    public function describe($description)
69
    {
70 1
        $this->setDescription($description);
71
72 1
        return $this;
73
    }
74
}
75