Complex classes like EndpointConfigurator 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 EndpointConfigurator, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
64 | class EndpointConfigurator |
||
65 | { |
||
66 | /** |
||
67 | * @var Settings |
||
68 | */ |
||
69 | private $settings; |
||
70 | |||
71 | /** |
||
72 | * @var string |
||
73 | */ |
||
74 | private $endpointName; |
||
75 | |||
76 | /** |
||
77 | * @var MessageHandlerRegistry |
||
78 | */ |
||
79 | private $messageHandlerRegistry; |
||
80 | |||
81 | /** |
||
82 | * @var UnicastRoutingTable |
||
83 | */ |
||
84 | private $unicastRoutingTable; |
||
85 | |||
86 | /** |
||
87 | * @var MessageMutatorRegistry |
||
88 | */ |
||
89 | private $messageMutatorRegistry; |
||
90 | |||
91 | /** |
||
92 | * @var PipelineModifications |
||
93 | */ |
||
94 | private $pipelineModifications; |
||
95 | |||
96 | /** |
||
97 | * @param string $endpointName |
||
98 | * @param Settings $settings |
||
99 | * @param MessageHandlerRegistry $messageHandlerRegistry |
||
100 | * @param UnicastRoutingTable $unicastRoutingTable |
||
101 | * @param MessageMutatorRegistry $messageMutatorRegistry |
||
102 | * @param PipelineModifications $pipelineModifications |
||
103 | */ |
||
104 | 25 | public function __construct( |
|
120 | |||
121 | /** |
||
122 | * @param string $endpointName |
||
123 | * |
||
124 | * @return EndpointConfigurator |
||
125 | */ |
||
126 | 1 | public static function create($endpointName) |
|
137 | |||
138 | /** |
||
139 | * @param string $endpointName |
||
140 | */ |
||
141 | public function setEndpointName($endpointName) |
||
145 | |||
146 | /** |
||
147 | * @param PersistenceDefinition $definition |
||
148 | * @param StorageType|null $storageType |
||
149 | * |
||
150 | * @return Persistence\PersistenceConfigurator |
||
151 | */ |
||
152 | 2 | public function usePersistence(PersistenceDefinition $definition, StorageType $storageType = null) |
|
162 | |||
163 | public function clearPersistences() |
||
167 | |||
168 | /** |
||
169 | * @param TransportDefinition $definition |
||
170 | * |
||
171 | * @return Transport\Config\TransportConfigurator |
||
172 | */ |
||
173 | 1 | public function useTransport(TransportDefinition $definition) |
|
181 | |||
182 | /** |
||
183 | * @param SerializationDefinition $definition |
||
184 | * |
||
185 | * @return SerializationConfigurator |
||
186 | */ |
||
187 | 1 | public function useSerialization(SerializationDefinition $definition) |
|
193 | |||
194 | /** |
||
195 | * @param UuidGenerationDefinition $definition |
||
196 | * |
||
197 | * @return UuidGenerationConfigurator |
||
198 | */ |
||
199 | 1 | public function useUuidGeneration(UuidGenerationDefinition $definition) |
|
205 | |||
206 | /** |
||
207 | * Using your own container allows you to register handlers as services. |
||
208 | * Supported containers are the same as those supported by jeremeamia/acclimate-container. |
||
209 | * |
||
210 | * @param mixed $container |
||
211 | */ |
||
212 | 1 | public function useContainer($container) |
|
216 | |||
217 | /** |
||
218 | * @param string $eventFqcn |
||
219 | * @param string $handlerContainerId |
||
220 | */ |
||
221 | 1 | public function registerEventHandler($eventFqcn, $handlerContainerId) |
|
225 | |||
226 | /** |
||
227 | * @param string $commandFqcn |
||
228 | * @param string $handlerContainerId |
||
229 | */ |
||
230 | 1 | public function registerCommandHandler($commandFqcn, $handlerContainerId) |
|
234 | |||
235 | /** |
||
236 | * @param string $mutatorContainerId |
||
237 | */ |
||
238 | 1 | public function registerIncomingLogicalMessageMutator($mutatorContainerId) |
|
242 | |||
243 | /** |
||
244 | * @param string $mutatorContainerId |
||
245 | */ |
||
246 | 1 | public function registerIncomingPhysicalMessageMutator($mutatorContainerId) |
|
250 | |||
251 | /** |
||
252 | * @param string $mutatorContainerId |
||
253 | */ |
||
254 | 1 | public function registerOutgoingLogicalMessageMutator($mutatorContainerId) |
|
258 | |||
259 | /** |
||
260 | * @param string $mutatorContainerId |
||
261 | */ |
||
262 | 1 | public function registerOutgoingPhysicalMessageMutator($mutatorContainerId) |
|
266 | |||
267 | /** |
||
268 | * It allows you to configure which endpoints should receive a command message. |
||
269 | * Command messages are those being sent via ->send and not via ->publish. |
||
270 | * |
||
271 | * @param string $messageFqcn |
||
272 | * @param string $endpointName |
||
273 | */ |
||
274 | 1 | public function registerCommandRoutingRule($messageFqcn, $endpointName) |
|
278 | |||
279 | /** |
||
280 | * @param string $stepId |
||
281 | */ |
||
282 | 1 | public function removePipelineStep($stepId) |
|
286 | |||
287 | /** |
||
288 | * @param string $stepId |
||
289 | * @param string $stepFqcn |
||
290 | * @param callable|null $factory |
||
291 | * @param string|null $description |
||
292 | */ |
||
293 | 1 | public function replacePipelineStep($stepId, $stepFqcn, callable $factory = null, $description = null) |
|
297 | |||
298 | /** |
||
299 | * @param string $stepId |
||
300 | * @param string $stepFqcn |
||
301 | * @param callable|null $factory |
||
302 | * @param string|null $description |
||
303 | * |
||
304 | * @return Pipeline\StepRegistration |
||
305 | */ |
||
306 | 1 | public function registerPipelineStep($stepId, $stepFqcn, callable $factory = null, $description = null) |
|
310 | |||
311 | /** |
||
312 | * Installers are supposed to be tasks that only need to be ran once per deployment, like creating endpoint queues, |
||
313 | * persistence related database tables, etc. They are disabled by default and they need to be explicitly enabled |
||
314 | * if needed. |
||
315 | */ |
||
316 | 1 | public function enableInstallers() |
|
320 | |||
321 | public function disableInstallers() |
||
325 | |||
326 | /** |
||
327 | * @return bool |
||
328 | */ |
||
329 | public function areInstallersEnabled() |
||
333 | |||
334 | /** |
||
335 | * Putting the endpoint in send only mode disables any message receiving capabilities. |
||
336 | * This also means that the endpoint will no longer block waiting for messages when started. |
||
337 | */ |
||
338 | 1 | public function enableSendOnly() |
|
342 | |||
343 | /** |
||
344 | * @return bool |
||
345 | */ |
||
346 | public function isSendOnly() |
||
350 | |||
351 | /** |
||
352 | * @param string $errorQueue |
||
353 | */ |
||
354 | public function sendFailedMessagesTo($errorQueue) |
||
358 | |||
359 | 1 | public function enableDurableMessaging() |
|
363 | |||
364 | 1 | public function disableDurableMessaging() |
|
368 | |||
369 | /** |
||
370 | * @param int $days |
||
371 | */ |
||
372 | 1 | public function setDaysToKeepOutboxDeduplicationData($days) |
|
376 | |||
377 | /** |
||
378 | * @param string $featureFqcn |
||
379 | */ |
||
380 | 1 | public function enableFeature($featureFqcn) |
|
384 | |||
385 | /** |
||
386 | * @param string $featureFqcn |
||
387 | */ |
||
388 | 1 | public function disableFeature($featureFqcn) |
|
392 | |||
393 | /** |
||
394 | * @param int $maxRetries |
||
395 | */ |
||
396 | public function setMaxFirstLevelRetries($maxRetries) |
||
401 | |||
402 | /** |
||
403 | * @return StartableEndpoint |
||
404 | */ |
||
405 | public function build() |
||
436 | |||
437 | private function ensureTransportConfigured() |
||
443 | |||
444 | private function ensureOutboxPersistenceConfigured() |
||
462 | |||
463 | private function ensureSerializationConfigured() |
||
469 | |||
470 | private function ensureUuidGenerationConfigured() |
||
476 | |||
477 | private function registerBaseContainerServices(Container $c) |
||
550 | |||
551 | private function registerKnownFeatures() |
||
576 | } |
||
577 |