| Conditions | 11 |
| Paths | 12 |
| Total Lines | 31 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 19 |
| CRAP Score | 11 |
| Changes | 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 |
||
| 20 | 34 | public function __invoke(ContainerInterface $container) |
|
| 21 | { |
||
| 22 | 34 | $config = $container->has('config') ? $container->get('config') : []; |
|
| 23 | 34 | $loggerConfig = $config['logger'] ?? []; |
|
| 24 | 34 | $handlersAdded = false; |
|
| 25 | |||
| 26 | 34 | $logger = new Logger('app'); |
|
| 27 | |||
| 28 | 34 | if (!empty($loggerConfig)) { |
|
| 29 | 34 | $handlers = $loggerConfig['handlers'] ?? []; |
|
| 30 | 34 | if (!empty($handlers) && is_array($handlers)) { |
|
| 31 | 34 | foreach ($handlers as $handler) { |
|
| 32 | 34 | if (is_object($handler) && $handler instanceof HandlerInterface) { |
|
| 33 | 1 | $logger->pushHandler($handler); |
|
| 34 | 1 | $handlersAdded = true; |
|
| 35 | 33 | } elseif (is_string($handler) && $container->has($handler)) { |
|
| 36 | 32 | $logger->pushHandler($container->get($handler)); |
|
| 37 | 34 | $handlersAdded = true; |
|
| 38 | } |
||
| 39 | } |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | 34 | if (!$handlersAdded) { |
|
| 44 | // add default handler |
||
| 45 | 1 | $baseHandler = new StreamHandler('data/log/app.log'); |
|
| 46 | 1 | $logger->pushHandler($baseHandler); |
|
| 47 | } |
||
| 48 | |||
| 49 | 34 | return $logger; |
|
| 50 | } |
||
| 51 | } |
||
| 52 |