Conditions | 9 |
Paths | 24 |
Total Lines | 56 |
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 |
||
34 | public function load(array $configs, ContainerBuilder $container) |
||
35 | { |
||
36 | // Load our YAML resources |
||
37 | $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
||
38 | $loader->load('services.yml'); |
||
39 | |||
40 | // @TODO: Broadcasters array should dynamic |
||
41 | $configuration = new Configuration($this->defaultAdapters, ['slack', 'pusher']); |
||
42 | $config = $this->processConfiguration($configuration, $configs); |
||
43 | |||
44 | foreach ($configs as $subConfig) { |
||
45 | $config = array_merge($config, $subConfig); |
||
46 | } |
||
47 | |||
48 | $enabledChannels = []; |
||
49 | if (!empty($config['channels'])) { |
||
50 | foreach ($config['channels'] as $channel => $channelConfig) { |
||
51 | $enabledChannels[] = $channel; |
||
52 | $container->setParameter('notification.channel.' . $channel . '.enabled', true); |
||
53 | |||
54 | // Set a configuration parameter for each channel also. |
||
55 | $parameters = empty($channelConfig) ? [] : $channelConfig; |
||
56 | $parameterName = 'notification.channel.' . $channel . '.configuration'; |
||
57 | $container->setParameter($parameterName, $parameters); |
||
58 | |||
59 | // Create a service for this channel. |
||
60 | $this->createChannelService($channel, $container, $parameters); |
||
61 | } |
||
62 | } |
||
63 | |||
64 | $container->setParameter('notification.available_channels', $enabledChannels); |
||
65 | |||
66 | // Create the channel service |
||
67 | $this->createChannelManagerService($enabledChannels, $container); |
||
68 | |||
69 | // Create the notification manager service |
||
70 | $this->createNotificationManagerService($container); |
||
71 | |||
72 | // Create broadcasters and broadcast channels |
||
73 | if (!empty($config['broadcasters'])) { |
||
74 | foreach ($config['broadcasters'] as $name => $config) { |
||
75 | $this->createBroadcaster($name, $config, $container); |
||
76 | } |
||
77 | } |
||
78 | |||
79 | // Create the Event driven channel service |
||
80 | $this->createEventDrivenChannel($container); |
||
81 | |||
82 | // @TODO: Check that required parameters are set. |
||
83 | foreach ($this->defaultAdapters as $type) { |
||
84 | if (!$container->hasParameter('notification.channel.' . $type . '.configuration')) { |
||
85 | $container->setParameter('notification.channel.' . $type . '.configuration', []); |
||
86 | $container->setParameter('notification.channel.' . $type . '.enabled', false); |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | |||
149 | } |