Passed
Push — 0.7.0 ( 679d5f...dd56a8 )
by Alexander
03:01 queued 10s
created

Lenevor   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 23
c 2
b 0
f 0
dl 0
loc 114
rs 10
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A bootstrappers() 0 3 1
A getPrime() 0 3 1
A __construct() 0 3 1
A renderException() 0 3 1
A reportException() 0 3 1
A bootstrap() 0 4 2
A handle() 0 13 2
1
<?php
2
3
/**
4
 * Lenevor Framework
5
 *
6
 * LICENSE
7
 *
8
 * This source file is subject to the new BSD license that is bundled
9
 * with this package in the file license.md.
10
 * It is also available through the world-wide-web at this URL:
11
 * https://lenevor.com/license
12
 * If you did not receive a copy of the license and are unable to
13
 * obtain it through the world-wide-web, please send an email
14
 * to [email protected] so we can send you a copy immediately.
15
 *
16
 * @package     Lenevor
17
 * @subpackage  Base
18
 * @link        https://lenevor.com
19
 * @copyright   Copyright (c) 2019 - 2021 Alexander Campo <[email protected]>
20
 * @license     https://opensource.org/licenses/BSD-3-Clause New BSD license or see https://lenevor.com/license or see /license.md
21
 */
22
23
namespace Syscodes\Core\Console;
24
25
use Closure;
26
use Throwable;
27
use ReflectionClass;
28
use Syscodes\Support\Str;
29
use Syscodes\Support\Finder;
30
use Syscodes\Collections\Arr;
31
use Syscodes\Contracts\Core\Application;
32
use Syscodes\Contracts\Events\Dispatcher;
33
use Syscodes\Console\Application as Prime;
34
use Syscodes\Contracts\Debug\ExceptionHandler;
35
use Syscodes\Contracts\Console\Lenevor as LenevorConsole;
36
37
/**
38
 * The Lenevor class is the heart of the system when use 
39
 * the console of commands in framework.
40
 *
41
 * @author Alexander Campo <[email protected]>
42
 */
43
class Lenevor implements LenevorConsole
44
{
45
    /**
46
     * The application implementation.
47
     * 
48
     * @var \Syscodes\Contracts\Core\Application $app
49
     */
50
    protected $app;
51
52
    /**
53
	 * The bootstrap classes for the application.
54
	 * 
55
	 * @var array $bootstrappers
56
	 */
57
	protected $bootstrappers = [
58
		\Syscodes\Core\Bootstrap\BootDetectEnvironment::class,
59
		\Syscodes\Core\Bootstrap\BootConfiguration::class,
60
		\Syscodes\Core\Bootstrap\BootHandleExceptions::class,
61
		\Syscodes\Core\Bootstrap\BootRegisterFacades::class,
62
		\Syscodes\Core\Bootstrap\BootRegisterProviders::class,
63
		\Syscodes\Core\Bootstrap\BootProviders::class,
64
	];
65
66
    /**
67
     * Constructor. Create new console Lenevor instance.
68
     * 
69
     * @param  \Syscodes\Contracts\Core\Application $app
70
     * 
71
     * @return void
72
     */
73
    public function __construct(Application $app)
74
    {
75
        $this->app = $app;
76
    }
77
78
    /**
79
     * Handle an incoming console command.
80
     * 
81
     * @param  \Syscodes\Http\Request  $request
82
     * 
83
     * @return int
84
     */
85
    public function handle($request)
86
    {
87
        try {
88
            $this->bootstrap();
89
            
90
            return $this->getPrime();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getPrime() returns the type Syscodes\Console\Application which is incompatible with the documented return type integer.
Loading history...
91
        } catch (Throwable $e) {
92
            
93
            $this->reportException($e);
94
            
95
            $this->renderException($request, $e);
96
97
            return 1;
98
        }
99
        
100
    }
101
102
    /**
103
     * Bootstrap the application for artisan commands.
104
     * 
105
     * @return void
106
     */
107
    public function bootstrap()
108
    {
109
        if ( ! $this->app->hasBeenBootstrapped()) {
110
			$this->app->bootstrapWith($this->bootstrappers());
111
		}
112
    }
113
114
    /**
115
	 * Get the bootstrap classes for the application.
116
	 * 
117
	 * @return array
118
	 */
119
	protected function bootstrappers()
120
	{
121
		return $this->bootstrappers;
122
	}
123
124
    /**
125
     * Get the Prime application instance.
126
     * 
127
     * @return \Syscodes\Console\Application
128
     */
129
    protected function getPrime()
130
    {
131
        return (new Prime($this->app))->showHeader();
132
    }
133
134
    /**
135
	 * Report the exception to the exception handler.
136
	 * 
137
	 * @param  \Throwable  $e
138
	 * 
139
	 * @return void
140
	 */
141
	protected function reportException(Throwable $e)
142
	{
143
		$this->app[ExceptionHandler::class]->report($e);
144
	}
145
	
146
	/**
147
	 * Render the exception to a response.
148
	 * 
149
	 * @param  \Syscodes\Http\Request  $request
150
	 * @param  \Throwable  $e
151
	 * 
152
	 * @return void
153
	 */
154
	protected function renderException($request, Throwable $e)
155
	{
156
		$this->app[ExceptionHandler::class]->render($request, $e);
157
	}
158
}