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 | * The actual operation name. |
||
| 129 | * |
||
| 130 | * @var string |
||
| 131 | */ |
||
| 132 | protected $operationName ; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * The flag that stop's overserver execution on the actual row. |
||
| 136 | * |
||
| 137 | * @var boolean |
||
| 138 | */ |
||
| 139 | protected $skipRow = false; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Stop's observer execution on the actual row. |
||
| 143 | * |
||
| 144 | * @return void |
||
| 145 | */ |
||
| 146 | public function skipRow() |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Return's the actual line number. |
||
| 153 | * |
||
| 154 | * @return integer The line number |
||
| 155 | */ |
||
| 156 | public function getLineNumber() |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Return's the actual operation name. |
||
| 163 | * |
||
| 164 | * @return string |
||
| 165 | */ |
||
| 166 | public function getOperationName() |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Set's the array containing header row. |
||
| 173 | * |
||
| 174 | * @param array $headers The array with the header row |
||
| 175 | * |
||
| 176 | * @return void |
||
| 177 | */ |
||
| 178 | public function setHeaders(array $headers) |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Return's the array containing header row. |
||
| 185 | * |
||
| 186 | * @return array The array with the header row |
||
| 187 | */ |
||
| 188 | public function getHeaders() |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Queries whether or not the header with the passed name is available. |
||
| 195 | * |
||
| 196 | * @param string $name The header name to query |
||
| 197 | * |
||
| 198 | * @return boolean TRUE if the header is available, else FALSE |
||
| 199 | */ |
||
| 200 | public function hasHeader($name) |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Return's the header value for the passed name. |
||
| 207 | * |
||
| 208 | * @param string $name The name of the header to return the value for |
||
| 209 | * |
||
| 210 | * @return mixed The header value |
||
| 211 | * \InvalidArgumentException Is thrown, if the header with the passed name is NOT available |
||
| 212 | */ |
||
| 213 | public function getHeader($name) |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Add's the header with the passed name and position, if not NULL. |
||
| 227 | * |
||
| 228 | * @param string $name The header name to add |
||
| 229 | * |
||
| 230 | * @return integer The new headers position |
||
| 231 | */ |
||
| 232 | public function addHeader($name) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Queries whether or not debug mode is enabled or not, default is TRUE. |
||
| 244 | * |
||
| 245 | * @return boolean TRUE if debug mode is enabled, else FALSE |
||
| 246 | */ |
||
| 247 | public function isDebugMode() |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Set's the system configuration. |
||
| 254 | * |
||
| 255 | * @param \TechDivision\Import\Configuration\Subject $configuration The system configuration |
||
| 256 | * |
||
| 257 | * @return void |
||
| 258 | */ |
||
| 259 | public function setConfiguration(SubjectConfigurationInterface $configuration) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Return's the system configuration. |
||
| 266 | * |
||
| 267 | * @return \TechDivision\Import\Configuration\SubjectInterface The system configuration |
||
| 268 | */ |
||
| 269 | public function getConfiguration() |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Set's the system logger. |
||
| 276 | * |
||
| 277 | * @param \Psr\Log\LoggerInterface $systemLogger The system logger |
||
| 278 | * |
||
| 279 | * @return void |
||
| 280 | */ |
||
| 281 | public function setSystemLogger(LoggerInterface $systemLogger) |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Return's the system logger. |
||
| 288 | * |
||
| 289 | * @return \Psr\Log\LoggerInterface The system logger instance |
||
| 290 | */ |
||
| 291 | public function getSystemLogger() |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Set's root directory for the virtual filesystem. |
||
| 298 | * |
||
| 299 | * @param string $rootDir The root directory for the virtual filesystem |
||
| 300 | * |
||
| 301 | * @return void |
||
| 302 | */ |
||
| 303 | public function setRootDir($rootDir) |
||
| 307 | |||
| 308 | /** |
||
| 309 | * Return's the root directory for the virtual filesystem. |
||
| 310 | * |
||
| 311 | * @return string The root directory for the virtual filesystem |
||
| 312 | */ |
||
| 313 | public function getRootDir() |
||
| 317 | |||
| 318 | /** |
||
| 319 | * Set's the virtual filesystem instance. |
||
| 320 | * |
||
| 321 | * @param \League\Flysystem\FilesystemInterface $filesystem The filesystem instance |
||
| 322 | * |
||
| 323 | * @return void |
||
| 324 | */ |
||
| 325 | public function setFilesystem(FilesystemInterface $filesystem) |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Return's the virtual filesystem instance. |
||
| 332 | * |
||
| 333 | * @return \League\Flysystem\FilesystemInterface The filesystem instance |
||
| 334 | */ |
||
| 335 | public function getFilesystem() |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Sets's the RegistryProcessor instance to handle the running threads. |
||
| 342 | * |
||
| 343 | * @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor instance |
||
| 344 | * |
||
| 345 | * @return void |
||
| 346 | */ |
||
| 347 | public function setRegistryProcessor(RegistryProcessorInterface $registryProcessor) |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Return's the RegistryProcessor instance to handle the running threads. |
||
| 354 | * |
||
| 355 | * @return \TechDivision\Import\Services\RegistryProcessorInterface The registry processor instance |
||
| 356 | */ |
||
| 357 | public function getRegistryProcessor() |
||
| 361 | |||
| 362 | /** |
||
| 363 | * Set's the unique serial for this import process. |
||
| 364 | * |
||
| 365 | * @param string $serial The unique serial |
||
| 366 | * |
||
| 367 | * @return void |
||
| 368 | */ |
||
| 369 | public function setSerial($serial) |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Return's the unique serial for this import process. |
||
| 376 | * |
||
| 377 | * @return string The unique serial |
||
| 378 | */ |
||
| 379 | public function getSerial() |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Set's the name of the file to import |
||
| 386 | * |
||
| 387 | * @param string $filename The filename |
||
| 388 | * |
||
| 389 | * @return void |
||
| 390 | */ |
||
| 391 | public function setFilename($filename) |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Return's the name of the file to import. |
||
| 398 | * |
||
| 399 | * @return string The filename |
||
| 400 | */ |
||
| 401 | public function getFilename() |
||
| 405 | |||
| 406 | /** |
||
| 407 | * Return's the source date format to use. |
||
| 408 | * |
||
| 409 | * @return string The source date format |
||
| 410 | */ |
||
| 411 | public function getSourceDateFormat() |
||
| 415 | |||
| 416 | /** |
||
| 417 | * Return's the multiple field delimiter character to use, default value is comma (,). |
||
| 418 | * |
||
| 419 | * @return string The multiple field delimiter character |
||
| 420 | */ |
||
| 421 | public function getMultipleFieldDelimiter() |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Return's the initialized PDO connection. |
||
| 428 | * |
||
| 429 | * @return \PDO The initialized PDO connection |
||
| 430 | */ |
||
| 431 | public function getConnection() |
||
| 435 | |||
| 436 | /** |
||
| 437 | * Intializes the previously loaded global data for exactly one bunch. |
||
| 438 | * |
||
| 439 | * @return void |
||
| 440 | * @see \Importer\Csv\Actions\ProductImportAction::prepare() |
||
| 441 | */ |
||
| 442 | public function setUp() |
||
| 456 | |||
| 457 | /** |
||
| 458 | * This method tries to resolve the passed path and returns it. If the path |
||
| 459 | * is relative, the actual working directory will be prepended. |
||
| 460 | * |
||
| 461 | * @param string $path The path to be resolved |
||
| 462 | * |
||
| 463 | * @return string The resolved path |
||
| 464 | * @throws \InvalidArgumentException Is thrown, if the path can not be resolved |
||
| 465 | */ |
||
| 466 | public function resolvePath($path) |
||
| 483 | |||
| 484 | /** |
||
| 485 | * Clean up the global data after importing the variants. |
||
| 486 | * |
||
| 487 | * @return void |
||
| 488 | */ |
||
| 489 | public function tearDown() |
||
| 506 | |||
| 507 | /** |
||
| 508 | * Return's the next source directory, which will be the target directory |
||
| 509 | * of this subject, in most cases. |
||
| 510 | * |
||
| 511 | * @return string The new source directory |
||
| 512 | */ |
||
| 513 | protected function getNewSourceDir() |
||
| 517 | |||
| 518 | /** |
||
| 519 | * Register the passed observer with the specific type. |
||
| 520 | * |
||
| 521 | * @param \TechDivision\Import\Observers\ObserverInterface $observer The observer to register |
||
| 522 | * @param string $type The type to register the observer with |
||
| 523 | * |
||
| 524 | * @return void |
||
| 525 | */ |
||
| 526 | public function registerObserver(ObserverInterface $observer, $type) |
||
| 538 | |||
| 539 | /** |
||
| 540 | * Register the passed callback with the specific type. |
||
| 541 | * |
||
| 542 | * @param \TechDivision\Import\Callbacks\CallbackInterface $callback The subject to register the callbacks for |
||
| 543 | * @param string $type The type to register the callback with |
||
| 544 | * |
||
| 545 | * @return void |
||
| 546 | */ |
||
| 547 | public function registerCallback(CallbackInterface $callback, $type) |
||
| 559 | |||
| 560 | /** |
||
| 561 | * Return's the array with callbacks for the passed type. |
||
| 562 | * |
||
| 563 | * @param string $type The type of the callbacks to return |
||
| 564 | * |
||
| 565 | * @return array The callbacks |
||
| 566 | */ |
||
| 567 | public function getCallbacksByType($type) |
||
| 581 | |||
| 582 | /** |
||
| 583 | * Return's the array with the available observers. |
||
| 584 | * |
||
| 585 | * @return array The observers |
||
| 586 | */ |
||
| 587 | public function getObservers() |
||
| 591 | |||
| 592 | /** |
||
| 593 | * Return's the array with the available callbacks. |
||
| 594 | * |
||
| 595 | * @return array The callbacks |
||
| 596 | */ |
||
| 597 | public function getCallbacks() |
||
| 601 | |||
| 602 | /** |
||
| 603 | * Imports the content of the file with the passed filename. |
||
| 604 | * |
||
| 605 | * @param string $serial The unique process serial |
||
| 606 | * @param string $filename The filename to process |
||
| 607 | * |
||
| 608 | * @return void |
||
| 609 | * @throws \Exception Is thrown, if the import can't be processed |
||
| 610 | */ |
||
| 611 | public function import($serial, $filename) |
||
| 696 | |||
| 697 | /** |
||
| 698 | * This method queries whether or not the passed filename matches |
||
| 699 | * the pattern, based on the subjects configured prefix. |
||
| 700 | * |
||
| 701 | * @param string $filename The filename to match |
||
| 702 | * |
||
| 703 | * @return boolean TRUE if the filename matches, else FALSE |
||
| 704 | */ |
||
| 705 | protected function match($filename) |
||
| 714 | |||
| 715 | /** |
||
| 716 | * Initialize and return the lexer configuration. |
||
| 717 | * |
||
| 718 | * @return \Goodby\CSV\Import\Standard\LexerConfig The lexer configuration |
||
| 719 | */ |
||
| 720 | protected function getLexerConfig() |
||
| 754 | |||
| 755 | /** |
||
| 756 | * Imports the passed row into the database. |
||
| 757 | * |
||
| 758 | * If the import failed, the exception will be catched and logged, |
||
| 759 | * but the import process will be continued. |
||
| 760 | * |
||
| 761 | * @param array $row The row with the data to be imported |
||
| 762 | * |
||
| 763 | * @return void |
||
| 764 | */ |
||
| 765 | public function importRow(array $row) |
||
| 803 | } |
||
| 804 |
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.