| Conditions | 12 |
| Paths | 384 |
| Total Lines | 89 |
| Code Lines | 51 |
| 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 |
||
| 42 | public function load(array $configs, ContainerBuilder $container): void |
||
| 43 | { |
||
| 44 | $configuration = new Configuration(); |
||
| 45 | $config = $this->processConfiguration($configuration, $configs); |
||
| 46 | |||
| 47 | $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
||
| 48 | $loader->load('services.xml'); |
||
| 49 | |||
| 50 | $container->setAlias(NewRelicInteractorInterface::class, $this->getInteractorServiceId($config))->setPublic(false); |
||
| 51 | $container->setAlias(TransactionNamingStrategyInterface::class, $this->getTransactionNamingServiceId($config))->setPublic(false); |
||
| 52 | |||
| 53 | if ($config['logging']) { |
||
| 54 | $container->register(LoggingInteractorDecorator::class) |
||
| 55 | ->setDecoratedService(NewRelicInteractorInterface::class) |
||
| 56 | ->setArguments( |
||
| 57 | [ |
||
| 58 | '$interactor' => new Reference(LoggingInteractorDecorator::class.'.inner'), |
||
| 59 | '$logger' => new Reference('logger', ContainerInterface::NULL_ON_INVALID_REFERENCE), |
||
| 60 | ] |
||
| 61 | ) |
||
| 62 | ->setPublic(false) |
||
| 63 | ; |
||
| 64 | } |
||
| 65 | |||
| 66 | if (empty($config['deployment_names'])) { |
||
| 67 | $config['deployment_names'] = \array_values(\array_filter(\explode(';', $config['application_name'] ?? ''))); |
||
| 68 | } |
||
| 69 | |||
| 70 | $container->getDefinition(Config::class) |
||
| 71 | ->setArguments( |
||
| 72 | [ |
||
| 73 | '$name' => $config['application_name'], |
||
| 74 | '$apiKey' => $config['api_key'], |
||
| 75 | '$licenseKey' => $config['license_key'], |
||
| 76 | '$xmit' => $config['xmit'], |
||
| 77 | '$deploymentNames' => $config['deployment_names'], |
||
| 78 | ] |
||
| 79 | ); |
||
| 80 | |||
| 81 | if ($config['http']['enabled']) { |
||
| 82 | $loader->load('http_listener.xml'); |
||
| 83 | $container->getDefinition(RequestListener::class) |
||
| 84 | ->setArguments( |
||
| 85 | [ |
||
| 86 | '$ignoreRoutes' => $config['http']['ignored_routes'], |
||
| 87 | '$ignoredPaths' => $config['http']['ignored_paths'], |
||
| 88 | '$symfonyCache' => $config['http']['using_symfony_cache'], |
||
| 89 | ] |
||
| 90 | ); |
||
| 91 | |||
| 92 | $container->getDefinition(ResponseListener::class) |
||
| 93 | ->setArguments( |
||
| 94 | [ |
||
| 95 | '$instrument' => $config['instrument'], |
||
| 96 | '$symfonyCache' => $config['http']['using_symfony_cache'], |
||
| 97 | ] |
||
| 98 | ); |
||
| 99 | } |
||
| 100 | |||
| 101 | if ($config['commands']['enabled']) { |
||
| 102 | $loader->load('command_listener.xml'); |
||
| 103 | $container->getDefinition(CommandListener::class) |
||
| 104 | ->setArguments( |
||
| 105 | [ |
||
| 106 | '$ignoredCommands' => $config['commands']['ignored_commands'], |
||
| 107 | ] |
||
| 108 | ); |
||
| 109 | } |
||
| 110 | |||
| 111 | if ($config['exceptions']['enabled']) { |
||
| 112 | $loader->load('exception_listener.xml'); |
||
| 113 | } |
||
| 114 | |||
| 115 | if ($config['deprecations']['enabled']) { |
||
| 116 | $loader->load('deprecation_listener.xml'); |
||
| 117 | } |
||
| 118 | |||
| 119 | if ($config['twig']) { |
||
| 120 | $loader->load('twig.xml'); |
||
| 121 | } |
||
| 122 | |||
| 123 | if (\extension_loaded('newrelic') && $config['enabled'] && $config['monolog']['enabled']) { |
||
| 124 | if (!\class_exists(\Monolog\Handler\NewRelicHandler::class)) { |
||
| 125 | throw new \LogicException('The "symfony/monolog-bundle" package must be installed in order to use "monolog" option.'); |
||
| 126 | } |
||
| 127 | $loader->load('monolog.xml'); |
||
| 128 | $container->setParameter('ekino.new_relic.monolog', $config['monolog'] ?? []); |
||
| 129 | $container->setParameter('ekino.new_relic.application_name', $config['application_name']); |
||
| 130 | $container->setAlias('ekino.new_relic.logs_handler', $config['monolog']['service'])->setPublic(false); |
||
| 131 | } |
||
| 178 |