Completed
Push — master ( bb7c54...31bc63 )
by Elf
02:10
created

Application   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 75%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 4
c 5
b 0
f 0
lcom 1
cbo 4
dl 0
loc 52
ccs 12
cts 16
cp 0.75
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A command() 0 6 1
A runAsSingle() 0 8 2
1
<?php
2
3
namespace ElfSundae\Console;
4
5
use Closure;
6
use Illuminate\Container\Container;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Illuminate\Events\Dispatcher as EventsDispatcher;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Illuminate\Console\Application as LaravelApplication;
12
13
class Application extends LaravelApplication
14
{
15
    /**
16
     * Create a new console application.
17
     *
18
     * @param  string  $name
19
     * @param  string  $version
20
     */
21 3
    public function __construct($name = 'Console Application', $version = '1.0.0')
22
    {
23 3
        parent::__construct(
24 3
            $laravel = new Container,
25 3
            new EventsDispatcher($laravel),
26 3
            $version
27
        );
28
29 3
        $this->setName($name);
30 3
        $this->setAutoExit(true);
31 3
        $this->setCatchExceptions(true);
32 3
    }
33
34
    /**
35
     * Register a Closure based command.
36
     *
37
     * @param  string  $signature
38
     * @param  \Closure  $callback
39
     * @param  string  $description
40
     * @return \ElfSundae\Console\ClosureCommand
41
     */
42 1
    public function command($signature, Closure $callback, $description = null)
43
    {
44 1
        return $this->add(
45 1
            (new ClosureCommand($signature, $callback))->describe($description)
46
        );
47
    }
48
49
    /**
50
     * Run the current application as a single command application.
51
     *
52
     * @param  \Symfony\Component\Console\Input\InputInterface|null  $input
53
     * @param  \Symfony\Component\Console\Output\OutputInterface|null  $output
54
     * @return int
55
     */
56
    public function runAsSingle(InputInterface $input = null, OutputInterface $output = null)
57
    {
58
        if ($command = array_last($this->all())) {
59
            $this->setDefaultCommand($command->getName(), true);
60
        }
61
62
        return $this->run($input, $output);
63
    }
64
}
65