InterceptorServiceProvider::boot()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 24
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 18
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 24
ccs 20
cts 20
cp 1
crap 3
rs 9.6666
1
<?php
2
declare(strict_types=1);
3
namespace Modulate\Artisan\Interceptor\Providers;
4
5
use Illuminate\Support\ServiceProvider;
6
7
use Illuminate\Console\Events\ArtisanStarting;
8
use Illuminate\Console\Events\CommandStarting;
9
use Illuminate\Console\Events\CommandFinished;
10
use Illuminate\Support\Facades\Event;
11
use Modulate\Artisan\Interceptor\Contracts\HandlerStack as HandlerStackContract;
12
use Modulate\Artisan\Interceptor\InterceptedCommand;
13
14
15
use Modulate\Artisan\Interceptor\Contracts\Interceptor as InterceptorContract;
16
use Modulate\Artisan\Interceptor\Facades\ArtisanInterceptor;
17
use Modulate\Artisan\Interceptor\HandlerStack;
18
use Modulate\Artisan\Interceptor\Interceptor;
19
use Modulate\Artisan\Interceptor\OptionBuilder;
20
21
class InterceptorServiceProvider extends ServiceProvider
22
{
23
24
    protected $artisan;
25
26 8
    public function register()
27
    {
28
        if (
29 8
            $this->app->runningInConsole()
30 8
            || $this->app->runningUnitTests()
31
        ) {
32 8
            $this->app->bind(HandlerStackContract::class, HandlerStack::class);
33 8
            $this->app->singleton(InterceptorContract::class, Interceptor::class);
34
35 8
            $this->app->bind(OptionBuilder::class, function() {
36 2
                return new OptionBuilder();
37 8
            });
38
        }
39
40
    }
41
42 8
    public function boot()
43
    {
44
        if (
45 8
            $this->app->runningInConsole()
46 8
            || $this->app->runningUnitTests()
47
        ) {
48 8
            Event::listen(ArtisanStarting::class, function(ArtisanStarting $e) {
49 8
                $this
50 8
                    ->app
51 8
                    ->make(InterceptorContract::class)
52 8
                    ->starting($e->artisan);
53 8
            });
54
55 8
            Event::listen(CommandStarting::class, function(CommandStarting $e) {
56 6
                $this
57 6
                    ->app
58 6
                    ->make(InterceptorContract::class)
59 6
                    ->handleBefore(new InterceptedCommand($e->command, $e->input, $e->output));
0 ignored issues
show
Bug introduced by
It seems like $e->input can also be of type null; however, parameter $input of Modulate\Artisan\Interce...dCommand::__construct() does only seem to accept Symfony\Component\Console\Input\InputInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

59
                    ->handleBefore(new InterceptedCommand($e->command, /** @scrutinizer ignore-type */ $e->input, $e->output));
Loading history...
Bug introduced by
It seems like $e->output can also be of type null; however, parameter $output of Modulate\Artisan\Interce...dCommand::__construct() does only seem to accept Symfony\Component\Console\Output\OutputInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

59
                    ->handleBefore(new InterceptedCommand($e->command, $e->input, /** @scrutinizer ignore-type */ $e->output));
Loading history...
60 8
            });
61 8
            Event::listen(CommandFinished::class, function(CommandFinished $e) {
62 6
                $this
63 6
                    ->app
64 6
                    ->make(InterceptorContract::class)
65 6
                    ->handleAfter(new InterceptedCommand($e->command, $e->input, $e->output, $e->exitCode));
0 ignored issues
show
Bug introduced by
It seems like $e->input can also be of type null; however, parameter $input of Modulate\Artisan\Interce...dCommand::__construct() does only seem to accept Symfony\Component\Console\Input\InputInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
                    ->handleAfter(new InterceptedCommand($e->command, /** @scrutinizer ignore-type */ $e->input, $e->output, $e->exitCode));
Loading history...
Bug introduced by
It seems like $e->output can also be of type null; however, parameter $output of Modulate\Artisan\Interce...dCommand::__construct() does only seem to accept Symfony\Component\Console\Output\OutputInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
                    ->handleAfter(new InterceptedCommand($e->command, $e->input, /** @scrutinizer ignore-type */ $e->output, $e->exitCode));
Loading history...
66 8
            });
67
68
        }
69
    }
70
}
71