ServiceProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 0
loc 50
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 9 1
A register() 0 26 1
1
<?php
2
3
namespace Softonic\AmqpConsumer;
4
5
use Illuminate\Support\Arr;
6
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
7
8
class ServiceProvider extends LaravelServiceProvider
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $packageName = 'amqp-consumer';
14
15
    /**
16
     * Bootstrap the application services.
17
     */
18
    public function boot()
19
    {
20
        $this->publishes(
21
            [
22
                __DIR__ . '/../config/' . $this->packageName . '.php' => config_path($this->packageName . '.php'),
23
            ],
24
            'config'
25
        );
26
    }
27
28
    /**
29
     * Register the application services.
30
     */
31
    public function register()
32
    {
33
        $this->mergeConfigFrom(__DIR__ . '/../config/' . $this->packageName . '.php', $this->packageName);
34
35
        $this->app->bind(AmqpListener::class, function () {
36
            $amqpProperties  = config('amqp-consumer')['properties'];
37
            $messageHandlers = config('amqp-consumer')['message_handlers'];
38
39
            $routingKeys = array_unique(Arr::flatten($messageHandlers));
40
41
            $amqpProperties['routing'] = $routingKeys;
42
43
            return new AmqpListener(
44
                config('amqp-consumer')['queue'],
45
                $amqpProperties
46
            );
47
        });
48
49
        $this->app->bind(AmqpHandler::class, function () {
50
            return new AmqpHandler(
51
                config('amqp-consumer')['message_handlers']
52
            );
53
        });
54
55
        $this->commands([AmqpListener::class]);
56
    }
57
}
58