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 | * Array with the subject's observers. |
||
| 86 | * |
||
| 87 | * @var array |
||
| 88 | */ |
||
| 89 | protected $observers = array(); |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Array with the subject's callbacks. |
||
| 93 | * |
||
| 94 | * @var array |
||
| 95 | */ |
||
| 96 | protected $callbacks = array(); |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Contain's the column names from the header line. |
||
| 100 | * |
||
| 101 | * @var array |
||
| 102 | */ |
||
| 103 | protected $headers = array(); |
||
| 104 | |||
| 105 | /** |
||
| 106 | * The virtual filesystem instance. |
||
| 107 | * |
||
| 108 | * @var \League\Flysystem\FilesystemInterface |
||
| 109 | */ |
||
| 110 | protected $filesystem; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Set's the array containing header row. |
||
| 114 | * |
||
| 115 | * @param array $headers The array with the header row |
||
| 116 | * |
||
| 117 | * @return void |
||
| 118 | */ |
||
| 119 | public function setHeaders(array $headers) |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Return's the array containing header row. |
||
| 126 | * |
||
| 127 | * @return array The array with the header row |
||
| 128 | */ |
||
| 129 | public function getHeaders() |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Set's the system configuration. |
||
| 136 | * |
||
| 137 | * @param \TechDivision\Import\Configuration\Subject $configuration The system configuration |
||
| 138 | * |
||
| 139 | * @return void |
||
| 140 | */ |
||
| 141 | public function setConfiguration(SubjectConfigurationInterface $configuration) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Return's the system configuration. |
||
| 148 | * |
||
| 149 | * @return \TechDivision\Import\Configuration\SubjectInterface The system configuration |
||
| 150 | */ |
||
| 151 | public function getConfiguration() |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Set's the system logger. |
||
| 158 | * |
||
| 159 | * @param \Psr\Log\LoggerInterface $systemLogger The system logger |
||
| 160 | * |
||
| 161 | * @return void |
||
| 162 | */ |
||
| 163 | public function setSystemLogger(LoggerInterface $systemLogger) |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Return's the system logger. |
||
| 170 | * |
||
| 171 | * @return \Psr\Log\LoggerInterface The system logger instance |
||
| 172 | */ |
||
| 173 | public function getSystemLogger() |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Set's root directory for the virtual filesystem. |
||
| 180 | * |
||
| 181 | * @param string $rootDir The root directory for the virtual filesystem |
||
| 182 | * |
||
| 183 | * @return void |
||
| 184 | */ |
||
| 185 | public function setRootDir($rootDir) |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Return's the root directory for the virtual filesystem. |
||
| 192 | * |
||
| 193 | * @return string The root directory for the virtual filesystem |
||
| 194 | */ |
||
| 195 | public function getRootDir() |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Set's the virtual filesystem instance. |
||
| 202 | * |
||
| 203 | * @param \League\Flysystem\FilesystemInterface $filesystem The filesystem instance |
||
| 204 | * |
||
| 205 | * @return void |
||
| 206 | */ |
||
| 207 | public function setFilesystem(FilesystemInterface $filesystem) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Return's the virtual filesystem instance. |
||
| 214 | * |
||
| 215 | * @return \League\Flysystem\FilesystemInterface The filesystem instance |
||
| 216 | */ |
||
| 217 | public function getFilesystem() |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Sets's the RegistryProcessor instance to handle the running threads. |
||
| 224 | * |
||
| 225 | * @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor instance |
||
| 226 | * |
||
| 227 | * @return void |
||
| 228 | */ |
||
| 229 | public function setRegistryProcessor(RegistryProcessorInterface $registryProcessor) |
||
| 233 | |||
| 234 | /** |
||
| 235 | * Return's the RegistryProcessor instance to handle the running threads. |
||
| 236 | * |
||
| 237 | * @return \TechDivision\Import\Services\RegistryProcessorInterface The registry processor instance |
||
| 238 | */ |
||
| 239 | public function getRegistryProcessor() |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Set's the unique serial for this import process. |
||
| 246 | * |
||
| 247 | * @param string $serial The unique serial |
||
| 248 | * |
||
| 249 | * @return void |
||
| 250 | */ |
||
| 251 | public function setSerial($serial) |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Return's the unique serial for this import process. |
||
| 258 | * |
||
| 259 | * @return string The unique serial |
||
| 260 | */ |
||
| 261 | public function getSerial() |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Return's the source date format to use. |
||
| 268 | * |
||
| 269 | * @return string The source date format |
||
| 270 | */ |
||
| 271 | public function getSourceDateFormat() |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Return's the initialized PDO connection. |
||
| 278 | * |
||
| 279 | * @return \PDO The initialized PDO connection |
||
| 280 | */ |
||
| 281 | public function getConnection() |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Intializes the previously loaded global data for exactly one bunch. |
||
| 288 | * |
||
| 289 | * @return void |
||
| 290 | * @see \Importer\Csv\Actions\ProductImportAction::prepare() |
||
| 291 | */ |
||
| 292 | public function setUp() |
||
| 303 | |||
| 304 | /** |
||
| 305 | * This method tries to resolve the passed path and returns it. If the path |
||
| 306 | * is relative, the actual working directory will be prepended. |
||
| 307 | * |
||
| 308 | * @param string $path The path to be resolved |
||
| 309 | * |
||
| 310 | * @return string The resolved path |
||
| 311 | * @throws \InvalidArgumentException Is thrown, if the path can not be resolved |
||
| 312 | */ |
||
| 313 | public function resolvePath($path) |
||
| 330 | |||
| 331 | /** |
||
| 332 | * Clean up the global data after importing the variants. |
||
| 333 | * |
||
| 334 | * @return void |
||
| 335 | */ |
||
| 336 | public function tearDown() |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Register the passed observer with the specific type. |
||
| 342 | * |
||
| 343 | * @param \TechDivision\Import\Observers\ObserverInterface $observer The observer to register |
||
| 344 | * @param string $type The type to register the observer with |
||
| 345 | * |
||
| 346 | * @return void |
||
| 347 | */ |
||
| 348 | public function registerObserver(ObserverInterface $observer, $type) |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Register the passed callback with the specific type. |
||
| 363 | * |
||
| 364 | * @param \TechDivision\Import\Callbacks\CallbackInterface $callback The subject to register the callbacks for |
||
| 365 | * @param string $type The type to register the callback with |
||
| 366 | * |
||
| 367 | * @return void |
||
| 368 | */ |
||
| 369 | public function registerCallback(CallbackInterface $callback, $type) |
||
| 381 | |||
| 382 | /** |
||
| 383 | * Return's the array with callbacks for the passed type. |
||
| 384 | * |
||
| 385 | * @param string $type The type of the callbacks to return |
||
| 386 | * |
||
| 387 | * @return array The callbacks |
||
| 388 | */ |
||
| 389 | public function getCallbacksByType($type) |
||
| 403 | |||
| 404 | /** |
||
| 405 | * Return's the array with the available observers. |
||
| 406 | * |
||
| 407 | * @return array The observers |
||
| 408 | */ |
||
| 409 | public function getObservers() |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Return's the array with the available callbacks. |
||
| 416 | * |
||
| 417 | * @return array The callbacks |
||
| 418 | */ |
||
| 419 | public function getCallbacks() |
||
| 423 | |||
| 424 | /** |
||
| 425 | * Imports the content of the file with the passed filename. |
||
| 426 | * |
||
| 427 | * @param string $serial The unique process serial |
||
| 428 | * @param string $filename The filename to process |
||
| 429 | * |
||
| 430 | * @return void |
||
| 431 | */ |
||
| 432 | public function import($serial, $filename) |
||
| 483 | |||
| 484 | /** |
||
| 485 | * Initialize and return the lexer configuration. |
||
| 486 | * |
||
| 487 | * @return \Goodby\CSV\Import\Standard\LexerConfig The lexer configuration |
||
| 488 | */ |
||
| 489 | protected function getLexerConfig() |
||
| 523 | |||
| 524 | /** |
||
| 525 | * Imports the passed row into the database. |
||
| 526 | * |
||
| 527 | * If the import failed, the exception will be catched and logged, |
||
| 528 | * but the import process will be continued. |
||
| 529 | * |
||
| 530 | * @param array $row The row with the data to be imported |
||
| 531 | * |
||
| 532 | * @return void |
||
| 533 | */ |
||
| 534 | public function importRow(array $row) |
||
| 553 | } |
||
| 554 |
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.