Passed
Push — master ( c76517...75329d )
by Runner
02:47
created

Console   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 10

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 53
ccs 0
cts 30
cp 0
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A registerCommands() 0 13 4
A doRun() 0 12 3
1
<?php
2
/**
3
 * @author    jan huang <[email protected]>
4
 * @copyright 2016
5
 *
6
 * @see      https://www.github.com/janhuang
7
 * @see      http://www.fast-d.cn/
8
 */
9
10
namespace FastD;
11
12
use FastD\Console\ConfigDump;
13
use FastD\Console\ControllerCreate;
14
use FastD\Console\ModelCreate;
15
use FastD\Console\RouteDump;
16
use FastD\Console\SeedCreate;
17
use FastD\Console\SeedRun;
18
use Symfony\Component\Console\Application as Symfony;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Output\OutputInterface;
21
use Symfony\Component\Debug\Exception\FatalThrowableError;
22
23
/**
24
 * Class AppConsole.
25
 */
26
class Console extends Symfony
27
{
28
    /**
29
     * AppConsole constructor.
30
     *
31
     * @param Application $app
32
     */
33
    public function __construct(Application $app)
34
    {
35
        parent::__construct($app->getName(), Application::VERSION);
36
37
        $this->addCommands([
38
            new ModelCreate(),
39
            new ControllerCreate(),
40
            new RouteDump(),
41
            new ConfigDump(),
42
            new SeedCreate(),
43
            new SeedRun(),
44
        ]);
45
46
        $this->registerCommands();
47
    }
48
49
    /**
50
     * Scan commands.
51
     */
52
    public function registerCommands()
53
    {
54
        foreach (config()->get('consoles', []) as $console) {
55
            $this->add(new $console());
56
        }
57
58
        if (false !== ($files = glob(app()->getPath().'/src/Console/*.php', GLOB_NOSORT | GLOB_NOESCAPE))) {
59
            foreach ($files as $file) {
60
                $command = '\\Console\\'.pathinfo($file, PATHINFO_FILENAME);
61
                $this->add(new $command());
62
            }
63
        }
64
    }
65
66
    public function doRun(InputInterface $input, OutputInterface $output)
67
    {
68
        try {
69
            return parent::doRun($input, $output);
70
        } catch (\Exception $exception) {
71
            app()->handleException($exception);
72
        } catch (\Throwable $exception) {
0 ignored issues
show
Bug introduced by
The class Throwable does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
73
            app()->handleException(new FatalThrowableError($exception));
74
        }
75
76
        throw $exception;
77
    }
78
}
79