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 |
||
| 49 | abstract class AbstractSubject implements SubjectInterface |
||
| 50 | { |
||
| 51 | |||
| 52 | /** |
||
| 53 | * The root directory for the virtual filesystem. |
||
| 54 | * |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | protected $rootDir; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * The system configuration. |
||
| 61 | * |
||
| 62 | * @var \TechDivision\Import\Configuration\SubjectInterface |
||
| 63 | */ |
||
| 64 | protected $configuration; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * The system logger implementation. |
||
| 68 | * |
||
| 69 | * @var \Psr\Log\LoggerInterface |
||
| 70 | */ |
||
| 71 | protected $systemLogger; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * The RegistryProcessor instance to handle running threads. |
||
| 75 | * |
||
| 76 | * @var \TechDivision\Import\Services\RegistryProcessorInterface |
||
| 77 | */ |
||
| 78 | protected $registryProcessor; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * The actions unique serial. |
||
| 82 | * |
||
| 83 | * @var string |
||
| 84 | */ |
||
| 85 | protected $serial; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * The name of the file to be imported. |
||
| 89 | * |
||
| 90 | * @var string |
||
| 91 | */ |
||
| 92 | protected $filename; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Array with the subject's observers. |
||
| 96 | * |
||
| 97 | * @var array |
||
| 98 | */ |
||
| 99 | protected $observers = array(); |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Array with the subject's callbacks. |
||
| 103 | * |
||
| 104 | * @var array |
||
| 105 | */ |
||
| 106 | protected $callbacks = array(); |
||
| 107 | |||
| 108 | /** |
||
| 109 | * The subject's callback mappings. |
||
| 110 | * |
||
| 111 | * @var array |
||
| 112 | */ |
||
| 113 | protected $callbackMappings = array(); |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Contain's the column names from the header line. |
||
| 117 | * |
||
| 118 | * @var array |
||
| 119 | */ |
||
| 120 | protected $headers = array(); |
||
| 121 | |||
| 122 | /** |
||
| 123 | * The virtual filesystem instance. |
||
| 124 | * |
||
| 125 | * @var \League\Flysystem\FilesystemInterface |
||
| 126 | */ |
||
| 127 | protected $filesystem; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * The actual line number. |
||
| 131 | * |
||
| 132 | * @var integer |
||
| 133 | */ |
||
| 134 | protected $lineNumber = 0; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * The actual operation name. |
||
| 138 | * |
||
| 139 | * @var string |
||
| 140 | */ |
||
| 141 | protected $operationName ; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * The flag that stop's overserver execution on the actual row. |
||
| 145 | * |
||
| 146 | * @var boolean |
||
| 147 | */ |
||
| 148 | protected $skipRow = false; |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Mappings for attribute code => CSV column header. |
||
| 152 | * |
||
| 153 | * @var array |
||
| 154 | */ |
||
| 155 | protected $headerMappings = array( |
||
| 156 | 'product_online' => 'status', |
||
| 157 | 'tax_class_name' => 'tax_class_id', |
||
| 158 | 'bundle_price_type' => 'price_type', |
||
| 159 | 'bundle_sku_type' => 'sku_type', |
||
| 160 | 'bundle_price_view' => 'price_view', |
||
| 161 | 'bundle_weight_type' => 'weight_type', |
||
| 162 | 'base_image' => 'image', |
||
| 163 | 'base_image_label' => 'image_label', |
||
| 164 | 'thumbnail_image' => 'thumbnail', |
||
| 165 | 'thumbnail_image_label'=> 'thumbnail_label', |
||
| 166 | 'bundle_shipment_type' => 'shipment_type' |
||
| 167 | ); |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Stop's observer execution on the actual row. |
||
| 171 | * |
||
| 172 | * @return void |
||
| 173 | */ |
||
| 174 | public function skipRow() |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Return's the actual line number. |
||
| 181 | * |
||
| 182 | * @return integer The line number |
||
| 183 | */ |
||
| 184 | public function getLineNumber() |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Return's the actual operation name. |
||
| 191 | * |
||
| 192 | * @return string |
||
| 193 | */ |
||
| 194 | public function getOperationName() |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Set's the array containing header row. |
||
| 201 | * |
||
| 202 | * @param array $headers The array with the header row |
||
| 203 | * |
||
| 204 | * @return void |
||
| 205 | */ |
||
| 206 | public function setHeaders(array $headers) |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Return's the array containing header row. |
||
| 213 | * |
||
| 214 | * @return array The array with the header row |
||
| 215 | */ |
||
| 216 | public function getHeaders() |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Queries whether or not the header with the passed name is available. |
||
| 223 | * |
||
| 224 | * @param string $name The header name to query |
||
| 225 | * |
||
| 226 | * @return boolean TRUE if the header is available, else FALSE |
||
| 227 | */ |
||
| 228 | public function hasHeader($name) |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Return's the header value for the passed name. |
||
| 235 | * |
||
| 236 | * @param string $name The name of the header to return the value for |
||
| 237 | * |
||
| 238 | * @return mixed The header value |
||
| 239 | * \InvalidArgumentException Is thrown, if the header with the passed name is NOT available |
||
| 240 | */ |
||
| 241 | public function getHeader($name) |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Add's the header with the passed name and position, if not NULL. |
||
| 255 | * |
||
| 256 | * @param string $name The header name to add |
||
| 257 | * |
||
| 258 | * @return integer The new headers position |
||
| 259 | */ |
||
| 260 | public function addHeader($name) |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Queries whether or not debug mode is enabled or not, default is TRUE. |
||
| 272 | * |
||
| 273 | * @return boolean TRUE if debug mode is enabled, else FALSE |
||
| 274 | */ |
||
| 275 | public function isDebugMode() |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Set's the system configuration. |
||
| 282 | * |
||
| 283 | * @param \TechDivision\Import\Configuration\Subject $configuration The system configuration |
||
| 284 | * |
||
| 285 | * @return void |
||
| 286 | */ |
||
| 287 | public function setConfiguration(SubjectConfigurationInterface $configuration) |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Return's the system configuration. |
||
| 294 | * |
||
| 295 | * @return \TechDivision\Import\Configuration\SubjectInterface The system configuration |
||
| 296 | */ |
||
| 297 | public function getConfiguration() |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Set's the system logger. |
||
| 304 | * |
||
| 305 | * @param \Psr\Log\LoggerInterface $systemLogger The system logger |
||
| 306 | * |
||
| 307 | * @return void |
||
| 308 | */ |
||
| 309 | public function setSystemLogger(LoggerInterface $systemLogger) |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Return's the system logger. |
||
| 316 | * |
||
| 317 | * @return \Psr\Log\LoggerInterface The system logger instance |
||
| 318 | */ |
||
| 319 | public function getSystemLogger() |
||
| 323 | |||
| 324 | /** |
||
| 325 | * Set's root directory for the virtual filesystem. |
||
| 326 | * |
||
| 327 | * @param string $rootDir The root directory for the virtual filesystem |
||
| 328 | * |
||
| 329 | * @return void |
||
| 330 | */ |
||
| 331 | public function setRootDir($rootDir) |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Return's the root directory for the virtual filesystem. |
||
| 338 | * |
||
| 339 | * @return string The root directory for the virtual filesystem |
||
| 340 | */ |
||
| 341 | public function getRootDir() |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Set's the virtual filesystem instance. |
||
| 348 | * |
||
| 349 | * @param \League\Flysystem\FilesystemInterface $filesystem The filesystem instance |
||
| 350 | * |
||
| 351 | * @return void |
||
| 352 | */ |
||
| 353 | public function setFilesystem(FilesystemInterface $filesystem) |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Return's the virtual filesystem instance. |
||
| 360 | * |
||
| 361 | * @return \League\Flysystem\FilesystemInterface The filesystem instance |
||
| 362 | */ |
||
| 363 | public function getFilesystem() |
||
| 367 | |||
| 368 | /** |
||
| 369 | * Sets's the RegistryProcessor instance to handle the running threads. |
||
| 370 | * |
||
| 371 | * @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor instance |
||
| 372 | * |
||
| 373 | * @return void |
||
| 374 | */ |
||
| 375 | public function setRegistryProcessor(RegistryProcessorInterface $registryProcessor) |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Return's the RegistryProcessor instance to handle the running threads. |
||
| 382 | * |
||
| 383 | * @return \TechDivision\Import\Services\RegistryProcessorInterface The registry processor instance |
||
| 384 | */ |
||
| 385 | public function getRegistryProcessor() |
||
| 389 | |||
| 390 | /** |
||
| 391 | * Set's the unique serial for this import process. |
||
| 392 | * |
||
| 393 | * @param string $serial The unique serial |
||
| 394 | * |
||
| 395 | * @return void |
||
| 396 | */ |
||
| 397 | public function setSerial($serial) |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Return's the unique serial for this import process. |
||
| 404 | * |
||
| 405 | * @return string The unique serial |
||
| 406 | */ |
||
| 407 | public function getSerial() |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Set's the name of the file to import |
||
| 414 | * |
||
| 415 | * @param string $filename The filename |
||
| 416 | * |
||
| 417 | * @return void |
||
| 418 | */ |
||
| 419 | public function setFilename($filename) |
||
| 423 | |||
| 424 | /** |
||
| 425 | * Return's the name of the file to import. |
||
| 426 | * |
||
| 427 | * @return string The filename |
||
| 428 | */ |
||
| 429 | public function getFilename() |
||
| 433 | |||
| 434 | /** |
||
| 435 | * Return's the source date format to use. |
||
| 436 | * |
||
| 437 | * @return string The source date format |
||
| 438 | */ |
||
| 439 | public function getSourceDateFormat() |
||
| 443 | |||
| 444 | /** |
||
| 445 | * Return's the multiple field delimiter character to use, default value is comma (,). |
||
| 446 | * |
||
| 447 | * @return string The multiple field delimiter character |
||
| 448 | */ |
||
| 449 | public function getMultipleFieldDelimiter() |
||
| 453 | |||
| 454 | /** |
||
| 455 | * Return's the initialized PDO connection. |
||
| 456 | * |
||
| 457 | * @return \PDO The initialized PDO connection |
||
| 458 | */ |
||
| 459 | public function getConnection() |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Intializes the previously loaded global data for exactly one bunch. |
||
| 466 | * |
||
| 467 | * @return void |
||
| 468 | * @see \Importer\Csv\Actions\ProductImportAction::prepare() |
||
| 469 | */ |
||
| 470 | public function setUp() |
||
| 488 | |||
| 489 | /** |
||
| 490 | * This method tries to resolve the passed path and returns it. If the path |
||
| 491 | * is relative, the actual working directory will be prepended. |
||
| 492 | * |
||
| 493 | * @param string $path The path to be resolved |
||
| 494 | * |
||
| 495 | * @return string The resolved path |
||
| 496 | * @throws \InvalidArgumentException Is thrown, if the path can not be resolved |
||
| 497 | */ |
||
| 498 | public function resolvePath($path) |
||
| 515 | |||
| 516 | /** |
||
| 517 | * Clean up the global data after importing the variants. |
||
| 518 | * |
||
| 519 | * @return void |
||
| 520 | */ |
||
| 521 | public function tearDown() |
||
| 538 | |||
| 539 | /** |
||
| 540 | * Return's the next source directory, which will be the target directory |
||
| 541 | * of this subject, in most cases. |
||
| 542 | * |
||
| 543 | * @return string The new source directory |
||
| 544 | */ |
||
| 545 | protected function getNewSourceDir() |
||
| 549 | |||
| 550 | /** |
||
| 551 | * Register the passed observer with the specific type. |
||
| 552 | * |
||
| 553 | * @param \TechDivision\Import\Observers\ObserverInterface $observer The observer to register |
||
| 554 | * @param string $type The type to register the observer with |
||
| 555 | * |
||
| 556 | * @return void |
||
| 557 | */ |
||
| 558 | public function registerObserver(ObserverInterface $observer, $type) |
||
| 570 | |||
| 571 | /** |
||
| 572 | * Register the passed callback with the specific type. |
||
| 573 | * |
||
| 574 | * @param \TechDivision\Import\Callbacks\CallbackInterface $callback The subject to register the callbacks for |
||
| 575 | * @param string $type The type to register the callback with |
||
| 576 | * |
||
| 577 | * @return void |
||
| 578 | */ |
||
| 579 | public function registerCallback(CallbackInterface $callback, $type) |
||
| 591 | |||
| 592 | /** |
||
| 593 | * Return's the array with callbacks for the passed type. |
||
| 594 | * |
||
| 595 | * @param string $type The type of the callbacks to return |
||
| 596 | * |
||
| 597 | * @return array The callbacks |
||
| 598 | */ |
||
| 599 | public function getCallbacksByType($type) |
||
| 613 | |||
| 614 | /** |
||
| 615 | * Return's the array with the available observers. |
||
| 616 | * |
||
| 617 | * @return array The observers |
||
| 618 | */ |
||
| 619 | public function getObservers() |
||
| 623 | |||
| 624 | /** |
||
| 625 | * Return's the array with the available callbacks. |
||
| 626 | * |
||
| 627 | * @return array The callbacks |
||
| 628 | */ |
||
| 629 | public function getCallbacks() |
||
| 633 | |||
| 634 | /** |
||
| 635 | * Return's the callback mappings for this subject. |
||
| 636 | * |
||
| 637 | * @return array The array with the subject's callback mappings |
||
| 638 | */ |
||
| 639 | public function getCallbackMappings() |
||
| 643 | |||
| 644 | /** |
||
| 645 | * Imports the content of the file with the passed filename. |
||
| 646 | * |
||
| 647 | * @param string $serial The unique process serial |
||
| 648 | * @param string $filename The filename to process |
||
| 649 | * |
||
| 650 | * @return void |
||
| 651 | * @throws \Exception Is thrown, if the import can't be processed |
||
| 652 | */ |
||
| 653 | public function import($serial, $filename) |
||
| 738 | |||
| 739 | /** |
||
| 740 | * This method queries whether or not the passed filename matches |
||
| 741 | * the pattern, based on the subjects configured prefix. |
||
| 742 | * |
||
| 743 | * @param string $filename The filename to match |
||
| 744 | * |
||
| 745 | * @return boolean TRUE if the filename matches, else FALSE |
||
| 746 | */ |
||
| 747 | protected function match($filename) |
||
| 756 | |||
| 757 | /** |
||
| 758 | * Initialize and return the lexer configuration. |
||
| 759 | * |
||
| 760 | * @return \Goodby\CSV\Import\Standard\LexerConfig The lexer configuration |
||
| 761 | */ |
||
| 762 | protected function getLexerConfig() |
||
| 796 | |||
| 797 | /** |
||
| 798 | * Imports the passed row into the database. |
||
| 799 | * |
||
| 800 | * If the import failed, the exception will be catched and logged, |
||
| 801 | * but the import process will be continued. |
||
| 802 | * |
||
| 803 | * @param array $row The row with the data to be imported |
||
| 804 | * |
||
| 805 | * @return void |
||
| 806 | */ |
||
| 807 | public function importRow(array $row) |
||
| 847 | |||
| 848 | /** |
||
| 849 | * Map the passed attribute code, if a header mapping exists and return the |
||
| 850 | * mapped mapping. |
||
| 851 | * |
||
| 852 | * @param string $attributeCode The attribute code to map |
||
| 853 | * |
||
| 854 | * @return string The mapped attribute code, or the original one |
||
| 855 | */ |
||
| 856 | public function mapAttributeCodeByHeaderMapping($attributeCode) |
||
| 867 | |||
| 868 | /** |
||
| 869 | * Return's TRUE if an OK file is needed for the subject to be processed, else FALSE. |
||
| 870 | * |
||
| 871 | * @return boolean TRUE if the subject needs an OK file to be executed, else FALSE |
||
| 872 | */ |
||
| 873 | public function needsOkFile() |
||
| 877 | } |
||
| 878 |
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.