LaravelEpilogServiceProvider   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 7
Bugs 1 Features 0
Metric Value
wmc 9
c 7
b 1
f 0
lcom 0
cbo 1
dl 0
loc 69
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
C boot() 0 51 8
A register() 0 4 1
1
<?php
2
3
namespace Rap2hpoutre\LaravelEpilog;
4
5
use Illuminate\Support\ServiceProvider;
6
7
class LaravelEpilogServiceProvider extends ServiceProvider
8
{
9
    /**
10
     * Bootstrap the application services.
11
     *
12
     * @return void
13
     */
14
    public function boot()
0 ignored issues
show
Coding Style introduced by
boot uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
15
    {
16
        $this->publishes(array(
17
            __DIR__ . '/../../config/config.php' => config_path('epilog.php')
18
        ));
19
20
        $logger = \Log::getMonolog();
21
22
        // Additional info in message
23
        $logger->pushProcessor(function($record) {
24
            $info = '';
25
            if (\Auth::check()) {
26
                $info .= 'User #' . \Auth::user()->id . ' (' . \Auth::user()->email . ') - ';
27
            }
28
            if (isset($_SERVER['REMOTE_ADDR'])) {
29
                $info .= 'IP: ' . $_SERVER['REMOTE_ADDR'];
30
            }
31
            if (isset($_SERVER['REQUEST_URI'])) {
32
                $info .= "\n" . $_SERVER['REQUEST_METHOD'] . " " . url($_SERVER['REQUEST_URI']);
33
            }
34
            if (isset($_SERVER['HTTP_REFERER'])) {
35
                $info .= "\nReferer: " . $_SERVER['HTTP_REFERER'];
36
            }
37
            if ($info) {
38
                $info = "\n---\n$info\n---";
39
                if (strpos($record['message'], "\n")) {
40
                    $record['message'] = preg_replace("/\n/", $info . "\n", $record['message'], 1);
41
                } else {
42
                    $record['message'] .= $info . "\n";
43
                }
44
            }
45
            return $record;
46
        });
47
48
        // Slack notification
49
        if (app()->environment(config('epilog.slack.env'))) {
50
            $slackHandler = new \Monolog\Handler\SlackHandler(
51
                config('epilog.slack.token'),
52
                config('epilog.slack.channel'),
53
                config('epilog.slack.username'),
54
                true,
55
                ':skull:',
56
                \Monolog\Logger::ERROR,
57
                true,
58
                true,
59
                true
60
            );
61
            $logger->pushHandler($slackHandler);
62
        }
63
64
    }
65
66
    /**
67
     * Register the application services.
68
     *
69
     * @return void
70
     */
71
    public function register()
72
    {
73
        //
74
    }
75
}
76