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 | * Mappings for attribute code => CSV column header. |
||
| 143 | * |
||
| 144 | * @var array |
||
| 145 | */ |
||
| 146 | protected $headerMappings = array( |
||
| 147 | 'product_online' => 'status', |
||
| 148 | 'tax_class_name' => 'tax_class_id', |
||
| 149 | 'bundle_price_type' => 'price_type', |
||
| 150 | 'bundle_sku_type' => 'sku_type', |
||
| 151 | 'bundle_price_view' => 'price_view', |
||
| 152 | 'bundle_weight_type' => 'weight_type', |
||
| 153 | 'base_image' => 'image', |
||
| 154 | 'base_image_label' => 'image_label', |
||
| 155 | 'thumbnail_image' => 'thumbnail', |
||
| 156 | 'thumbnail_image_label'=> 'thumbnail_label', |
||
| 157 | 'bundle_shipment_type' => 'shipment_type' |
||
| 158 | ); |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Stop's observer execution on the actual row. |
||
| 162 | * |
||
| 163 | * @return void |
||
| 164 | */ |
||
| 165 | public function skipRow() |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Return's the actual line number. |
||
| 172 | * |
||
| 173 | * @return integer The line number |
||
| 174 | */ |
||
| 175 | public function getLineNumber() |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Return's the actual operation name. |
||
| 182 | * |
||
| 183 | * @return string |
||
| 184 | */ |
||
| 185 | public function getOperationName() |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Set's the array containing header row. |
||
| 192 | * |
||
| 193 | * @param array $headers The array with the header row |
||
| 194 | * |
||
| 195 | * @return void |
||
| 196 | */ |
||
| 197 | public function setHeaders(array $headers) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Return's the array containing header row. |
||
| 204 | * |
||
| 205 | * @return array The array with the header row |
||
| 206 | */ |
||
| 207 | public function getHeaders() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Queries whether or not the header with the passed name is available. |
||
| 214 | * |
||
| 215 | * @param string $name The header name to query |
||
| 216 | * |
||
| 217 | * @return boolean TRUE if the header is available, else FALSE |
||
| 218 | */ |
||
| 219 | public function hasHeader($name) |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Return's the header value for the passed name. |
||
| 226 | * |
||
| 227 | * @param string $name The name of the header to return the value for |
||
| 228 | * |
||
| 229 | * @return mixed The header value |
||
| 230 | * \InvalidArgumentException Is thrown, if the header with the passed name is NOT available |
||
| 231 | */ |
||
| 232 | public function getHeader($name) |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Add's the header with the passed name and position, if not NULL. |
||
| 246 | * |
||
| 247 | * @param string $name The header name to add |
||
| 248 | * |
||
| 249 | * @return integer The new headers position |
||
| 250 | */ |
||
| 251 | public function addHeader($name) |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Queries whether or not debug mode is enabled or not, default is TRUE. |
||
| 263 | * |
||
| 264 | * @return boolean TRUE if debug mode is enabled, else FALSE |
||
| 265 | */ |
||
| 266 | public function isDebugMode() |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Set's the system configuration. |
||
| 273 | * |
||
| 274 | * @param \TechDivision\Import\Configuration\Subject $configuration The system configuration |
||
| 275 | * |
||
| 276 | * @return void |
||
| 277 | */ |
||
| 278 | public function setConfiguration(SubjectConfigurationInterface $configuration) |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Return's the system configuration. |
||
| 285 | * |
||
| 286 | * @return \TechDivision\Import\Configuration\SubjectInterface The system configuration |
||
| 287 | */ |
||
| 288 | public function getConfiguration() |
||
| 292 | |||
| 293 | /** |
||
| 294 | * Set's the system logger. |
||
| 295 | * |
||
| 296 | * @param \Psr\Log\LoggerInterface $systemLogger The system logger |
||
| 297 | * |
||
| 298 | * @return void |
||
| 299 | */ |
||
| 300 | public function setSystemLogger(LoggerInterface $systemLogger) |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Return's the system logger. |
||
| 307 | * |
||
| 308 | * @return \Psr\Log\LoggerInterface The system logger instance |
||
| 309 | */ |
||
| 310 | public function getSystemLogger() |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Set's root directory for the virtual filesystem. |
||
| 317 | * |
||
| 318 | * @param string $rootDir The root directory for the virtual filesystem |
||
| 319 | * |
||
| 320 | * @return void |
||
| 321 | */ |
||
| 322 | public function setRootDir($rootDir) |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Return's the root directory for the virtual filesystem. |
||
| 329 | * |
||
| 330 | * @return string The root directory for the virtual filesystem |
||
| 331 | */ |
||
| 332 | public function getRootDir() |
||
| 336 | |||
| 337 | /** |
||
| 338 | * Set's the virtual filesystem instance. |
||
| 339 | * |
||
| 340 | * @param \League\Flysystem\FilesystemInterface $filesystem The filesystem instance |
||
| 341 | * |
||
| 342 | * @return void |
||
| 343 | */ |
||
| 344 | public function setFilesystem(FilesystemInterface $filesystem) |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Return's the virtual filesystem instance. |
||
| 351 | * |
||
| 352 | * @return \League\Flysystem\FilesystemInterface The filesystem instance |
||
| 353 | */ |
||
| 354 | public function getFilesystem() |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Sets's the RegistryProcessor instance to handle the running threads. |
||
| 361 | * |
||
| 362 | * @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor instance |
||
| 363 | * |
||
| 364 | * @return void |
||
| 365 | */ |
||
| 366 | public function setRegistryProcessor(RegistryProcessorInterface $registryProcessor) |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Return's the RegistryProcessor instance to handle the running threads. |
||
| 373 | * |
||
| 374 | * @return \TechDivision\Import\Services\RegistryProcessorInterface The registry processor instance |
||
| 375 | */ |
||
| 376 | public function getRegistryProcessor() |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Set's the unique serial for this import process. |
||
| 383 | * |
||
| 384 | * @param string $serial The unique serial |
||
| 385 | * |
||
| 386 | * @return void |
||
| 387 | */ |
||
| 388 | public function setSerial($serial) |
||
| 392 | |||
| 393 | /** |
||
| 394 | * Return's the unique serial for this import process. |
||
| 395 | * |
||
| 396 | * @return string The unique serial |
||
| 397 | */ |
||
| 398 | public function getSerial() |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Set's the name of the file to import |
||
| 405 | * |
||
| 406 | * @param string $filename The filename |
||
| 407 | * |
||
| 408 | * @return void |
||
| 409 | */ |
||
| 410 | public function setFilename($filename) |
||
| 414 | |||
| 415 | /** |
||
| 416 | * Return's the name of the file to import. |
||
| 417 | * |
||
| 418 | * @return string The filename |
||
| 419 | */ |
||
| 420 | public function getFilename() |
||
| 424 | |||
| 425 | /** |
||
| 426 | * Return's the source date format to use. |
||
| 427 | * |
||
| 428 | * @return string The source date format |
||
| 429 | */ |
||
| 430 | public function getSourceDateFormat() |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Return's the multiple field delimiter character to use, default value is comma (,). |
||
| 437 | * |
||
| 438 | * @return string The multiple field delimiter character |
||
| 439 | */ |
||
| 440 | public function getMultipleFieldDelimiter() |
||
| 444 | |||
| 445 | /** |
||
| 446 | * Return's the initialized PDO connection. |
||
| 447 | * |
||
| 448 | * @return \PDO The initialized PDO connection |
||
| 449 | */ |
||
| 450 | public function getConnection() |
||
| 454 | |||
| 455 | /** |
||
| 456 | * Intializes the previously loaded global data for exactly one bunch. |
||
| 457 | * |
||
| 458 | * @return void |
||
| 459 | * @see \Importer\Csv\Actions\ProductImportAction::prepare() |
||
| 460 | */ |
||
| 461 | public function setUp() |
||
| 475 | |||
| 476 | /** |
||
| 477 | * This method tries to resolve the passed path and returns it. If the path |
||
| 478 | * is relative, the actual working directory will be prepended. |
||
| 479 | * |
||
| 480 | * @param string $path The path to be resolved |
||
| 481 | * |
||
| 482 | * @return string The resolved path |
||
| 483 | * @throws \InvalidArgumentException Is thrown, if the path can not be resolved |
||
| 484 | */ |
||
| 485 | public function resolvePath($path) |
||
| 502 | |||
| 503 | /** |
||
| 504 | * Clean up the global data after importing the variants. |
||
| 505 | * |
||
| 506 | * @return void |
||
| 507 | */ |
||
| 508 | public function tearDown() |
||
| 525 | |||
| 526 | /** |
||
| 527 | * Return's the next source directory, which will be the target directory |
||
| 528 | * of this subject, in most cases. |
||
| 529 | * |
||
| 530 | * @return string The new source directory |
||
| 531 | */ |
||
| 532 | protected function getNewSourceDir() |
||
| 536 | |||
| 537 | /** |
||
| 538 | * Register the passed observer with the specific type. |
||
| 539 | * |
||
| 540 | * @param \TechDivision\Import\Observers\ObserverInterface $observer The observer to register |
||
| 541 | * @param string $type The type to register the observer with |
||
| 542 | * |
||
| 543 | * @return void |
||
| 544 | */ |
||
| 545 | public function registerObserver(ObserverInterface $observer, $type) |
||
| 557 | |||
| 558 | /** |
||
| 559 | * Register the passed callback with the specific type. |
||
| 560 | * |
||
| 561 | * @param \TechDivision\Import\Callbacks\CallbackInterface $callback The subject to register the callbacks for |
||
| 562 | * @param string $type The type to register the callback with |
||
| 563 | * |
||
| 564 | * @return void |
||
| 565 | */ |
||
| 566 | public function registerCallback(CallbackInterface $callback, $type) |
||
| 578 | |||
| 579 | /** |
||
| 580 | * Return's the array with callbacks for the passed type. |
||
| 581 | * |
||
| 582 | * @param string $type The type of the callbacks to return |
||
| 583 | * |
||
| 584 | * @return array The callbacks |
||
| 585 | */ |
||
| 586 | public function getCallbacksByType($type) |
||
| 600 | |||
| 601 | /** |
||
| 602 | * Return's the array with the available observers. |
||
| 603 | * |
||
| 604 | * @return array The observers |
||
| 605 | */ |
||
| 606 | public function getObservers() |
||
| 610 | |||
| 611 | /** |
||
| 612 | * Return's the array with the available callbacks. |
||
| 613 | * |
||
| 614 | * @return array The callbacks |
||
| 615 | */ |
||
| 616 | public function getCallbacks() |
||
| 620 | |||
| 621 | /** |
||
| 622 | * Imports the content of the file with the passed filename. |
||
| 623 | * |
||
| 624 | * @param string $serial The unique process serial |
||
| 625 | * @param string $filename The filename to process |
||
| 626 | * |
||
| 627 | * @return void |
||
| 628 | * @throws \Exception Is thrown, if the import can't be processed |
||
| 629 | */ |
||
| 630 | public function import($serial, $filename) |
||
| 715 | |||
| 716 | /** |
||
| 717 | * This method queries whether or not the passed filename matches |
||
| 718 | * the pattern, based on the subjects configured prefix. |
||
| 719 | * |
||
| 720 | * @param string $filename The filename to match |
||
| 721 | * |
||
| 722 | * @return boolean TRUE if the filename matches, else FALSE |
||
| 723 | */ |
||
| 724 | protected function match($filename) |
||
| 733 | |||
| 734 | /** |
||
| 735 | * Initialize and return the lexer configuration. |
||
| 736 | * |
||
| 737 | * @return \Goodby\CSV\Import\Standard\LexerConfig The lexer configuration |
||
| 738 | */ |
||
| 739 | protected function getLexerConfig() |
||
| 773 | |||
| 774 | /** |
||
| 775 | * Imports the passed row into the database. |
||
| 776 | * |
||
| 777 | * If the import failed, the exception will be catched and logged, |
||
| 778 | * but the import process will be continued. |
||
| 779 | * |
||
| 780 | * @param array $row The row with the data to be imported |
||
| 781 | * |
||
| 782 | * @return void |
||
| 783 | */ |
||
| 784 | public function importRow(array $row) |
||
| 824 | |||
| 825 | /** |
||
| 826 | * Map the passed attribute code, if a header mapping exists and return the |
||
| 827 | * mapped mapping. |
||
| 828 | * |
||
| 829 | * @param string $attributeCode The attribute code to map |
||
| 830 | * |
||
| 831 | * @return string The mapped attribute code, or the original one |
||
| 832 | */ |
||
| 833 | public function mapAttributeCodeByHeaderMapping($attributeCode) |
||
| 844 | } |
||
| 845 |
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.