Complex classes like DtcQueueExtension 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 DtcQueueExtension, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | class DtcQueueExtension extends Extension |
||
13 | { |
||
14 | 9 | public function load(array $configs, ContainerBuilder $container) |
|
47 | |||
48 | 9 | protected function configDeprecated(array $config, ContainerBuilder $container) |
|
49 | { |
||
50 | 9 | if (isset($config['default_manager'])) { |
|
51 | 1 | $container->setParameter('dtc_queue.manager.job', $config['default_manager']); |
|
52 | } |
||
53 | 9 | if (isset($config['run_manager'])) { |
|
54 | 1 | $container->setParameter('dtc_queue.manager.run', $config['run_manager']); |
|
55 | } |
||
56 | 9 | if (isset($config['job_timing_manager'])) { |
|
57 | 1 | $container->setParameter('dtc_queue.manager.job_timing', $config['job_timing_manager']); |
|
58 | } |
||
59 | 9 | if (isset($config['document_manager'])) { |
|
60 | 1 | $container->setParameter('dtc_queue.odm.document_manager', $config['document_manager']); |
|
61 | } |
||
62 | 9 | if (isset($config['entity_manager'])) { |
|
63 | 1 | $container->setParameter('dtc_queue.orm.entity_manager', $config['entity_manager']); |
|
64 | } |
||
65 | 9 | $this->configClassDeprecated($config, $container); |
|
66 | 9 | $this->configOtherDeprecated($config, $container); |
|
67 | 9 | } |
|
68 | |||
69 | 9 | protected function configClassDeprecated(array $config, ContainerBuilder $container) |
|
70 | { |
||
71 | 9 | if (isset($config['class_job'])) { |
|
72 | 1 | $container->setParameter('dtc_queue.class.job', $config['class_job']); |
|
73 | } |
||
74 | 9 | if (isset($config['class_job_archive'])) { |
|
75 | 1 | $container->setParameter('dtc_queue.class.job_archive', $config['class_job_archive']); |
|
76 | } |
||
77 | 9 | if (isset($config['class_run'])) { |
|
78 | 1 | $container->setParameter('dtc_queue.class.run', $config['class_run']); |
|
79 | } |
||
80 | 9 | if (isset($config['class_run_archive'])) { |
|
81 | 1 | $container->setParameter('dtc_queue.class.run_archive', $config['class_run_archive']); |
|
82 | } |
||
83 | 9 | if (isset($config['class_job_timing'])) { |
|
84 | 1 | $container->setParameter('dtc_queue.class.job_timing', $config['class_job_timing']); |
|
85 | } |
||
86 | 9 | } |
|
87 | |||
88 | 9 | protected function configOtherDeprecated(array $config, ContainerBuilder $container) |
|
89 | { |
||
90 | 9 | if (isset($config['record_timings'])) { |
|
91 | 1 | $container->setParameter('dtc_queue.timings.record', $config['record_timings']); |
|
92 | } |
||
93 | 9 | if (isset($config['record_timings_timezone_offset'])) { |
|
94 | 1 | $container->setParameter('dtc_queue.timings.timezone_offset', $config['record_timings_timezone_offset']); |
|
95 | } |
||
96 | 9 | if (isset($config['record_timings_timezone_offset'])) { |
|
97 | 1 | $container->setParameter('dtc_queue.timings.timezone_offset', $config['record_timings_timezone_offset']); |
|
98 | } |
||
99 | 9 | if (isset($config['priority_max'])) { |
|
100 | 1 | $container->setParameter('dtc_queue.priority.max', $config['priority_max']); |
|
101 | } |
||
102 | 9 | if (isset($config['priority_direction'])) { |
|
103 | 1 | $container->setParameter('dtc_queue.priority.direction', $config['priority_direction']); |
|
104 | } |
||
105 | 9 | } |
|
106 | |||
107 | 9 | protected function configRedis(array $config, ContainerBuilder $container) |
|
108 | { |
||
109 | 9 | $container->setParameter('dtc_queue.redis.prefix', $config['redis']['prefix']); |
|
110 | 9 | if (isset($config['redis']['snc_redis']['type'])) { |
|
111 | 1 | $container->setParameter('dtc_queue.redis.snc_redis.type', $config['redis']['snc_redis']['type']); |
|
112 | 1 | $container->setParameter('dtc_queue.redis.snc_redis.alias', $config['redis']['snc_redis']['alias']); |
|
113 | 8 | } elseif (isset($config['redis']['predis']['dsn'])) { |
|
114 | 1 | $container->setParameter('dtc_queue.redis.predis.dsn', $config['redis']['predis']['dsn']); |
|
115 | 8 | } elseif (isset($config['redis']['predis']['connection_parameters']['host'])) { |
|
116 | 1 | $container->setParameter('dtc_queue.redis.predis.connection_parameters', $config['redis']['predis']['connection_parameters']); |
|
117 | } |
||
118 | 9 | $this->configPhpRedis($config, $container); |
|
119 | 9 | } |
|
120 | |||
121 | 9 | protected function configPhpRedis(array $config, ContainerBuilder $container) |
|
122 | { |
||
123 | 9 | $container->setParameter('dtc_queue.redis.phpredis.host', isset($config['redis']['phpredis']['host']) ? $config['redis']['phpredis']['host'] : null); |
|
124 | 9 | $container->setParameter('dtc_queue.redis.phpredis.port', isset($config['redis']['phpredis']['port']) ? $config['redis']['phpredis']['port'] : null); |
|
125 | 9 | $container->setParameter('dtc_queue.redis.phpredis.timeout', isset($config['redis']['phpredis']['timeout']) ? $config['redis']['phpredis']['timeout'] : null); |
|
126 | 9 | $container->setParameter('dtc_queue.redis.phpredis.retry_interval', isset($config['redis']['phpredis']['retry_interval']) ? $config['redis']['phpredis']['retry_interval'] : null); |
|
127 | 9 | $container->setParameter('dtc_queue.redis.phpredis.read_timeout', isset($config['redis']['phpredis']['read_timeout']) ? $config['redis']['phpredis']['read_timeout'] : null); |
|
128 | 9 | if (isset($config['redis']['phpredis']['auth'])) { |
|
129 | 1 | $container->setParameter('dtc_queue.redis.phpredis.auth', $config['redis']['phpredis']['auth']); |
|
130 | } |
||
131 | 9 | } |
|
132 | |||
133 | 9 | protected function configAdmin(array $config, ContainerBuilder $container) |
|
137 | |||
138 | 9 | protected function configClasses(array $config, ContainerBuilder $container) |
|
146 | |||
147 | 9 | protected function configRecordTimings(array $config, ContainerBuilder $container) |
|
152 | |||
153 | 9 | protected function configRabbitMQ(array $config, ContainerBuilder $container) |
|
154 | { |
||
155 | 9 | if (isset($config['rabbit_mq'])) { |
|
156 | 1 | foreach (['host', 'port', 'user', 'password'] as $value) { |
|
157 | 1 | if (!isset($config['rabbit_mq'][$value])) { |
|
158 | 1 | throw new InvalidConfigurationException('dtc_queue: rabbit_mq must have '.$value.' in config.yml'); |
|
159 | } |
||
160 | } |
||
161 | 1 | $config['rabbit_mq']['queue_args']['max_priority'] = $config['priority']['max']; |
|
162 | 1 | $container->setParameter('dtc_queue.rabbit_mq', $config['rabbit_mq']); |
|
163 | } |
||
164 | 9 | } |
|
165 | |||
166 | 9 | protected function configBeanstalkd(array $config, ContainerBuilder $container) |
|
167 | { |
||
168 | 9 | if (isset($config['beanstalkd'])) { |
|
169 | 1 | if (!isset($config['beanstalkd']['host'])) { |
|
170 | 1 | throw new InvalidConfigurationException('dtc_queue: beanstalkd requires host in config.yml'); |
|
171 | } |
||
172 | } |
||
173 | |||
174 | 9 | if (isset($config['beanstalkd']['host'])) { |
|
175 | 1 | $container->setParameter('dtc_queue.beanstalkd.host', $config['beanstalkd']['host']); |
|
176 | } |
||
177 | 9 | if (isset($config['beanstalkd']['tube'])) { |
|
178 | 1 | $container->setParameter('dtc_queue.beanstalkd.tube', $config['beanstalkd']['tube']); |
|
179 | } |
||
180 | 9 | } |
|
181 | |||
182 | 1 | public function getAlias() |
|
186 | } |
||
187 |