Total Complexity | 43 |
Total Lines | 213 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like Notification often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Notification, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
29 | final class Notification implements ModuleConfigurationInterface |
||
30 | { |
||
31 | public function addConfig(NodeBuilder $nodeBuilder): void |
||
71 | } |
||
72 | |||
73 | public function handleDefaultParameters(ContainerBuilder $container): void |
||
85 | } |
||
86 | |||
87 | public function handleConfiguration(array $config, ContainerBuilder $container): void |
||
88 | { |
||
89 | if (!isset($config['notification']) || !isset($config['notification']['enabled']) || false == $config['notification']['enabled']) { |
||
90 | return; |
||
91 | } |
||
92 | |||
93 | $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config')); |
||
94 | $loader->load('services/notification.xml'); |
||
95 | |||
96 | $config = $this->configureSlack($config, $container); |
||
97 | |||
98 | if (!isset($config['notification']['email'])) { |
||
99 | return; |
||
100 | } |
||
101 | |||
102 | $senderInterface = $this->configureSendToQueue($config['notification']['email']['send_via_queue'], $container); |
||
103 | $config = $this->configureProvider($config, $container, $senderInterface); |
||
104 | $config = $this->configureFromAddress($config, $container); |
||
105 | $this->configureFromName($config, $container); |
||
106 | } |
||
107 | |||
108 | private function configureSlack(array $config, ContainerBuilder $container): array |
||
109 | { |
||
110 | if (isset($config['notification']['slack'])) { |
||
111 | if (isset($config['notification']['slack']['client_id'])) { |
||
112 | $container->setParameter('parthenon_notification_slack_client_id', $config['notification']['slack']['client_id']); |
||
113 | } |
||
114 | |||
115 | if (isset($config['notification']['slack']['client_secret'])) { |
||
116 | $container->setParameter('parthenon_notification_slack_client_secret', $config['notification']['slack']['client_secret']); |
||
117 | } |
||
118 | |||
119 | if (isset($config['notification']['slack']['redirect_url'])) { |
||
120 | $container->setParameter('parthenon_notification_slack_redirect_url', $config['notification']['slack']['redirect_url']); |
||
121 | } |
||
122 | } |
||
123 | |||
124 | return $config; |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * @param $send_via_queue |
||
129 | */ |
||
130 | private function configureSendToQueue($send_via_queue, ContainerBuilder $container): string |
||
131 | { |
||
132 | if (true === $send_via_queue) { |
||
133 | $senderInterface = 'parthenon.notification.sender.background'; |
||
134 | |||
135 | $container->setAlias(EmailSenderInterface::class, MessengerEmailSender::class); |
||
136 | } else { |
||
137 | $senderInterface = EmailSenderInterface::class; |
||
138 | } |
||
139 | |||
140 | return $senderInterface; |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * @throws ParameterNotSetException |
||
145 | */ |
||
146 | private function configureMailGun(array $config, ContainerBuilder $container, string $senderInterface): array |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * @throws ParameterNotSetException |
||
171 | */ |
||
172 | private function configureSendgrid(array $config, ContainerBuilder $container, string $senderInterface): array |
||
173 | { |
||
174 | if (!isset($config['notification']['email']['sendgrid']) || empty($config['notification']['email']['sendgrid'])) { |
||
175 | throw new ParameterNotSetException('When the notification.email.provider is SendGrid you need to define sendgrid.api_key'); |
||
176 | } |
||
177 | |||
178 | if (!isset($config['notification']['email']['sendgrid']['api_key']) || empty($config['notification']['email']['sendgrid']['api_key'])) { |
||
179 | throw new ParameterNotSetException('When the notification.email.provider is SendGrid you need to define sendgrid.api_key'); |
||
180 | } |
||
181 | |||
182 | $container->setParameter('parthenon_notification_email_sendgrid_api_key', $config['notification']['email']['sendgrid']['api_key']); |
||
183 | |||
184 | $container->setAlias($senderInterface, SendGridEmailSender::class); |
||
185 | |||
186 | return $config; |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * @throws ParameterNotSetException |
||
191 | */ |
||
192 | private function configurePostmark(array $config, ContainerBuilder $container, string $senderInterface): array |
||
207 | } |
||
208 | |||
209 | /** |
||
210 | * @throws ParameterNotSetException |
||
211 | */ |
||
212 | private function configureProvider(array $config, ContainerBuilder $container, string $senderInterface): array |
||
227 | } |
||
228 | |||
229 | private function configureFromAddress(array $config, ContainerBuilder $container): array |
||
236 | } |
||
237 | |||
238 | private function configureFromName(array $config, ContainerBuilder $container): void |
||
242 | } |
||
243 | } |
||
244 | } |
||
245 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths