SlackAlertServiceProvider::boot()   B
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 3
eloc 15
c 3
b 0
f 0
nc 3
nop 0
dl 0
loc 26
rs 8.8571
1
<?php
2
3
namespace Rutorika\LaravelSlackAlert;
4
5
use Illuminate\Log\Writer;
6
use Illuminate\Support\ServiceProvider;
7
use Monolog\Logger;
8
9
class SlackAlertServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap any application services.
13
     *
14
     * @return void
15
     */
16
    public function boot()
17
    {
18
        $this->publishes([
19
            __DIR__ . '/slack-alert.php' => config_path('slack-alert.php'),
20
        ]);
21
22
        $enabledForEnvironments = config('slack-alert.environments');
23
24
        if (in_array($this->app->environment(), $enabledForEnvironments)) {
25
26
            $channel = config('slack-alert.channel');
27
            $token = config('slack-alert.token');
28
            $name = config('slack-alert.app_name');
29
            $mentionTo = config('slack-alert.mention_to');
30
            $level = config('slack-alert.level');
31
32
            if ($token) {
33
                /** @var Writer $logger */
34
                $logger = $this->app['log'];
35
36
                $slackHandler = new MentionedSlackHandler($token, $channel, $name, true, null, $level);
37
                $slackHandler->setMentionTo($mentionTo);
38
                $logger->getMonolog()->pushHandler($slackHandler);
39
            }
40
        }
41
    }
42
43
    /**
44
     * Register any application services.
45
     *
46
     * @return void
47
     */
48
    public function register()
49
    {
50
        $this->mergeConfigFrom(__DIR__ . '/slack-alert.php', 'slack-alert');
51
    }
52
}
53