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 |
||
| 46 | abstract class AbstractSubject implements SubjectInterface |
||
| 47 | { |
||
| 48 | |||
| 49 | /** |
||
| 50 | * The root directory for the virtual filesystem. |
||
| 51 | * |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | protected $rootDir; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * The system configuration. |
||
| 58 | * |
||
| 59 | * @var \TechDivision\Import\Configuration\SubjectInterface |
||
| 60 | */ |
||
| 61 | protected $configuration; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * The system logger implementation. |
||
| 65 | * |
||
| 66 | * @var \Psr\Log\LoggerInterface |
||
| 67 | */ |
||
| 68 | protected $systemLogger; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * The RegistryProcessor instance to handle running threads. |
||
| 72 | * |
||
| 73 | * @var \TechDivision\Import\Services\RegistryProcessorInterface |
||
| 74 | */ |
||
| 75 | protected $registryProcessor; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * The actions unique serial. |
||
| 79 | * |
||
| 80 | * @var string |
||
| 81 | */ |
||
| 82 | protected $serial; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * The name of the file to be imported. |
||
| 86 | * |
||
| 87 | * @var string |
||
| 88 | */ |
||
| 89 | protected $filename; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Array with the subject's observers. |
||
| 93 | * |
||
| 94 | * @var array |
||
| 95 | */ |
||
| 96 | protected $observers = array(); |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Array with the subject's callbacks. |
||
| 100 | * |
||
| 101 | * @var array |
||
| 102 | */ |
||
| 103 | protected $callbacks = array(); |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Contain's the column names from the header line. |
||
| 107 | * |
||
| 108 | * @var array |
||
| 109 | */ |
||
| 110 | protected $headers = array(); |
||
| 111 | |||
| 112 | /** |
||
| 113 | * The virtual filesystem instance. |
||
| 114 | * |
||
| 115 | * @var \League\Flysystem\FilesystemInterface |
||
| 116 | */ |
||
| 117 | protected $filesystem; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Set's the array containing header row. |
||
| 121 | * |
||
| 122 | * @param array $headers The array with the header row |
||
| 123 | * |
||
| 124 | * @return void |
||
| 125 | */ |
||
| 126 | public function setHeaders(array $headers) |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Return's the array containing header row. |
||
| 133 | * |
||
| 134 | * @return array The array with the header row |
||
| 135 | */ |
||
| 136 | public function getHeaders() |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Queries whether or not the header with the passed name is available. |
||
| 143 | * |
||
| 144 | * @param string $name The header name to query |
||
| 145 | * |
||
| 146 | * @return boolean TRUE if the header is available, else FALSE |
||
| 147 | */ |
||
| 148 | public function hasHeader($name) |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Return's the header value for the passed name. |
||
| 155 | * |
||
| 156 | * @param string $name The name of the header to return the value for |
||
| 157 | * |
||
| 158 | * @return mixed The header value |
||
| 159 | * \InvalidArgumentException Is thrown, if the header with the passed name is NOT available |
||
| 160 | */ |
||
| 161 | public function getHeader($name) |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Add's the header with the passed name and position, if not NULL. |
||
| 175 | * |
||
| 176 | * @param string $name The header name to add |
||
| 177 | * |
||
| 178 | * @return integer The new headers position |
||
| 179 | */ |
||
| 180 | public function addHeader($name) |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Set's the system configuration. |
||
| 192 | * |
||
| 193 | * @param \TechDivision\Import\Configuration\Subject $configuration The system configuration |
||
| 194 | * |
||
| 195 | * @return void |
||
| 196 | */ |
||
| 197 | public function setConfiguration(SubjectConfigurationInterface $configuration) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Return's the system configuration. |
||
| 204 | * |
||
| 205 | * @return \TechDivision\Import\Configuration\SubjectInterface The system configuration |
||
| 206 | */ |
||
| 207 | public function getConfiguration() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Set's the system logger. |
||
| 214 | * |
||
| 215 | * @param \Psr\Log\LoggerInterface $systemLogger The system logger |
||
| 216 | * |
||
| 217 | * @return void |
||
| 218 | */ |
||
| 219 | public function setSystemLogger(LoggerInterface $systemLogger) |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Return's the system logger. |
||
| 226 | * |
||
| 227 | * @return \Psr\Log\LoggerInterface The system logger instance |
||
| 228 | */ |
||
| 229 | public function getSystemLogger() |
||
| 233 | |||
| 234 | /** |
||
| 235 | * Set's root directory for the virtual filesystem. |
||
| 236 | * |
||
| 237 | * @param string $rootDir The root directory for the virtual filesystem |
||
| 238 | * |
||
| 239 | * @return void |
||
| 240 | */ |
||
| 241 | public function setRootDir($rootDir) |
||
| 245 | |||
| 246 | /** |
||
| 247 | * Return's the root directory for the virtual filesystem. |
||
| 248 | * |
||
| 249 | * @return string The root directory for the virtual filesystem |
||
| 250 | */ |
||
| 251 | public function getRootDir() |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Set's the virtual filesystem instance. |
||
| 258 | * |
||
| 259 | * @param \League\Flysystem\FilesystemInterface $filesystem The filesystem instance |
||
| 260 | * |
||
| 261 | * @return void |
||
| 262 | */ |
||
| 263 | public function setFilesystem(FilesystemInterface $filesystem) |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Return's the virtual filesystem instance. |
||
| 270 | * |
||
| 271 | * @return \League\Flysystem\FilesystemInterface The filesystem instance |
||
| 272 | */ |
||
| 273 | public function getFilesystem() |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Sets's the RegistryProcessor instance to handle the running threads. |
||
| 280 | * |
||
| 281 | * @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor instance |
||
| 282 | * |
||
| 283 | * @return void |
||
| 284 | */ |
||
| 285 | public function setRegistryProcessor(RegistryProcessorInterface $registryProcessor) |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Return's the RegistryProcessor instance to handle the running threads. |
||
| 292 | * |
||
| 293 | * @return \TechDivision\Import\Services\RegistryProcessorInterface The registry processor instance |
||
| 294 | */ |
||
| 295 | public function getRegistryProcessor() |
||
| 299 | |||
| 300 | /** |
||
| 301 | * Set's the unique serial for this import process. |
||
| 302 | * |
||
| 303 | * @param string $serial The unique serial |
||
| 304 | * |
||
| 305 | * @return void |
||
| 306 | */ |
||
| 307 | public function setSerial($serial) |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Return's the unique serial for this import process. |
||
| 314 | * |
||
| 315 | * @return string The unique serial |
||
| 316 | */ |
||
| 317 | public function getSerial() |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Set's the name of the file to import |
||
| 324 | * |
||
| 325 | * @param string $filename The filename |
||
| 326 | * |
||
| 327 | * @return void |
||
| 328 | */ |
||
| 329 | public function setFilename($filename) |
||
| 333 | |||
| 334 | /** |
||
| 335 | * Return's the name of the file to import. |
||
| 336 | * |
||
| 337 | * @return string The filename |
||
| 338 | */ |
||
| 339 | public function getFilename() |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Return's the source date format to use. |
||
| 346 | * |
||
| 347 | * @return string The source date format |
||
| 348 | */ |
||
| 349 | public function getSourceDateFormat() |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Return's the initialized PDO connection. |
||
| 356 | * |
||
| 357 | * @return \PDO The initialized PDO connection |
||
| 358 | */ |
||
| 359 | public function getConnection() |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Intializes the previously loaded global data for exactly one bunch. |
||
| 366 | * |
||
| 367 | * @return void |
||
| 368 | * @see \Importer\Csv\Actions\ProductImportAction::prepare() |
||
| 369 | */ |
||
| 370 | public function setUp() |
||
| 381 | |||
| 382 | /** |
||
| 383 | * This method tries to resolve the passed path and returns it. If the path |
||
| 384 | * is relative, the actual working directory will be prepended. |
||
| 385 | * |
||
| 386 | * @param string $path The path to be resolved |
||
| 387 | * |
||
| 388 | * @return string The resolved path |
||
| 389 | * @throws \InvalidArgumentException Is thrown, if the path can not be resolved |
||
| 390 | */ |
||
| 391 | public function resolvePath($path) |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Clean up the global data after importing the variants. |
||
| 411 | * |
||
| 412 | * @return void |
||
| 413 | */ |
||
| 414 | public function tearDown() |
||
| 417 | |||
| 418 | /** |
||
| 419 | * Register the passed observer with the specific type. |
||
| 420 | * |
||
| 421 | * @param \TechDivision\Import\Observers\ObserverInterface $observer The observer to register |
||
| 422 | * @param string $type The type to register the observer with |
||
| 423 | * |
||
| 424 | * @return void |
||
| 425 | */ |
||
| 426 | public function registerObserver(ObserverInterface $observer, $type) |
||
| 438 | |||
| 439 | /** |
||
| 440 | * Register the passed callback with the specific type. |
||
| 441 | * |
||
| 442 | * @param \TechDivision\Import\Callbacks\CallbackInterface $callback The subject to register the callbacks for |
||
| 443 | * @param string $type The type to register the callback with |
||
| 444 | * |
||
| 445 | * @return void |
||
| 446 | */ |
||
| 447 | public function registerCallback(CallbackInterface $callback, $type) |
||
| 459 | |||
| 460 | /** |
||
| 461 | * Return's the array with callbacks for the passed type. |
||
| 462 | * |
||
| 463 | * @param string $type The type of the callbacks to return |
||
| 464 | * |
||
| 465 | * @return array The callbacks |
||
| 466 | */ |
||
| 467 | public function getCallbacksByType($type) |
||
| 481 | |||
| 482 | /** |
||
| 483 | * Return's the array with the available observers. |
||
| 484 | * |
||
| 485 | * @return array The observers |
||
| 486 | */ |
||
| 487 | public function getObservers() |
||
| 491 | |||
| 492 | /** |
||
| 493 | * Return's the array with the available callbacks. |
||
| 494 | * |
||
| 495 | * @return array The callbacks |
||
| 496 | */ |
||
| 497 | public function getCallbacks() |
||
| 501 | |||
| 502 | /** |
||
| 503 | * Imports the content of the file with the passed filename. |
||
| 504 | * |
||
| 505 | * @param string $serial The unique process serial |
||
| 506 | * @param string $filename The filename to process |
||
| 507 | * |
||
| 508 | * @return void |
||
| 509 | */ |
||
| 510 | public function import($serial, $filename) |
||
| 562 | |||
| 563 | /** |
||
| 564 | * Initialize and return the lexer configuration. |
||
| 565 | * |
||
| 566 | * @return \Goodby\CSV\Import\Standard\LexerConfig The lexer configuration |
||
| 567 | */ |
||
| 568 | protected function getLexerConfig() |
||
| 602 | |||
| 603 | /** |
||
| 604 | * Imports the passed row into the database. |
||
| 605 | * |
||
| 606 | * If the import failed, the exception will be catched and logged, |
||
| 607 | * but the import process will be continued. |
||
| 608 | * |
||
| 609 | * @param array $row The row with the data to be imported |
||
| 610 | * |
||
| 611 | * @return void |
||
| 612 | */ |
||
| 613 | public function importRow(array $row) |
||
| 632 | } |
||
| 633 |
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.