LaravelServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 59
ccs 19
cts 19
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A registerSocketCluster() 0 10 1
A boot() 0 8 1
A provides() 0 4 1
1
<?php
2
3
namespace SocketCluster\Providers;
4
5
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
6
use Illuminate\Broadcasting\BroadcastManager;
7
use SocketCluster\WebSocket;
8
use SocketCluster\SocketCluster;
9
use SocketCluster\Laravel\SCBroadcaster;
10
use SocketCluster\Laravel\SCFacade;
11
12
class LaravelServiceProvider extends BaseServiceProvider
13
{
14
    /**
15
     * Indicates if loading of the provider is deferred.
16
     *
17
     * @var bool
18
     */
19
    protected $defer = false;
20
    
21
    /**
22
     * Register bindings in the container.
23
     *
24
     * @return void
25
     */
26 2
    public function register()
27
    {
28 2
        $this->registerSocketCluster();
29 2
    }
30
31
    /**
32
     * Register SocketCluster
33
     *
34
     * @return void
35
     */
36 2
    protected function registerSocketCluster()
37
    {
38
        $this->app->singleton('SocketCluster', function ($app) {
39 1
            $config = $app['config']['broadcasting']['connections']['socketcluster']['options'];
40 1
            $websocket = WebSocket::factory($config);
41 1
            return new SocketCluster($websocket);
42 2
        });
43
44 2
        $this->app->alias('SocketCluster', SocketCluster::class);
45 2
    }
46
47
    /**
48
     * Register new BroadcastManager in boot
49
     *
50
     * @return void
51
     */
52 1
    public function boot()
53
    {
54 1
        $this->app
55 1
            ->make(BroadcastManager::class)
56 1
            ->extend('socketcluster', function ($app) {
57 1
                return new SCBroadcaster($app['SocketCluster']);
58 1
            });
59 1
    }
60
61
    /**
62
     * Get the services provided by the provider.
63
     *
64
     * @return array
65
     */
66 1
    public function provides()
67
    {
68 1
        return ['SocketCluster'];
69
    }
70
}
71