DatabaseServiceProviders   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
dl 0
loc 26
ccs 18
cts 18
cp 1
rs 10
c 3
b 0
f 1
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 23 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Cart\ServiceProviders;
5
6
use Cart\Contracts\ServiceProviderContract;
7
use Cart\Drivers\DatabaseDriver;
8
use Illuminate\Database\Capsule\Manager;
9
use Illuminate\Events\Dispatcher;
10
use Illuminate\Container\Container;
11
12
class DatabaseServiceProviders implements ServiceProviderContract
13
{
14
15 2
    public function register(Container $container) : void
16
    {
17 2
        $capsule = new Manager;
18 2
        $prefix = 'cart.drivers.database';
19
20 2
        $capsule->addConnection([
21 2
            'driver'    => config($prefix . '.driver'),
22 2
            'host'      => config($prefix . '.host'),
23 2
            'database'  => config($prefix . '.database'),
24 2
            'username'  => config($prefix . '.username'),
25 2
            'password'  => config($prefix . '.password'),
26 2
            'charset'   => config($prefix . '.charset'),
27 2
            'collation' => config($prefix . '.collation'),
28 2
            'prefix'    => config($prefix . '.prefix'),
29
        ]);
30
31 2
        $capsule->setEventDispatcher(new Dispatcher(app()));
32 2
        $capsule->setAsGlobal();
33 2
        $capsule->bootEloquent();
34 2
        $container->bind(Manager::class, $capsule);
0 ignored issues
show
Bug introduced by
$capsule of type Illuminate\Database\Capsule\Manager is incompatible with the type null|string|Closure expected by parameter $concrete of Illuminate\Container\Container::bind(). ( Ignorable by Annotation )

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

34
        $container->bind(Manager::class, /** @scrutinizer ignore-type */ $capsule);
Loading history...
35
36 2
        $container->bind(DatabaseDriver::class, function () use ($capsule) {
37 1
            return new DatabaseDriver($capsule);
38 2
        });
39
    }
40
}