Conditions | 12 |
Paths | 768 |
Total Lines | 99 |
Code Lines | 57 |
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 |
||
40 | public function load(array $configs, ContainerBuilder $container): void |
||
41 | { |
||
42 | $configuration = new Configuration(); |
||
43 | $config = $this->processConfiguration($configuration, $configs); |
||
44 | |||
45 | $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
||
46 | $loader->load('services.xml'); |
||
47 | |||
48 | $container->setAlias(NewRelicInteractorInterface::class, $this->getInteractorServiceId($config)); |
||
49 | $container->setAlias(TransactionNamingStrategyInterface::class, $this->getTransactionNamingServiceId($config)); |
||
50 | |||
51 | if ($config['logging']) { |
||
52 | $container->register(LoggingInteractorDecorator::class) |
||
53 | ->setDecoratedService(NewRelicInteractorInterface::class) |
||
54 | ->setArguments( |
||
55 | [ |
||
56 | '$interactor' => new Reference(LoggingInteractorDecorator::class.'.inner'), |
||
57 | '$logger' => new Reference('logger'), |
||
58 | ] |
||
59 | ) |
||
60 | ->setPublic(false) |
||
61 | ; |
||
62 | } |
||
63 | |||
64 | if (!empty($config['deployment_names'])) { |
||
65 | $config['deployment_names'] = \array_values(\array_filter(\explode(';', $config['application_name']))); |
||
66 | } |
||
67 | |||
68 | $container->getDefinition(Config::class) |
||
69 | ->setArguments( |
||
70 | [ |
||
71 | '$name' => $config['application_name'], |
||
72 | '$apiKey' => $config['api_key'], |
||
73 | '$licenseKey' => $config['license_key'], |
||
74 | '$xmit' => $config['xmit'], |
||
75 | '$deploymentNames' => $config['deployment_names'], |
||
76 | ] |
||
77 | ); |
||
78 | |||
79 | if ($config['http']['enabled']) { |
||
80 | $loader->load('http_listener.xml'); |
||
81 | $container->getDefinition(RequestListener::class) |
||
82 | ->setArguments( |
||
83 | [ |
||
84 | '$ignoreRoutes' => $config['http']['ignored_routes'], |
||
85 | '$ignoredPaths' => $config['http']['ignored_paths'], |
||
86 | '$symfonyCache' => $config['http']['using_symfony_cache'], |
||
87 | ] |
||
88 | ); |
||
89 | |||
90 | $container->getDefinition(ResponseListener::class) |
||
91 | ->setArguments( |
||
92 | [ |
||
93 | '$instrument' => $config['http']['instrument'], |
||
94 | '$symfonyCache' => $config['http']['using_symfony_cache'], |
||
95 | ] |
||
96 | ); |
||
97 | } |
||
98 | |||
99 | if ($config['commands']['enabled']) { |
||
100 | $loader->load('command_listener.xml'); |
||
101 | $container->getDefinition(CommandListener::class) |
||
102 | ->setArguments( |
||
103 | [ |
||
104 | '$ignoredCommands' => $config['commands']['ignored_commands'], |
||
105 | ] |
||
106 | ); |
||
107 | } |
||
108 | |||
109 | if ($config['exceptions']['enabled']) { |
||
110 | $loader->load('exception_listener.xml'); |
||
111 | } |
||
112 | |||
113 | if ($config['deprecations']['enabled']) { |
||
114 | $loader->load('deprecation_listener.xml'); |
||
115 | } |
||
116 | |||
117 | if ($config['twig']) { |
||
118 | $loader->load('twig.xml'); |
||
119 | } |
||
120 | |||
121 | if (!$config['enabled']) { |
||
122 | $config['monolog']['enabled'] = false; |
||
123 | } |
||
124 | if ($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.channels', $config['monolog']['channels']); |
||
130 | $container->setAlias('ekino.new_relic.logs_handler', $config['monolog']['service']); |
||
131 | |||
132 | $level = $config['monolog']['level']; |
||
133 | // This service is used by MonologHandlerPass to inject into Monolog Service |
||
134 | $container->findDefinition('ekino.new_relic.logs_handler') |
||
135 | ->setArguments( |
||
136 | [ |
||
137 | '$level' => \is_int($level) ? $level : \constant('Monolog\Logger::'.\strtoupper($level)), |
||
138 | '$appName' => $config['application_name'], |
||
139 | ] |
||
185 |
The
break
statement is not necessary if it is preceded for example by areturn
statement:If you would like to keep this construct to be consistent with other
case
statements, you can safely mark this issue as a false-positive.