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 | 8 | public function load(array $configs, ContainerBuilder $container) |
|
| 47 | |||
| 48 | 8 | protected function configDeprecated(array $config, ContainerBuilder $container) |
|
| 68 | |||
| 69 | 8 | protected function configClassDeprecated(array $config, ContainerBuilder $container) |
|
| 87 | |||
| 88 | 8 | protected function configOtherDeprecated(array $config, ContainerBuilder $container) |
|
| 106 | |||
| 107 | 8 | protected function configRedis(array $config, ContainerBuilder $container) |
|
| 108 | { |
||
| 109 | 8 | $container->setParameter('dtc_queue.redis.prefix', $config['redis']['prefix']); |
|
| 110 | 8 | 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 | 7 | } elseif (isset($config['redis']['predis']['dsn'])) { |
|
| 114 | 1 | $container->setParameter('dtc_queue.redis.predis.dsn', $config['redis']['predis']['dsn']); |
|
| 115 | 7 | } 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 | 8 | $this->configPhpRedis($config, $container); |
|
| 119 | 8 | } |
|
| 120 | |||
| 121 | 8 | protected function configPhpRedis(array $config, ContainerBuilder $container) |
|
| 122 | { |
||
| 123 | 8 | $container->setParameter('dtc_queue.redis.phpredis.host', isset($config['redis']['phpredis']['host']) ? $config['redis']['phpredis']['host'] : null); |
|
| 124 | 8 | $container->setParameter('dtc_queue.redis.phpredis.port', isset($config['redis']['phpredis']['port']) ? $config['redis']['phpredis']['port'] : null); |
|
| 125 | 8 | $container->setParameter('dtc_queue.redis.phpredis.timeout', isset($config['redis']['phpredis']['timeout']) ? $config['redis']['phpredis']['timeout'] : null); |
|
| 126 | 8 | $container->setParameter('dtc_queue.redis.phpredis.retry_interval', isset($config['redis']['phpredis']['retry_interval']) ? $config['redis']['phpredis']['retry_interval'] : null); |
|
| 127 | 8 | $container->setParameter('dtc_queue.redis.phpredis.read_timeout', isset($config['redis']['phpredis']['read_timeout']) ? $config['redis']['phpredis']['read_timeout'] : null); |
|
| 128 | 8 | if (isset($config['redis']['phpredis']['auth'])) { |
|
| 129 | 1 | $container->setParameter('dtc_queue.redis.phpredis.auth', $config['redis']['phpredis']['auth']); |
|
| 130 | } |
||
| 131 | 8 | } |
|
| 132 | |||
| 133 | 8 | protected function configAdmin(array $config, ContainerBuilder $container) |
|
| 137 | |||
| 138 | 8 | protected function configClasses(array $config, ContainerBuilder $container) |
|
| 146 | |||
| 147 | 8 | protected function configRecordTimings(array $config, ContainerBuilder $container) |
|
| 152 | |||
| 153 | 8 | protected function configRabbitMQ(array $config, ContainerBuilder $container) |
|
| 154 | { |
||
| 155 | 8 | 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 | 8 | } |
|
| 165 | |||
| 166 | 8 | protected function configBeanstalkd(array $config, ContainerBuilder $container) |
|
| 167 | { |
||
| 168 | 8 | 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 | 8 | if (isset($config['beanstalkd']['host'])) { |
|
| 175 | 1 | $container->setParameter('dtc_queue.beanstalkd.host', $config['beanstalkd']['host']); |
|
| 176 | } |
||
| 177 | 8 | if (isset($config['beanstalkd']['tube'])) { |
|
| 178 | 1 | $container->setParameter('dtc_queue.beanstalkd.tube', $config['beanstalkd']['tube']); |
|
| 179 | } |
||
| 180 | 8 | } |
|
| 181 | |||
| 182 | 1 | public function getAlias() |
|
| 186 | } |
||
| 187 |