PaperTrailServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Providers;
4
5
use Illuminate\Support\Facades\Log;
6
use Illuminate\Support\ServiceProvider;
7
use Monolog\Formatter\LineFormatter;
8
use Monolog\Handler\SyslogUdpHandler;
9
10
class PaperTrailServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Bootstrap the application services.
14
     *
15
     * @return void
16
     */
17
    public function boot()
18
    {
19
        //
20
    }
21
22
    /**
23
     * Register the application services.
24
     *
25
     * @return void
26
     */
27
    public function register()
28
    {
29
        if (!(env('APP_ENV', '') === 'testing') && !(env('APP_ENV', '') === 'docker')) {
30
            try {
31
                $monolog = Log::getMonolog();
32
                $syslogHandler = new SyslogUdpHandler(env('PAPERTRAIL_URL'), env('PAPERTRAIL_PORT'));
0 ignored issues
show
Bug introduced by
It seems like env('PAPERTRAIL_PORT') can also be of type string and boolean; however, parameter $port of Monolog\Handler\SyslogUdpHandler::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

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

32
                $syslogHandler = new SyslogUdpHandler(env('PAPERTRAIL_URL'), /** @scrutinizer ignore-type */ env('PAPERTRAIL_PORT'));
Loading history...
33
34
                $formatter = new LineFormatter('%channel%.%level_name%: %message% %extra%');
35
                $syslogHandler->setFormatter($formatter);
36
37
                $monolog->pushHandler($syslogHandler);
38
            } catch (Exception $ex) {
0 ignored issues
show
Bug introduced by
The type App\Providers\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
39
                // Check if Monolog is reachable
40
            }
41
        }
42
    }
43
}
44