Complex classes like MatcherObjectFactory 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 MatcherObjectFactory, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 30 | class MatcherObjectFactory implements SingletonInterface |
||
| 31 | { |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Gets a singleton instance of this class. |
||
| 35 | * |
||
| 36 | * @return $this |
||
| 37 | */ |
||
| 38 | static public function getInstance() |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Returns a matcher object. |
||
| 45 | * |
||
| 46 | * @param array $matches |
||
| 47 | * @param string $dataType |
||
| 48 | * @return Matcher |
||
| 49 | * @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException |
||
| 50 | * @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException |
||
| 51 | * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException |
||
| 52 | * @throws \InvalidArgumentException |
||
| 53 | */ |
||
| 54 | public function getMatcher(array $matches = array(), $dataType = '') |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Get a possible id from the URL and apply as filter criteria. |
||
| 80 | * Except if the main module belongs to the File. The id would be a combined identifier |
||
| 81 | * including the storage and a mount point. |
||
| 82 | * |
||
| 83 | * @param Matcher $matcher |
||
| 84 | * @return Matcher $matcher |
||
| 85 | * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException |
||
| 86 | */ |
||
| 87 | protected function applyCriteriaFromUrl(Matcher $matcher) |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @param Matcher $matcher |
||
| 99 | * @return Matcher $matcher |
||
| 100 | * @throws \InvalidArgumentException |
||
| 101 | * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException |
||
| 102 | */ |
||
| 103 | protected function applyCriteriaFromTSConfig(Matcher $matcher) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @param Matcher $matcher |
||
| 135 | * @param array $matches |
||
| 136 | * @return Matcher $matcher |
||
| 137 | */ |
||
| 138 | protected function applyCriteriaFromMatchesArgument(Matcher $matcher, $matches) |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Apply criteria specific to jQuery plugin DataTable. |
||
| 155 | * |
||
| 156 | * @param Matcher $matcher |
||
| 157 | * @param string $dataType |
||
| 158 | * @return Matcher $matcher |
||
| 159 | * @throws \Exception |
||
| 160 | */ |
||
| 161 | protected function applyCriteriaFromDataTables(Matcher $matcher, $dataType) |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @param array $queryParts |
||
| 192 | * @param Matcher $matcher |
||
| 193 | * @param string $dataType |
||
| 194 | * @return Matcher $matcher |
||
| 195 | * @throws \InvalidArgumentException |
||
| 196 | */ |
||
| 197 | protected function parseQuery(array $queryParts, Matcher $matcher, $dataType) |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Tell whether the operator should be equals instead of like for a search, e.g. if the value is numerical. |
||
| 229 | * |
||
| 230 | * @param string $fieldName |
||
| 231 | * @param string $dataType |
||
| 232 | * @param string $value |
||
| 233 | * @return bool |
||
| 234 | * @throws \Exception |
||
| 235 | */ |
||
| 236 | protected function isOperatorEquals($fieldName, $dataType, $value) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Signal that is called for post-processing a matcher object. |
||
| 244 | * |
||
| 245 | * @param Matcher $matcher |
||
| 246 | * @signal |
||
| 247 | * @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException |
||
| 248 | * @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException |
||
| 249 | * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException |
||
| 250 | */ |
||
| 251 | protected function emitPostProcessMatcherObjectSignal(Matcher $matcher) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Get the SignalSlot dispatcher |
||
| 266 | * |
||
| 267 | * @return Dispatcher |
||
| 268 | */ |
||
| 269 | protected function getSignalSlotDispatcher() |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @return ObjectManager |
||
| 276 | * @throws \InvalidArgumentException |
||
| 277 | */ |
||
| 278 | protected function getObjectManager() |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Get the Vidi Module Loader. |
||
| 285 | * |
||
| 286 | * @return ModuleLoader |
||
| 287 | * @throws \InvalidArgumentException |
||
| 288 | */ |
||
| 289 | protected function getModuleLoader() |
||
| 293 | |||
| 294 | /** |
||
| 295 | * @return FieldPathResolver |
||
| 296 | * @throws \InvalidArgumentException |
||
| 297 | */ |
||
| 298 | protected function getFieldPathResolver() |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Returns an instance of the current Backend User. |
||
| 305 | * |
||
| 306 | * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
||
| 307 | */ |
||
| 308 | protected function getBackendUser() |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Returns whether the current mode is Backend |
||
| 315 | * |
||
| 316 | * @return bool |
||
| 317 | */ |
||
| 318 | protected function isBackendMode() |
||
| 322 | } |
||
| 323 |