InterceptorServiceProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 45
ccs 28
cts 28
cp 1
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 11 3
A boot() 0 24 3
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