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