| Conditions | 9 |
| Paths | 2 |
| Total Lines | 62 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 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 |
||
| 31 | public function configureServiceManager(ServiceManager $serviceManager) |
||
| 32 | { |
||
| 33 | $configs = $serviceManager->get('Config'); |
||
| 34 | $configs['parameters'] = array_merge(array( |
||
| 35 | "monolog.logger.class" => "PPI\Framework\Log\Logger", |
||
| 36 | "monolog.gelf.publisher.class" => "Gelf\MessagePublisher", |
||
| 37 | "monolog.handler.stream.class" => "Monolog\Handler\StreamHandler", |
||
| 38 | "monolog.handler.group.class" => "Monolog\Handler\GroupHandler", |
||
| 39 | "monolog.handler.buffer.class" => "Monolog\Handler\BufferHandler", |
||
| 40 | "monolog.handler.rotating_file.class" => "Monolog\Handler\RotatingFileHandler", |
||
| 41 | "monolog.handler.syslog.class" => "Monolog\Handler\SyslogHandler", |
||
| 42 | "monolog.handler.null.class" => "Monolog\Handler\NullHandler", |
||
| 43 | "monolog.handler.test.class" => "Monolog\Handler\TestHandler", |
||
| 44 | "monolog.handler.gelf.class" => "Monolog\Handler\GelfHandler", |
||
| 45 | "monolog.handler.firephp.class" => "Symfony\Bridge\Monolog\Handler\FirePHPHandler", |
||
| 46 | "monolog.handler.chromephp.class" => "Symfony\Bridge\Monolog\Handler\ChromePhpHandler", |
||
| 47 | "monolog.handler.debug.class" => "Symfony\Bridge\Monolog\Handler\DebugHandler", |
||
| 48 | "monolog.handler.swift_mailer.class" => "Monolog\Handler\SwiftMailerHandler", |
||
| 49 | "monolog.handler.native_mailer.class" => "Monolog\Handler\NativeMailerHandler", |
||
| 50 | "monolog.handler.socket.class" => "Monolog\Handler\SocketHandler", |
||
| 51 | "monolog.handler.pushover.class" => "Monolog\Handler\PushoverHandler", |
||
| 52 | "monolog.handler.fingers_crossed.class" => "Monolog\Handler\FingersCrossedHandler", |
||
| 53 | "monolog.handler.fingers_crossed.error_level_activation_strategy.class" => "Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy", |
||
| 54 | ), $configs['parameters']); |
||
| 55 | |||
| 56 | $config = $this->processConfiguration($configs, $serviceManager); |
||
|
|
|||
| 57 | $handlersToChannels = array(); |
||
| 58 | |||
| 59 | if (isset($config['handlers'])) { |
||
| 60 | $handlers = array(); |
||
| 61 | |||
| 62 | foreach ($config['handlers'] as $name => $handler) { |
||
| 63 | $handlers[$handler['priority']][] = array( |
||
| 64 | 'id' => $this->buildHandler($serviceManager, $configs['parameters'], $name, $handler), |
||
| 65 | 'channels' => isset($handler['channels']) ? $handler['channels'] : null, |
||
| 66 | ); |
||
| 67 | } |
||
| 68 | |||
| 69 | $sortedHandlers = array(); |
||
| 70 | foreach ($handlers as $priorityHandlers) { |
||
| 71 | foreach (array_reverse($priorityHandlers) as $handler) { |
||
| 72 | $sortedHandlers[] = $handler; |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | foreach ($sortedHandlers as $handler) { |
||
| 77 | if (!in_array($handler['id'], $this->nestedHandlers)) { |
||
| 78 | $handlersToChannels[$handler['id']] = $handler['channels']; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | $loggerClass = $configs['parameters']['monolog.logger.class']; |
||
| 84 | $serviceManager->setFactory('monolog.logger', function ($serviceManager) use ($loggerClass, $handlersToChannels) { |
||
| 85 | $logger = new $loggerClass('app'); |
||
| 86 | foreach ($handlersToChannels as $handler => $channels) { |
||
| 87 | $logger->pushHandler($serviceManager->get($handler)); |
||
| 88 | } |
||
| 89 | |||
| 90 | return $logger; |
||
| 91 | }); |
||
| 92 | } |
||
| 93 | |||
| 161 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.