Conditions | 11 |
Paths | 384 |
Total Lines | 90 |
Code Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 | '$apiHost' => $config['api_host'], |
||
79 | ] |
||
80 | ); |
||
81 | |||
82 | if ($config['http']['enabled']) { |
||
83 | $loader->load('http_listener.xml'); |
||
84 | $container->getDefinition(RequestListener::class) |
||
85 | ->setArguments( |
||
86 | [ |
||
87 | '$ignoreRoutes' => $config['http']['ignored_routes'], |
||
88 | '$ignoredPaths' => $config['http']['ignored_paths'], |
||
89 | '$symfonyCache' => $config['http']['using_symfony_cache'], |
||
90 | ] |
||
91 | ); |
||
92 | |||
93 | $container->getDefinition(ResponseListener::class) |
||
94 | ->setArguments( |
||
95 | [ |
||
96 | '$instrument' => $config['instrument'], |
||
97 | '$symfonyCache' => $config['http']['using_symfony_cache'], |
||
98 | ] |
||
99 | ); |
||
100 | } |
||
101 | |||
102 | if ($config['commands']['enabled']) { |
||
103 | $loader->load('command_listener.xml'); |
||
104 | $container->getDefinition(CommandListener::class) |
||
105 | ->setArguments( |
||
106 | [ |
||
107 | '$ignoredCommands' => $config['commands']['ignored_commands'], |
||
108 | ] |
||
109 | ); |
||
110 | } |
||
111 | |||
112 | if ($config['exceptions']['enabled']) { |
||
113 | $loader->load('exception_listener.xml'); |
||
114 | } |
||
115 | |||
116 | if ($config['deprecations']['enabled']) { |
||
117 | $loader->load('deprecation_listener.xml'); |
||
118 | } |
||
119 | |||
120 | if ($config['twig']) { |
||
121 | $loader->load('twig.xml'); |
||
122 | } |
||
123 | |||
124 | if ($config['enabled'] && $config['monolog']['enabled']) { |
||
125 | if (!\class_exists(\Monolog\Handler\NewRelicHandler::class)) { |
||
126 | throw new \LogicException('The "symfony/monolog-bundle" package must be installed in order to use "monolog" option.'); |
||
127 | } |
||
128 | $loader->load('monolog.xml'); |
||
129 | $container->setParameter('ekino.new_relic.monolog', $config['monolog'] ?? []); |
||
130 | $container->setParameter('ekino.new_relic.application_name', $config['application_name']); |
||
131 | $container->setAlias('ekino.new_relic.logs_handler', $config['monolog']['service'])->setPublic(false); |
||
132 | } |
||
172 |