| Conditions | 14 |
| Paths | 1536 |
| Total Lines | 80 |
| Code Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 38 | public function load(array $configs, ContainerBuilder $container): void |
||
| 39 | { |
||
| 40 | $configuration = new Configuration(); |
||
| 41 | $config = $this->processConfiguration($configuration, $configs); |
||
| 42 | |||
| 43 | $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
||
| 44 | $loader->load('services.xml'); |
||
| 45 | |||
| 46 | if (!$config['enabled']) { |
||
| 47 | $config['monolog']['enabled'] = false; |
||
| 48 | $interactor = BlackholeInteractor::class; |
||
| 49 | } elseif (isset($config['interactor'])) { |
||
| 50 | $interactor = $config['interactor']; |
||
| 51 | } else { |
||
| 52 | // Fallback to see if the extension is loaded or not |
||
| 53 | $interactor = \extension_loaded('newrelic') ? NewRelicInteractor::class : BlackholeInteractor::class; |
||
| 54 | } |
||
| 55 | |||
| 56 | if ($config['logging']) { |
||
| 57 | $container->getDefinition(LoggingInteractorDecorator::class) |
||
| 58 | ->replaceArgument(0, new Reference($interactor)); |
||
| 59 | $interactor = LoggingInteractorDecorator::class; |
||
| 60 | } |
||
| 61 | $container->setAlias('ekino.new_relic.interactor', $interactor); |
||
| 62 | |||
| 63 | if (!empty($config['deployment_names'])) { |
||
| 64 | $config['deployment_names'] = \array_values(\array_filter(\explode(';', $config['application_name']))); |
||
| 65 | } |
||
| 66 | |||
| 67 | $container->getDefinition(Config::class) |
||
| 68 | ->replaceArgument(0, $config['application_name']) |
||
| 69 | ->replaceArgument(1, $config['api_key']) |
||
| 70 | ->replaceArgument(2, $config['license_key']) |
||
| 71 | ->replaceArgument(3, $config['xmit']) |
||
| 72 | ->replaceArgument(4, $config['deployment_names']) |
||
| 73 | ; |
||
| 74 | |||
| 75 | if ($config['http']['enabled']) { |
||
| 76 | $loader->load('http_listener.xml'); |
||
| 77 | $container->getDefinition(RequestListener::class) |
||
| 78 | ->replaceArgument(2, $config['http']['ignored_routes']) |
||
| 79 | ->replaceArgument(3, $config['http']['ignored_paths']) |
||
| 80 | ->replaceArgument(4, $this->getTransactionNamingService($config)) |
||
| 81 | ->replaceArgument(5, $config['http']['using_symfony_cache']); |
||
| 82 | |||
| 83 | $container->getDefinition(ResponseListener::class) |
||
| 84 | ->replaceArgument(2, $config['http']['instrument']) |
||
| 85 | ->replaceArgument(3, $config['http']['using_symfony_cache']); |
||
| 86 | } |
||
| 87 | |||
| 88 | if ($config['commands']['enabled']) { |
||
| 89 | $loader->load('command_listener.xml'); |
||
| 90 | $container->getDefinition(CommandListener::class) |
||
| 91 | ->replaceArgument(2, $config['commands']['ignored_commands']); |
||
| 92 | } |
||
| 93 | |||
| 94 | if ($config['exceptions']['enabled']) { |
||
| 95 | $loader->load('exception_listener.xml'); |
||
| 96 | } |
||
| 97 | |||
| 98 | if ($config['deprecations']['enabled']) { |
||
| 99 | $loader->load('deprecation_listener.xml'); |
||
| 100 | } |
||
| 101 | |||
| 102 | if ($config['twig']) { |
||
| 103 | $loader->load('twig.xml'); |
||
| 104 | } |
||
| 105 | |||
| 106 | if ($config['monolog']['enabled']) { |
||
| 107 | if (!\class_exists(\Monolog\Handler\NewRelicHandler::class)) { |
||
| 108 | throw new \LogicException('The "symfony/monolog-bundle" package must be installed in order to use "monolog" option.'); |
||
| 109 | } |
||
| 110 | $loader->load('monolog.xml'); |
||
| 111 | $container->setParameter('ekino.new_relic.monolog.channels', $config['monolog']['channels']); |
||
| 112 | $container->setAlias('ekino.new_relic.logs_handler', $config['monolog']['service']); |
||
| 113 | |||
| 114 | $level = $config['monolog']['level']; |
||
| 115 | $container->findDefinition('ekino.new_relic.logs_handler') |
||
| 116 | ->replaceArgument(0, \is_int($level) ? $level : \constant('Monolog\Logger::'.\strtoupper($level))) |
||
| 117 | ->replaceArgument(2, $config['application_name']); |
||
| 118 | } |
||
| 151 |