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 | * Set's the array containing header row. |
||
| 122 | * |
||
| 123 | * @param array $headers The array with the header row |
||
| 124 | * |
||
| 125 | * @return void |
||
| 126 | */ |
||
| 127 | public function setHeaders(array $headers) |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Return's the array containing header row. |
||
| 134 | * |
||
| 135 | * @return array The array with the header row |
||
| 136 | */ |
||
| 137 | public function getHeaders() |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Queries whether or not the header with the passed name is available. |
||
| 144 | * |
||
| 145 | * @param string $name The header name to query |
||
| 146 | * |
||
| 147 | * @return boolean TRUE if the header is available, else FALSE |
||
| 148 | */ |
||
| 149 | public function hasHeader($name) |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Return's the header value for the passed name. |
||
| 156 | * |
||
| 157 | * @param string $name The name of the header to return the value for |
||
| 158 | * |
||
| 159 | * @return mixed The header value |
||
| 160 | * \InvalidArgumentException Is thrown, if the header with the passed name is NOT available |
||
| 161 | */ |
||
| 162 | public function getHeader($name) |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Add's the header with the passed name and position, if not NULL. |
||
| 176 | * |
||
| 177 | * @param string $name The header name to add |
||
| 178 | * |
||
| 179 | * @return integer The new headers position |
||
| 180 | */ |
||
| 181 | public function addHeader($name) |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Set's the system configuration. |
||
| 193 | * |
||
| 194 | * @param \TechDivision\Import\Configuration\Subject $configuration The system configuration |
||
| 195 | * |
||
| 196 | * @return void |
||
| 197 | */ |
||
| 198 | public function setConfiguration(SubjectConfigurationInterface $configuration) |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Return's the system configuration. |
||
| 205 | * |
||
| 206 | * @return \TechDivision\Import\Configuration\SubjectInterface The system configuration |
||
| 207 | */ |
||
| 208 | public function getConfiguration() |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Set's the system logger. |
||
| 215 | * |
||
| 216 | * @param \Psr\Log\LoggerInterface $systemLogger The system logger |
||
| 217 | * |
||
| 218 | * @return void |
||
| 219 | */ |
||
| 220 | public function setSystemLogger(LoggerInterface $systemLogger) |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Return's the system logger. |
||
| 227 | * |
||
| 228 | * @return \Psr\Log\LoggerInterface The system logger instance |
||
| 229 | */ |
||
| 230 | public function getSystemLogger() |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Set's root directory for the virtual filesystem. |
||
| 237 | * |
||
| 238 | * @param string $rootDir The root directory for the virtual filesystem |
||
| 239 | * |
||
| 240 | * @return void |
||
| 241 | */ |
||
| 242 | public function setRootDir($rootDir) |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Return's the root directory for the virtual filesystem. |
||
| 249 | * |
||
| 250 | * @return string The root directory for the virtual filesystem |
||
| 251 | */ |
||
| 252 | public function getRootDir() |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Set's the virtual filesystem instance. |
||
| 259 | * |
||
| 260 | * @param \League\Flysystem\FilesystemInterface $filesystem The filesystem instance |
||
| 261 | * |
||
| 262 | * @return void |
||
| 263 | */ |
||
| 264 | public function setFilesystem(FilesystemInterface $filesystem) |
||
| 268 | |||
| 269 | /** |
||
| 270 | * Return's the virtual filesystem instance. |
||
| 271 | * |
||
| 272 | * @return \League\Flysystem\FilesystemInterface The filesystem instance |
||
| 273 | */ |
||
| 274 | public function getFilesystem() |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Sets's the RegistryProcessor instance to handle the running threads. |
||
| 281 | * |
||
| 282 | * @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor instance |
||
| 283 | * |
||
| 284 | * @return void |
||
| 285 | */ |
||
| 286 | public function setRegistryProcessor(RegistryProcessorInterface $registryProcessor) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Return's the RegistryProcessor instance to handle the running threads. |
||
| 293 | * |
||
| 294 | * @return \TechDivision\Import\Services\RegistryProcessorInterface The registry processor instance |
||
| 295 | */ |
||
| 296 | public function getRegistryProcessor() |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Set's the unique serial for this import process. |
||
| 303 | * |
||
| 304 | * @param string $serial The unique serial |
||
| 305 | * |
||
| 306 | * @return void |
||
| 307 | */ |
||
| 308 | public function setSerial($serial) |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Return's the unique serial for this import process. |
||
| 315 | * |
||
| 316 | * @return string The unique serial |
||
| 317 | */ |
||
| 318 | public function getSerial() |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Set's the name of the file to import |
||
| 325 | * |
||
| 326 | * @param string $filename The filename |
||
| 327 | * |
||
| 328 | * @return void |
||
| 329 | */ |
||
| 330 | public function setFilename($filename) |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Return's the name of the file to import. |
||
| 337 | * |
||
| 338 | * @return string The filename |
||
| 339 | */ |
||
| 340 | public function getFilename() |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Return's the source date format to use. |
||
| 347 | * |
||
| 348 | * @return string The source date format |
||
| 349 | */ |
||
| 350 | public function getSourceDateFormat() |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Return's the multiple field delimiter character to use, default value is comma (,). |
||
| 357 | * |
||
| 358 | * @return string The multiple field delimiter character |
||
| 359 | */ |
||
| 360 | public function getMultipleFieldDelimiter() |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Return's the initialized PDO connection. |
||
| 367 | * |
||
| 368 | * @return \PDO The initialized PDO connection |
||
| 369 | */ |
||
| 370 | public function getConnection() |
||
| 374 | |||
| 375 | /** |
||
| 376 | * Intializes the previously loaded global data for exactly one bunch. |
||
| 377 | * |
||
| 378 | * @return void |
||
| 379 | * @see \Importer\Csv\Actions\ProductImportAction::prepare() |
||
| 380 | */ |
||
| 381 | public function setUp() |
||
| 392 | |||
| 393 | /** |
||
| 394 | * This method tries to resolve the passed path and returns it. If the path |
||
| 395 | * is relative, the actual working directory will be prepended. |
||
| 396 | * |
||
| 397 | * @param string $path The path to be resolved |
||
| 398 | * |
||
| 399 | * @return string The resolved path |
||
| 400 | * @throws \InvalidArgumentException Is thrown, if the path can not be resolved |
||
| 401 | */ |
||
| 402 | public function resolvePath($path) |
||
| 419 | |||
| 420 | /** |
||
| 421 | * Clean up the global data after importing the variants. |
||
| 422 | * |
||
| 423 | * @return void |
||
| 424 | */ |
||
| 425 | public function tearDown() |
||
| 442 | |||
| 443 | /** |
||
| 444 | * Return's the next source directory, which will be the target directory |
||
| 445 | * of this subject, in most cases. |
||
| 446 | * |
||
| 447 | * @return string The new source directory |
||
| 448 | */ |
||
| 449 | protected function getNewSourceDir() |
||
| 453 | |||
| 454 | /** |
||
| 455 | * Register the passed observer with the specific type. |
||
| 456 | * |
||
| 457 | * @param \TechDivision\Import\Observers\ObserverInterface $observer The observer to register |
||
| 458 | * @param string $type The type to register the observer with |
||
| 459 | * |
||
| 460 | * @return void |
||
| 461 | */ |
||
| 462 | public function registerObserver(ObserverInterface $observer, $type) |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Register the passed callback with the specific type. |
||
| 477 | * |
||
| 478 | * @param \TechDivision\Import\Callbacks\CallbackInterface $callback The subject to register the callbacks for |
||
| 479 | * @param string $type The type to register the callback with |
||
| 480 | * |
||
| 481 | * @return void |
||
| 482 | */ |
||
| 483 | public function registerCallback(CallbackInterface $callback, $type) |
||
| 495 | |||
| 496 | /** |
||
| 497 | * Return's the array with callbacks for the passed type. |
||
| 498 | * |
||
| 499 | * @param string $type The type of the callbacks to return |
||
| 500 | * |
||
| 501 | * @return array The callbacks |
||
| 502 | */ |
||
| 503 | public function getCallbacksByType($type) |
||
| 517 | |||
| 518 | /** |
||
| 519 | * Return's the array with the available observers. |
||
| 520 | * |
||
| 521 | * @return array The observers |
||
| 522 | */ |
||
| 523 | public function getObservers() |
||
| 527 | |||
| 528 | /** |
||
| 529 | * Return's the array with the available callbacks. |
||
| 530 | * |
||
| 531 | * @return array The callbacks |
||
| 532 | */ |
||
| 533 | public function getCallbacks() |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Imports the content of the file with the passed filename. |
||
| 540 | * |
||
| 541 | * @param string $serial The unique process serial |
||
| 542 | * @param string $filename The filename to process |
||
| 543 | * |
||
| 544 | * @return void |
||
| 545 | * @throws \Exception Is thrown, if the import can't be processed |
||
| 546 | */ |
||
| 547 | public function import($serial, $filename) |
||
| 633 | |||
| 634 | /** |
||
| 635 | * This method queries whether or not the passed filename matches |
||
| 636 | * the pattern, based on the subjects configured prefix. |
||
| 637 | * |
||
| 638 | * @param string $filename The filename to match |
||
| 639 | * |
||
| 640 | * @return boolean TRUE if the filename matches, else FALSE |
||
| 641 | */ |
||
| 642 | protected function match($filename) |
||
| 651 | |||
| 652 | /** |
||
| 653 | * Initialize and return the lexer configuration. |
||
| 654 | * |
||
| 655 | * @return \Goodby\CSV\Import\Standard\LexerConfig The lexer configuration |
||
| 656 | */ |
||
| 657 | protected function getLexerConfig() |
||
| 691 | |||
| 692 | /** |
||
| 693 | * Imports the passed row into the database. |
||
| 694 | * |
||
| 695 | * If the import failed, the exception will be catched and logged, |
||
| 696 | * but the import process will be continued. |
||
| 697 | * |
||
| 698 | * @param array $row The row with the data to be imported |
||
| 699 | * |
||
| 700 | * @return void |
||
| 701 | */ |
||
| 702 | public function importRow(array $row) |
||
| 721 | } |
||
| 722 |
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.