Complex classes like WorkerCompilerPass 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 WorkerCompilerPass, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class WorkerCompilerPass implements CompilerPassInterface |
||
| 18 | { |
||
| 19 | 3 | public function process(ContainerBuilder $container) |
|
| 49 | |||
| 50 | 3 | protected function setupAlias(ContainerBuilder $container, $defaultManagerType, $type) |
|
| 63 | |||
| 64 | 3 | protected function setupAliases(ContainerBuilder $container) |
|
| 71 | |||
| 72 | /** |
||
| 73 | * @param ContainerBuilder $container |
||
| 74 | * @param Reference[] $jobManagerRef |
||
| 75 | * @param string $jobClass |
||
| 76 | */ |
||
| 77 | 3 | protected function setupTaggedServices(ContainerBuilder $container, Definition $definition, array $jobManagerRef, $jobClass) |
|
| 97 | |||
| 98 | 2 | protected function setupDoctrineManagers(ContainerBuilder $container) |
|
| 114 | |||
| 115 | /** |
||
| 116 | * @param $managerType |
||
| 117 | * |
||
| 118 | * @return null|string |
||
| 119 | */ |
||
| 120 | 3 | protected function getDirectory($managerType) |
|
| 121 | { |
||
| 122 | 3 | switch ($managerType) { |
|
| 123 | case 'mongodb': // deprecated remove in 3.0 |
||
| 124 | case 'odm': |
||
| 125 | 3 | return 'Document'; |
|
| 126 | case 'beanstalkd': |
||
| 127 | return 'Beanstalkd'; |
||
| 128 | case 'rabbit_mq': |
||
| 129 | return 'RabbitMQ'; |
||
| 130 | case 'orm': |
||
| 131 | return 'Entity'; |
||
| 132 | } |
||
| 133 | |||
| 134 | return null; |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Determines the job class based on the queue manager type. |
||
| 139 | * |
||
| 140 | * @param ContainerBuilder $container |
||
| 141 | * |
||
| 142 | * @return mixed|string |
||
| 143 | * |
||
| 144 | * @throws InvalidConfigurationException |
||
| 145 | */ |
||
| 146 | 3 | protected function getJobClass(ContainerBuilder $container) |
|
| 161 | |||
| 162 | 3 | protected function getRunManagerType(ContainerBuilder $container) |
|
| 171 | |||
| 172 | 3 | protected function getClass(ContainerBuilder $container, $managerType, $type, $className, $baseClass) |
|
| 173 | { |
||
| 174 | 3 | $runClass = $container->hasParameter('dtc_queue.class_'.$type) ? $container->getParameter('dtc_queue.class_'.$type) : null; |
|
| 175 | 3 | if (!$runClass) { |
|
| 176 | 3 | switch ($container->getParameter($managerType)) { |
|
| 177 | case 'mongodb': // deprecated remove in 3.0 |
||
| 178 | case 'odm': |
||
| 179 | 3 | $runClass = 'Dtc\\QueueBundle\\Document\\'.$className; |
|
| 180 | 3 | break; |
|
| 181 | case 'orm': |
||
| 182 | $runClass = 'Dtc\\QueueBundle\\Entity\\'.$className; |
||
| 183 | break; |
||
| 184 | default: |
||
| 185 | $runClass = $baseClass; |
||
| 186 | } |
||
| 187 | } |
||
| 188 | |||
| 189 | 3 | $this->testClass($runClass, $baseClass); |
|
| 190 | |||
| 191 | 3 | return $runClass; |
|
| 192 | } |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @throws ClassNotFoundException |
||
| 196 | * @throws ClassNotSubclassException |
||
| 197 | */ |
||
| 198 | 3 | protected function testClass($className, $parent) |
|
| 209 | |||
| 210 | /** |
||
| 211 | * Determines the job class based on the queue manager type. |
||
| 212 | * |
||
| 213 | * @param ContainerBuilder $container |
||
| 214 | * |
||
| 215 | * @return mixed|string |
||
| 216 | * |
||
| 217 | * @throws ClassNotFoundException |
||
| 218 | * @throws ClassNotSubclassException |
||
| 219 | */ |
||
| 220 | 3 | protected function getJobClassArchive(ContainerBuilder $container) |
|
| 240 | } |
||
| 241 |