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 |
||
| 47 | abstract class AbstractSubject implements SubjectInterface |
||
| 48 | { |
||
| 49 | |||
| 50 | /** |
||
| 51 | * The root directory for the virtual filesystem. |
||
| 52 | * |
||
| 53 | * @var string |
||
| 54 | */ |
||
| 55 | protected $rootDir; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * The system configuration. |
||
| 59 | * |
||
| 60 | * @var \TechDivision\Import\Configuration\SubjectInterface |
||
| 61 | */ |
||
| 62 | protected $configuration; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * The system logger implementation. |
||
| 66 | * |
||
| 67 | * @var \Psr\Log\LoggerInterface |
||
| 68 | */ |
||
| 69 | protected $systemLogger; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * The RegistryProcessor instance to handle running threads. |
||
| 73 | * |
||
| 74 | * @var \TechDivision\Import\Services\RegistryProcessorInterface |
||
| 75 | */ |
||
| 76 | protected $registryProcessor; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * The actions unique serial. |
||
| 80 | * |
||
| 81 | * @var string |
||
| 82 | */ |
||
| 83 | protected $serial; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * The name of the file to be imported. |
||
| 87 | * |
||
| 88 | * @var string |
||
| 89 | */ |
||
| 90 | protected $filename; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Array with the subject's observers. |
||
| 94 | * |
||
| 95 | * @var array |
||
| 96 | */ |
||
| 97 | protected $observers = array(); |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Array with the subject's callbacks. |
||
| 101 | * |
||
| 102 | * @var array |
||
| 103 | */ |
||
| 104 | protected $callbacks = array(); |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Contain's the column names from the header line. |
||
| 108 | * |
||
| 109 | * @var array |
||
| 110 | */ |
||
| 111 | protected $headers = array(); |
||
| 112 | |||
| 113 | /** |
||
| 114 | * The virtual filesystem instance. |
||
| 115 | * |
||
| 116 | * @var \League\Flysystem\FilesystemInterface |
||
| 117 | */ |
||
| 118 | protected $filesystem; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * The actual line number. |
||
| 122 | * |
||
| 123 | * @var integer |
||
| 124 | */ |
||
| 125 | protected $lineNumber = 0; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Return's the actual line number. |
||
| 129 | * |
||
| 130 | * @return integer The line number |
||
| 131 | */ |
||
| 132 | public function getLineNumber() |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Set's the array containing header row. |
||
| 139 | * |
||
| 140 | * @param array $headers The array with the header row |
||
| 141 | * |
||
| 142 | * @return void |
||
| 143 | */ |
||
| 144 | public function setHeaders(array $headers) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Return's the array containing header row. |
||
| 151 | * |
||
| 152 | * @return array The array with the header row |
||
| 153 | */ |
||
| 154 | public function getHeaders() |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Queries whether or not the header with the passed name is available. |
||
| 161 | * |
||
| 162 | * @param string $name The header name to query |
||
| 163 | * |
||
| 164 | * @return boolean TRUE if the header is available, else FALSE |
||
| 165 | */ |
||
| 166 | public function hasHeader($name) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Return's the header value for the passed name. |
||
| 173 | * |
||
| 174 | * @param string $name The name of the header to return the value for |
||
| 175 | * |
||
| 176 | * @return mixed The header value |
||
| 177 | * \InvalidArgumentException Is thrown, if the header with the passed name is NOT available |
||
| 178 | */ |
||
| 179 | public function getHeader($name) |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Add's the header with the passed name and position, if not NULL. |
||
| 193 | * |
||
| 194 | * @param string $name The header name to add |
||
| 195 | * |
||
| 196 | * @return integer The new headers position |
||
| 197 | */ |
||
| 198 | public function addHeader($name) |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Set's the system configuration. |
||
| 210 | * |
||
| 211 | * @param \TechDivision\Import\Configuration\Subject $configuration The system configuration |
||
| 212 | * |
||
| 213 | * @return void |
||
| 214 | */ |
||
| 215 | public function setConfiguration(SubjectConfigurationInterface $configuration) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Return's the system configuration. |
||
| 222 | * |
||
| 223 | * @return \TechDivision\Import\Configuration\SubjectInterface The system configuration |
||
| 224 | */ |
||
| 225 | public function getConfiguration() |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Set's the system logger. |
||
| 232 | * |
||
| 233 | * @param \Psr\Log\LoggerInterface $systemLogger The system logger |
||
| 234 | * |
||
| 235 | * @return void |
||
| 236 | */ |
||
| 237 | public function setSystemLogger(LoggerInterface $systemLogger) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Return's the system logger. |
||
| 244 | * |
||
| 245 | * @return \Psr\Log\LoggerInterface The system logger instance |
||
| 246 | */ |
||
| 247 | public function getSystemLogger() |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Set's root directory for the virtual filesystem. |
||
| 254 | * |
||
| 255 | * @param string $rootDir The root directory for the virtual filesystem |
||
| 256 | * |
||
| 257 | * @return void |
||
| 258 | */ |
||
| 259 | public function setRootDir($rootDir) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Return's the root directory for the virtual filesystem. |
||
| 266 | * |
||
| 267 | * @return string The root directory for the virtual filesystem |
||
| 268 | */ |
||
| 269 | public function getRootDir() |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Set's the virtual filesystem instance. |
||
| 276 | * |
||
| 277 | * @param \League\Flysystem\FilesystemInterface $filesystem The filesystem instance |
||
| 278 | * |
||
| 279 | * @return void |
||
| 280 | */ |
||
| 281 | public function setFilesystem(FilesystemInterface $filesystem) |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Return's the virtual filesystem instance. |
||
| 288 | * |
||
| 289 | * @return \League\Flysystem\FilesystemInterface The filesystem instance |
||
| 290 | */ |
||
| 291 | public function getFilesystem() |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Sets's the RegistryProcessor instance to handle the running threads. |
||
| 298 | * |
||
| 299 | * @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor instance |
||
| 300 | * |
||
| 301 | * @return void |
||
| 302 | */ |
||
| 303 | public function setRegistryProcessor(RegistryProcessorInterface $registryProcessor) |
||
| 307 | |||
| 308 | /** |
||
| 309 | * Return's the RegistryProcessor instance to handle the running threads. |
||
| 310 | * |
||
| 311 | * @return \TechDivision\Import\Services\RegistryProcessorInterface The registry processor instance |
||
| 312 | */ |
||
| 313 | public function getRegistryProcessor() |
||
| 317 | |||
| 318 | /** |
||
| 319 | * Set's the unique serial for this import process. |
||
| 320 | * |
||
| 321 | * @param string $serial The unique serial |
||
| 322 | * |
||
| 323 | * @return void |
||
| 324 | */ |
||
| 325 | public function setSerial($serial) |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Return's the unique serial for this import process. |
||
| 332 | * |
||
| 333 | * @return string The unique serial |
||
| 334 | */ |
||
| 335 | public function getSerial() |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Set's the name of the file to import |
||
| 342 | * |
||
| 343 | * @param string $filename The filename |
||
| 344 | * |
||
| 345 | * @return void |
||
| 346 | */ |
||
| 347 | public function setFilename($filename) |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Return's the name of the file to import. |
||
| 354 | * |
||
| 355 | * @return string The filename |
||
| 356 | */ |
||
| 357 | public function getFilename() |
||
| 361 | |||
| 362 | /** |
||
| 363 | * Return's the source date format to use. |
||
| 364 | * |
||
| 365 | * @return string The source date format |
||
| 366 | */ |
||
| 367 | public function getSourceDateFormat() |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Return's the multiple field delimiter character to use, default value is comma (,). |
||
| 374 | * |
||
| 375 | * @return string The multiple field delimiter character |
||
| 376 | */ |
||
| 377 | public function getMultipleFieldDelimiter() |
||
| 381 | |||
| 382 | /** |
||
| 383 | * Return's the initialized PDO connection. |
||
| 384 | * |
||
| 385 | * @return \PDO The initialized PDO connection |
||
| 386 | */ |
||
| 387 | public function getConnection() |
||
| 391 | |||
| 392 | /** |
||
| 393 | * Intializes the previously loaded global data for exactly one bunch. |
||
| 394 | * |
||
| 395 | * @return void |
||
| 396 | * @see \Importer\Csv\Actions\ProductImportAction::prepare() |
||
| 397 | */ |
||
| 398 | public function setUp() |
||
| 409 | |||
| 410 | /** |
||
| 411 | * This method tries to resolve the passed path and returns it. If the path |
||
| 412 | * is relative, the actual working directory will be prepended. |
||
| 413 | * |
||
| 414 | * @param string $path The path to be resolved |
||
| 415 | * |
||
| 416 | * @return string The resolved path |
||
| 417 | * @throws \InvalidArgumentException Is thrown, if the path can not be resolved |
||
| 418 | */ |
||
| 419 | public function resolvePath($path) |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Clean up the global data after importing the variants. |
||
| 439 | * |
||
| 440 | * @return void |
||
| 441 | */ |
||
| 442 | public function tearDown() |
||
| 459 | |||
| 460 | /** |
||
| 461 | * Return's the next source directory, which will be the target directory |
||
| 462 | * of this subject, in most cases. |
||
| 463 | * |
||
| 464 | * @return string The new source directory |
||
| 465 | */ |
||
| 466 | protected function getNewSourceDir() |
||
| 470 | |||
| 471 | /** |
||
| 472 | * Register the passed observer with the specific type. |
||
| 473 | * |
||
| 474 | * @param \TechDivision\Import\Observers\ObserverInterface $observer The observer to register |
||
| 475 | * @param string $type The type to register the observer with |
||
| 476 | * |
||
| 477 | * @return void |
||
| 478 | */ |
||
| 479 | public function registerObserver(ObserverInterface $observer, $type) |
||
| 491 | |||
| 492 | /** |
||
| 493 | * Register the passed callback with the specific type. |
||
| 494 | * |
||
| 495 | * @param \TechDivision\Import\Callbacks\CallbackInterface $callback The subject to register the callbacks for |
||
| 496 | * @param string $type The type to register the callback with |
||
| 497 | * |
||
| 498 | * @return void |
||
| 499 | */ |
||
| 500 | public function registerCallback(CallbackInterface $callback, $type) |
||
| 512 | |||
| 513 | /** |
||
| 514 | * Return's the array with callbacks for the passed type. |
||
| 515 | * |
||
| 516 | * @param string $type The type of the callbacks to return |
||
| 517 | * |
||
| 518 | * @return array The callbacks |
||
| 519 | */ |
||
| 520 | public function getCallbacksByType($type) |
||
| 534 | |||
| 535 | /** |
||
| 536 | * Return's the array with the available observers. |
||
| 537 | * |
||
| 538 | * @return array The observers |
||
| 539 | */ |
||
| 540 | public function getObservers() |
||
| 544 | |||
| 545 | /** |
||
| 546 | * Return's the array with the available callbacks. |
||
| 547 | * |
||
| 548 | * @return array The callbacks |
||
| 549 | */ |
||
| 550 | public function getCallbacks() |
||
| 554 | |||
| 555 | /** |
||
| 556 | * Imports the content of the file with the passed filename. |
||
| 557 | * |
||
| 558 | * @param string $serial The unique process serial |
||
| 559 | * @param string $filename The filename to process |
||
| 560 | * |
||
| 561 | * @return void |
||
| 562 | * @throws \Exception Is thrown, if the import can't be processed |
||
| 563 | */ |
||
| 564 | public function import($serial, $filename) |
||
| 649 | |||
| 650 | /** |
||
| 651 | * This method queries whether or not the passed filename matches |
||
| 652 | * the pattern, based on the subjects configured prefix. |
||
| 653 | * |
||
| 654 | * @param string $filename The filename to match |
||
| 655 | * |
||
| 656 | * @return boolean TRUE if the filename matches, else FALSE |
||
| 657 | */ |
||
| 658 | protected function match($filename) |
||
| 667 | |||
| 668 | /** |
||
| 669 | * Initialize and return the lexer configuration. |
||
| 670 | * |
||
| 671 | * @return \Goodby\CSV\Import\Standard\LexerConfig The lexer configuration |
||
| 672 | */ |
||
| 673 | protected function getLexerConfig() |
||
| 707 | |||
| 708 | /** |
||
| 709 | * Imports the passed row into the database. |
||
| 710 | * |
||
| 711 | * If the import failed, the exception will be catched and logged, |
||
| 712 | * but the import process will be continued. |
||
| 713 | * |
||
| 714 | * @param array $row The row with the data to be imported |
||
| 715 | * |
||
| 716 | * @return void |
||
| 717 | */ |
||
| 718 | public function importRow(array $row) |
||
| 740 | } |
||
| 741 |
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.