LaravelMessengerServiceProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 95%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 81
ccs 19
cts 20
cp 0.95
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 8 1
A boot() 0 10 3
A provides() 0 8 1
A bindModels() 0 13 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arcanedev\LaravelMessenger;
6
7
use Arcanedev\Support\Providers\PackageServiceProvider;
8
9
/**
10
 * Class     LaravelMessengerServiceProvider
11
 *
12
 * @package  Arcanedev\LaravelMessenger
13
 * @author   ARCANEDEV <[email protected]>
14
 */
15
class LaravelMessengerServiceProvider extends PackageServiceProvider
16
{
17
    /* -----------------------------------------------------------------
18
     |  Properties
19
     | -----------------------------------------------------------------
20
     */
21
22
    /**
23
     * Package name.
24
     *
25
     * @var string
26
     */
27
    protected $package = 'messenger';
28
29
    /* -----------------------------------------------------------------
30
     |  Main Methods
31
     | -----------------------------------------------------------------
32
     */
33
34
    /**
35
     * Register the service provider.
36
     */
37 252
    public function register(): void
38
    {
39 252
        parent::register();
40
41 252
        $this->registerConfig();
42
43 252
        $this->bindModels();
44 252
    }
45
46
    /**
47
     * Boot the service provider.
48
     */
49 252
    public function boot(): void
50
    {
51 252
        if ($this->app->runningInConsole()) {
52 252
            $this->publishConfig();
53
54 252
            Messenger::$runsMigrations
55 252
                ? $this->loadMigrations()
56
                : $this->publishMigrations();
57
        }
58 252
    }
59
60
    /**
61
     * Get the services provided by the provider.
62
     *
63
     * @return array
64
     */
65 6
    public function provides(): array
66
    {
67
        return [
68 6
            Contracts\Discussion::class,
69
            Contracts\Message::class,
70
            Contracts\Participation::class,
71
        ];
72
    }
73
74
    /* -----------------------------------------------------------------
75
     |  Other Methods
76
     | -----------------------------------------------------------------
77
     */
78
79
    /**
80
     * Bind the models.
81
     */
82 252
    private function bindModels(): void
83
    {
84 252
        $config   = $this->app['config'];
85
        $bindings = [
86 252
            Contracts\Discussion::class    => 'discussions',
87
            Contracts\Message::class       => 'messages',
88
            Contracts\Participation::class => 'participations',
89
        ];
90
91 252
        foreach ($bindings as $contract => $key) {
92 252
            $this->bind($contract, $config->get("{$this->package}.{$key}.model"));
93
        }
94 252
    }
95
}
96