Conditions | 10 |
Paths | 56 |
Total Lines | 68 |
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 |
||
36 | public function load(array $configs, ContainerBuilder $container) |
||
37 | { |
||
38 | // Load our YAML resources |
||
39 | $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
||
40 | $loader->load('services.yml'); |
||
41 | |||
42 | // @TODO: Broadcasters array should dynamic |
||
43 | $configuration = new Configuration($this->defaultAdapters, ['slack', 'pusher']); |
||
44 | $config = $this->processConfiguration($configuration, $configs); |
||
45 | |||
46 | foreach ($configs as $subConfig) { |
||
47 | $config = array_merge($config, $subConfig); |
||
48 | } |
||
49 | |||
50 | // Create the adapterless channel |
||
51 | $this->createChannel($container, 'notification.channel'); |
||
52 | |||
53 | |||
54 | $enabledChannels = []; |
||
55 | |||
56 | // For each enabled channel build a channel service.. |
||
57 | if (!empty($config['channels'])) { |
||
58 | foreach ($config['channels'] as $channel => $channelConfig) { |
||
59 | $enabledChannels[] = $channel; |
||
60 | $container->setParameter('notification.channel.' . $channel . '.enabled', true); |
||
61 | |||
62 | // Set a configuration parameter for each channel also. |
||
63 | $parameters = empty($channelConfig) ? [] : $channelConfig; |
||
64 | $parameterName = 'notification.channel.' . $channel . '.configuration'; |
||
65 | $container->setParameter($parameterName, $parameters); |
||
66 | |||
67 | // Create a service for this channel. |
||
68 | $this->createChannelService($channel, $container, $parameters); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | $container->setParameter('notification.available_channels', $enabledChannels); |
||
73 | |||
74 | // Create the channel service |
||
75 | $this->createChannelManagerService($enabledChannels, $container); |
||
76 | |||
77 | // Create the notification manager service |
||
78 | $this->createNotificationManagerService($container); |
||
79 | |||
80 | // Create broadcasters and broadcast channels |
||
81 | if (!empty($config['broadcasters'])) { |
||
82 | foreach ($config['broadcasters'] as $name => $config) { |
||
83 | $this->createBroadcaster($name, $config, $container); |
||
84 | } |
||
85 | } |
||
86 | |||
87 | // Create the Event driven channel service |
||
88 | // $this->createEventDrivenChannel($container); |
||
89 | |||
90 | // @TODO: Check that required parameters are set. |
||
91 | foreach ($this->defaultAdapters as $type) { |
||
92 | if (!$container->hasParameter('notification.channel.' . $type . '.configuration')) { |
||
93 | $container->setParameter('notification.channel.' . $type . '.configuration', []); |
||
94 | $container->setParameter('notification.channel.' . $type . '.enabled', false); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | // Build the message crud listener unless its set to false |
||
99 | // @TODO: Add this to documentation |
||
100 | if ($config['use_default_message_subscriber']) { |
||
101 | $this->createNotificationChannelSubscriber($container); |
||
102 | } |
||
103 | } |
||
104 | |||
178 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.