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