Complex classes like AbstractSubject 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 AbstractSubject, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 46 | abstract class AbstractSubject implements SubjectInterface |
||
| 47 | { |
||
| 48 | |||
| 49 | /** |
||
| 50 | * The root directory for the virtual filesystem. |
||
| 51 | * |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | protected $rootDir; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * The system configuration. |
||
| 58 | * |
||
| 59 | * @var \TechDivision\Import\Configuration\SubjectInterface |
||
| 60 | */ |
||
| 61 | protected $configuration; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * The system logger implementation. |
||
| 65 | * |
||
| 66 | * @var \Psr\Log\LoggerInterface |
||
| 67 | */ |
||
| 68 | protected $systemLogger; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * The RegistryProcessor instance to handle running threads. |
||
| 72 | * |
||
| 73 | * @var \TechDivision\Import\Services\RegistryProcessorInterface |
||
| 74 | */ |
||
| 75 | protected $registryProcessor; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * The actions unique serial. |
||
| 79 | * |
||
| 80 | * @var string |
||
| 81 | */ |
||
| 82 | protected $serial; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * The name of the file to be imported. |
||
| 86 | * |
||
| 87 | * @var string |
||
| 88 | */ |
||
| 89 | protected $filename; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Array with the subject's observers. |
||
| 93 | * |
||
| 94 | * @var array |
||
| 95 | */ |
||
| 96 | protected $observers = array(); |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Array with the subject's callbacks. |
||
| 100 | * |
||
| 101 | * @var array |
||
| 102 | */ |
||
| 103 | protected $callbacks = array(); |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Contain's the column names from the header line. |
||
| 107 | * |
||
| 108 | * @var array |
||
| 109 | */ |
||
| 110 | protected $headers = array(); |
||
| 111 | |||
| 112 | /** |
||
| 113 | * The virtual filesystem instance. |
||
| 114 | * |
||
| 115 | * @var \League\Flysystem\FilesystemInterface |
||
| 116 | */ |
||
| 117 | protected $filesystem; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Set's the array containing header row. |
||
| 121 | * |
||
| 122 | * @param array $headers The array with the header row |
||
| 123 | * |
||
| 124 | * @return void |
||
| 125 | */ |
||
| 126 | public function setHeaders(array $headers) |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Return's the array containing header row. |
||
| 133 | * |
||
| 134 | * @return array The array with the header row |
||
| 135 | */ |
||
| 136 | public function getHeaders() |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Set's the system configuration. |
||
| 143 | * |
||
| 144 | * @param \TechDivision\Import\Configuration\Subject $configuration The system configuration |
||
| 145 | * |
||
| 146 | * @return void |
||
| 147 | */ |
||
| 148 | public function setConfiguration(SubjectConfigurationInterface $configuration) |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Return's the system configuration. |
||
| 155 | * |
||
| 156 | * @return \TechDivision\Import\Configuration\SubjectInterface The system configuration |
||
| 157 | */ |
||
| 158 | public function getConfiguration() |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Set's the system logger. |
||
| 165 | * |
||
| 166 | * @param \Psr\Log\LoggerInterface $systemLogger The system logger |
||
| 167 | * |
||
| 168 | * @return void |
||
| 169 | */ |
||
| 170 | public function setSystemLogger(LoggerInterface $systemLogger) |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Return's the system logger. |
||
| 177 | * |
||
| 178 | * @return \Psr\Log\LoggerInterface The system logger instance |
||
| 179 | */ |
||
| 180 | public function getSystemLogger() |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Set's root directory for the virtual filesystem. |
||
| 187 | * |
||
| 188 | * @param string $rootDir The root directory for the virtual filesystem |
||
| 189 | * |
||
| 190 | * @return void |
||
| 191 | */ |
||
| 192 | public function setRootDir($rootDir) |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Return's the root directory for the virtual filesystem. |
||
| 199 | * |
||
| 200 | * @return string The root directory for the virtual filesystem |
||
| 201 | */ |
||
| 202 | public function getRootDir() |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Set's the virtual filesystem instance. |
||
| 209 | * |
||
| 210 | * @param \League\Flysystem\FilesystemInterface $filesystem The filesystem instance |
||
| 211 | * |
||
| 212 | * @return void |
||
| 213 | */ |
||
| 214 | public function setFilesystem(FilesystemInterface $filesystem) |
||
| 218 | |||
| 219 | /** |
||
| 220 | * Return's the virtual filesystem instance. |
||
| 221 | * |
||
| 222 | * @return \League\Flysystem\FilesystemInterface The filesystem instance |
||
| 223 | */ |
||
| 224 | public function getFilesystem() |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Sets's the RegistryProcessor instance to handle the running threads. |
||
| 231 | * |
||
| 232 | * @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor instance |
||
| 233 | * |
||
| 234 | * @return void |
||
| 235 | */ |
||
| 236 | public function setRegistryProcessor(RegistryProcessorInterface $registryProcessor) |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Return's the RegistryProcessor instance to handle the running threads. |
||
| 243 | * |
||
| 244 | * @return \TechDivision\Import\Services\RegistryProcessorInterface The registry processor instance |
||
| 245 | */ |
||
| 246 | public function getRegistryProcessor() |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Set's the unique serial for this import process. |
||
| 253 | * |
||
| 254 | * @param string $serial The unique serial |
||
| 255 | * |
||
| 256 | * @return void |
||
| 257 | */ |
||
| 258 | public function setSerial($serial) |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Return's the unique serial for this import process. |
||
| 265 | * |
||
| 266 | * @return string The unique serial |
||
| 267 | */ |
||
| 268 | public function getSerial() |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Set's the name of the file to import |
||
| 275 | * |
||
| 276 | * @param string $filename The filename |
||
| 277 | * |
||
| 278 | * @return void |
||
| 279 | */ |
||
| 280 | public function setFilename($filename) |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Return's the name of the file to import. |
||
| 287 | * |
||
| 288 | * @return string The filename |
||
| 289 | */ |
||
| 290 | public function getFilename() |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Return's the source date format to use. |
||
| 297 | * |
||
| 298 | * @return string The source date format |
||
| 299 | */ |
||
| 300 | public function getSourceDateFormat() |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Return's the initialized PDO connection. |
||
| 307 | * |
||
| 308 | * @return \PDO The initialized PDO connection |
||
| 309 | */ |
||
| 310 | public function getConnection() |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Intializes the previously loaded global data for exactly one bunch. |
||
| 317 | * |
||
| 318 | * @return void |
||
| 319 | * @see \Importer\Csv\Actions\ProductImportAction::prepare() |
||
| 320 | */ |
||
| 321 | public function setUp() |
||
| 332 | |||
| 333 | /** |
||
| 334 | * This method tries to resolve the passed path and returns it. If the path |
||
| 335 | * is relative, the actual working directory will be prepended. |
||
| 336 | * |
||
| 337 | * @param string $path The path to be resolved |
||
| 338 | * |
||
| 339 | * @return string The resolved path |
||
| 340 | * @throws \InvalidArgumentException Is thrown, if the path can not be resolved |
||
| 341 | */ |
||
| 342 | public function resolvePath($path) |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Clean up the global data after importing the variants. |
||
| 362 | * |
||
| 363 | * @return void |
||
| 364 | */ |
||
| 365 | public function tearDown() |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Register the passed observer with the specific type. |
||
| 371 | * |
||
| 372 | * @param \TechDivision\Import\Observers\ObserverInterface $observer The observer to register |
||
| 373 | * @param string $type The type to register the observer with |
||
| 374 | * |
||
| 375 | * @return void |
||
| 376 | */ |
||
| 377 | public function registerObserver(ObserverInterface $observer, $type) |
||
| 389 | |||
| 390 | /** |
||
| 391 | * Register the passed callback with the specific type. |
||
| 392 | * |
||
| 393 | * @param \TechDivision\Import\Callbacks\CallbackInterface $callback The subject to register the callbacks for |
||
| 394 | * @param string $type The type to register the callback with |
||
| 395 | * |
||
| 396 | * @return void |
||
| 397 | */ |
||
| 398 | public function registerCallback(CallbackInterface $callback, $type) |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Return's the array with callbacks for the passed type. |
||
| 413 | * |
||
| 414 | * @param string $type The type of the callbacks to return |
||
| 415 | * |
||
| 416 | * @return array The callbacks |
||
| 417 | */ |
||
| 418 | public function getCallbacksByType($type) |
||
| 432 | |||
| 433 | /** |
||
| 434 | * Return's the array with the available observers. |
||
| 435 | * |
||
| 436 | * @return array The observers |
||
| 437 | */ |
||
| 438 | public function getObservers() |
||
| 442 | |||
| 443 | /** |
||
| 444 | * Return's the array with the available callbacks. |
||
| 445 | * |
||
| 446 | * @return array The callbacks |
||
| 447 | */ |
||
| 448 | public function getCallbacks() |
||
| 452 | |||
| 453 | /** |
||
| 454 | * Imports the content of the file with the passed filename. |
||
| 455 | * |
||
| 456 | * @param string $serial The unique process serial |
||
| 457 | * @param string $filename The filename to process |
||
| 458 | * |
||
| 459 | * @return void |
||
| 460 | */ |
||
| 461 | public function import($serial, $filename) |
||
| 513 | |||
| 514 | /** |
||
| 515 | * Initialize and return the lexer configuration. |
||
| 516 | * |
||
| 517 | * @return \Goodby\CSV\Import\Standard\LexerConfig The lexer configuration |
||
| 518 | */ |
||
| 519 | protected function getLexerConfig() |
||
| 553 | |||
| 554 | /** |
||
| 555 | * Imports the passed row into the database. |
||
| 556 | * |
||
| 557 | * If the import failed, the exception will be catched and logged, |
||
| 558 | * but the import process will be continued. |
||
| 559 | * |
||
| 560 | * @param array $row The row with the data to be imported |
||
| 561 | * |
||
| 562 | * @return void |
||
| 563 | */ |
||
| 564 | public function importRow(array $row) |
||
| 583 | } |
||
| 584 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.