| Conditions | 8 | 
| Paths | 2 | 
| Total Lines | 51 | 
| Code Lines | 33 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 7 | ||
| Bugs | 1 | Features | 0 | 
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php | ||
| 14 | public function boot() | ||
|  | |||
| 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 | |||
| 76 | 
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: