| Conditions | 5 |
| Paths | 2 |
| Total Lines | 51 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 86 | public function register(Container $app): void |
||
| 87 | { |
||
| 88 | $config = $app->parameters['monolog'] ?? []; |
||
| 89 | |||
| 90 | $app['monolog'] = function (Container $app) use ($config): Logger { |
||
| 91 | $log = new Logger($config['name']); |
||
| 92 | $handler = new Handler\GroupHandler($app['monolog.handlers']); |
||
| 93 | |||
| 94 | $log->pushHandler($handler); |
||
| 95 | |||
| 96 | return $log; |
||
| 97 | }; |
||
| 98 | |||
| 99 | $app->alias('logger', 'monolog'); |
||
| 100 | |||
| 101 | $app['monolog.formatter'] = new \Monolog\Formatter\LineFormatter(); |
||
| 102 | $app['monolog.handler'] = $defaultHandler = function (Container $app) use ($config): Handler\StreamHandler { |
||
| 103 | $level = MonologServiceProvider::translateLevel($config['level']); |
||
| 104 | |||
| 105 | if (null !== $config['logfile']) { |
||
| 106 | $config['logfile'] = $app->parameters['project_dir'] . $config['logfile']; |
||
| 107 | } |
||
| 108 | |||
| 109 | $handler = new Handler\StreamHandler($config['logfile'], $level, $config['bubble'], $config['permission']); |
||
| 110 | $handler->setFormatter($app['monolog.formatter']); |
||
| 111 | |||
| 112 | return $handler; |
||
| 113 | }; |
||
| 114 | |||
| 115 | $app['monolog.handlers'] = function (Container $app) use ($config, $defaultHandler) { |
||
| 116 | $handlers = []; |
||
| 117 | |||
| 118 | // enables the default handler if a logfile was set or the monolog.handler service was redefined |
||
| 119 | if ($config['logfile'] || $defaultHandler !== $app->get('monolog.handler')) { |
||
| 120 | $handlers[] = $app['monolog.handler']; |
||
| 121 | } |
||
| 122 | |||
| 123 | return $handlers; |
||
| 124 | }; |
||
| 125 | |||
| 126 | if ($app->parameters['debug']) { |
||
| 127 | $app->extend( |
||
| 128 | 'dispatcher', |
||
| 129 | function (EventDispatcherInterface $dispatcher, Container $app): TraceableEventDispatcher { |
||
| 130 | return new TraceableEventDispatcher($dispatcher, $app['logger']); |
||
| 131 | } |
||
| 132 | ); |
||
| 133 | } |
||
| 134 | $app['monolog.listener'] = $app->call(LogListener::class, [1 => $config['exception_logger_filter']]); |
||
| 135 | |||
| 136 | unset($app->parameters['monolog']); |
||
| 137 | } |
||
| 182 |