CollisionServiceProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 8
dl 0
loc 61
ccs 11
cts 22
cp 0.5
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
A register() 0 28 4
A provides() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of Collision.
5
 *
6
 * (c) Nuno Maduro <[email protected]>
7
 *
8
 *  For the full copyright and license information, please view the LICENSE
9
 *  file that was distributed with this source code.
10
 */
11
12
namespace NunoMaduro\Collision\Adapters\Laravel;
13
14
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract;
15
use Illuminate\Support\ServiceProvider;
16
use NunoMaduro\Collision\Adapters\Laravel\Commands\TestCommand;
17
use NunoMaduro\Collision\Contracts\Provider as ProviderContract;
18
use NunoMaduro\Collision\Handler;
19
use NunoMaduro\Collision\Provider;
20
use NunoMaduro\Collision\SolutionsRepositories\NullSolutionsRepository;
21
use NunoMaduro\Collision\Writer;
22
23
/**
24
 * This is an Collision Laravel Adapter Service Provider implementation.
25
 *
26
 * Registers the Error Handler on Laravel.
27
 *
28
 * @author Nuno Maduro <[email protected]>
29
 */
30
class CollisionServiceProvider extends ServiceProvider
31
{
32
    /**
33
     * {@inheritdoc}
34
     *
35
     * @var bool
36
     */
37
    protected $defer = true;
38
39
    /**
40
     * Boots application services.
41
     *
42
     * @return void
43
     */
44
    public function boot()
45
    {
46
        $this->commands([
47
            TestCommand::class,
48
        ]);
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 3
    public function register()
55
    {
56 3
        if ($this->app->runningInConsole() && !$this->app->runningUnitTests()) {
57
            $this->app->bind(ProviderContract::class, function () {
58
                if ($this->app->has(\Facade\IgnitionContracts\SolutionProviderRepository::class)) {
59
                    $solutionsRepository = new IgnitionSolutionsRepository(
60
                        $this->app->get(\Facade\IgnitionContracts\SolutionProviderRepository::class)
61
                    );
62
                } else {
63
                    $solutionsRepository = new NullSolutionsRepository();
64
                }
65
66
                $writer = new Writer($solutionsRepository);
67
                $handler = new Handler($writer);
68
69
                return new Provider(null, $handler);
70 1
            });
71
72 1
            $appExceptionHandler = $this->app->make(ExceptionHandlerContract::class);
73
74 1
            $this->app->singleton(
75 1
                ExceptionHandlerContract::class,
76
                function ($app) use ($appExceptionHandler) {
77 1
                    return new ExceptionHandler($app, $appExceptionHandler);
78 1
                }
79
            );
80
        }
81 3
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86 1
    public function provides()
87
    {
88 1
        return [ProviderContract::class];
89
    }
90
}
91