Complex classes like Subject 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 Subject, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 46 | class Subject implements SubjectConfigurationInterface, ListenerAwareConfigurationInterface |
||
| 47 | { |
||
| 48 | |||
| 49 | /** |
||
| 50 | * The trait that provides parameter handling functionality. |
||
| 51 | * |
||
| 52 | * @var \TechDivision\Import\Configuration\Jms\Configuration\ParamsTrait |
||
| 53 | */ |
||
| 54 | use ParamsTrait; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Trait that provides CSV configuration functionality. |
||
| 58 | * |
||
| 59 | * @var \TechDivision\Import\Configuration\Jms\Configuration\ListenersTrait |
||
| 60 | */ |
||
| 61 | use ListenersTrait; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * The subject's unique DI identifier. |
||
| 65 | * |
||
| 66 | * @var string |
||
| 67 | * @Type("string") |
||
| 68 | * @SerializedName("id") |
||
| 69 | */ |
||
| 70 | protected $id; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * The subject's name. |
||
| 74 | * |
||
| 75 | * @var string |
||
| 76 | * @Type("string") |
||
| 77 | * @SerializedName("name") |
||
| 78 | */ |
||
| 79 | protected $name; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * The array with the subject's observers. |
||
| 83 | * |
||
| 84 | * @var array |
||
| 85 | * @Type("array") |
||
| 86 | */ |
||
| 87 | protected $observers = array(); |
||
| 88 | |||
| 89 | /** |
||
| 90 | * The array with the subject's callbacks. |
||
| 91 | * |
||
| 92 | * @var array |
||
| 93 | * @Type("array<string, array>") |
||
| 94 | */ |
||
| 95 | protected $callbacks = array(); |
||
| 96 | |||
| 97 | /** |
||
| 98 | * The array with the subject's frontend input callbacks. |
||
| 99 | * |
||
| 100 | * @var array |
||
| 101 | * @Type("array<string, array>") |
||
| 102 | * @SerializedName("frontend-input-callbacks") |
||
| 103 | */ |
||
| 104 | protected $frontendInputCallbacks = array(); |
||
| 105 | |||
| 106 | /** |
||
| 107 | * The flag to signal that the subjects needs a OK file to be processed or not. |
||
| 108 | * |
||
| 109 | * @var boolean |
||
| 110 | * @Type("boolean") |
||
| 111 | * @SerializedName("ok-file-needed") |
||
| 112 | */ |
||
| 113 | protected $okFileNeeded = false; |
||
| 114 | |||
| 115 | /** |
||
| 116 | *The flag to signal that the subject has to create a .imported flagfile or not. |
||
| 117 | * |
||
| 118 | * @var boolean |
||
| 119 | * @Type("boolean") |
||
| 120 | * @SerializedName("create-imported-file") |
||
| 121 | */ |
||
| 122 | protected $createImportedFile = true; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * The import adapter configuration instance. |
||
| 126 | * |
||
| 127 | * @var \TechDivision\Import\Configuration\Subject\ImportAdapterConfigurationInterface |
||
| 128 | * @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\ImportAdapter") |
||
| 129 | * @SerializedName("import-adapter") |
||
| 130 | */ |
||
| 131 | protected $importAdapter; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * The export adapter configuration instance. |
||
| 135 | * |
||
| 136 | * @var \TechDivision\Import\Configuration\Subject\ExportAdapterConfigurationInterface |
||
| 137 | * @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\ExportAdapter") |
||
| 138 | * @SerializedName("export-adapter") |
||
| 139 | */ |
||
| 140 | protected $exportAdapter; |
||
| 141 | |||
| 142 | /** |
||
| 143 | * The filesystem adapter configuration instance. |
||
| 144 | * |
||
| 145 | * @var \TechDivision\Import\Configuration\Subject\FilesystemAdapterConfigurationInterface |
||
| 146 | * @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\FilesystemAdapter") |
||
| 147 | * @SerializedName("filesystem-adapter") |
||
| 148 | */ |
||
| 149 | protected $filesystemAdapter; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * The file resolver configuration instance. |
||
| 153 | * |
||
| 154 | * @var \TechDivision\Import\Configuration\Subject\FileResolverConfigurationInterface |
||
| 155 | * @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\FileResolver") |
||
| 156 | * @SerializedName("file-resolver") |
||
| 157 | */ |
||
| 158 | protected $fileResolver; |
||
| 159 | |||
| 160 | /** |
||
| 161 | * The number converter configuration instance. |
||
| 162 | * |
||
| 163 | * @var \TechDivision\Import\Configuration\Subject\NumberConverterConfigurationInterface |
||
| 164 | * @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\NumberConverter") |
||
| 165 | * @SerializedName("number-converter") |
||
| 166 | */ |
||
| 167 | protected $numberConverter; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * The date converter configuration instance. |
||
| 171 | * |
||
| 172 | * @var \TechDivision\Import\Configuration\Subject\DateConverterConfigurationInterface |
||
| 173 | * @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\DateConverter") |
||
| 174 | * @SerializedName("date-converter") |
||
| 175 | */ |
||
| 176 | protected $dateConverter; |
||
| 177 | |||
| 178 | /** |
||
| 179 | * The source directory that has to be watched for new files. |
||
| 180 | * |
||
| 181 | * @var string |
||
| 182 | * @Type("string") |
||
| 183 | * @SerializedName("source-dir") |
||
| 184 | */ |
||
| 185 | protected $sourceDir; |
||
| 186 | |||
| 187 | /** |
||
| 188 | * The target directory with the files that has been imported. |
||
| 189 | * |
||
| 190 | * @var string |
||
| 191 | * @Type("string") |
||
| 192 | * @SerializedName("target-dir") |
||
| 193 | */ |
||
| 194 | protected $targetDir; |
||
| 195 | |||
| 196 | /** |
||
| 197 | * A reference to the parent configuration instance. |
||
| 198 | * |
||
| 199 | * @var \TechDivision\Import\ConfigurationInterface |
||
| 200 | */ |
||
| 201 | protected $configuration; |
||
| 202 | |||
| 203 | /** |
||
| 204 | * The configuration of the parent plugin. |
||
| 205 | * |
||
| 206 | * @var \TechDivision\Import\Configuration\PluginConfigurationInterface |
||
| 207 | */ |
||
| 208 | protected $pluginConfiguration; |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Lifecycle callback that will be invoked after deserialization. |
||
| 212 | * |
||
| 213 | * @return void |
||
| 214 | * @PostDeserialize |
||
| 215 | */ |
||
| 216 | public function postDeserialize() |
||
| 249 | |||
| 250 | /** |
||
| 251 | * Return's the multiple field delimiter character to use, default value is comma (,). |
||
| 252 | * |
||
| 253 | * @return string The multiple field delimiter character |
||
| 254 | */ |
||
| 255 | public function getMultipleFieldDelimiter() |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Return's the multiple value delimiter character to use, default value is comma (|). |
||
| 262 | * |
||
| 263 | * @return string The multiple value delimiter character |
||
| 264 | */ |
||
| 265 | public function getMultipleValueDelimiter() |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Return's the delimiter character to use, default value is comma (,). |
||
| 272 | * |
||
| 273 | * @return string The delimiter character |
||
| 274 | */ |
||
| 275 | public function getDelimiter() |
||
| 279 | |||
| 280 | /** |
||
| 281 | * The enclosure character to use, default value is double quotation ("). |
||
| 282 | * |
||
| 283 | * @return string The enclosure character |
||
| 284 | */ |
||
| 285 | public function getEnclosure() |
||
| 289 | |||
| 290 | /** |
||
| 291 | * The escape character to use, default value is backslash (\). |
||
| 292 | * |
||
| 293 | * @return string The escape character |
||
| 294 | */ |
||
| 295 | public function getEscape() |
||
| 299 | |||
| 300 | /** |
||
| 301 | * The file encoding of the CSV source file, default value is UTF-8. |
||
| 302 | * |
||
| 303 | * @return string The charset used by the CSV source file |
||
| 304 | */ |
||
| 305 | public function getFromCharset() |
||
| 309 | |||
| 310 | /** |
||
| 311 | * The file encoding of the CSV targetfile, default value is UTF-8. |
||
| 312 | * |
||
| 313 | * @return string The charset used by the CSV target file |
||
| 314 | */ |
||
| 315 | public function getToCharset() |
||
| 319 | |||
| 320 | /** |
||
| 321 | * The file mode of the CSV target file, either one of write or append, default is write. |
||
| 322 | * |
||
| 323 | * @return string The file mode of the CSV target file |
||
| 324 | */ |
||
| 325 | public function getFileMode() |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Queries whether or not strict mode is enabled or not, default is TRUE. |
||
| 332 | * |
||
| 333 | * @return boolean TRUE if strict mode is enabled, else FALSE |
||
| 334 | */ |
||
| 335 | public function isStrictMode() |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Return's the subject's source date format to use. |
||
| 342 | * |
||
| 343 | * @return string The source date format |
||
| 344 | */ |
||
| 345 | public function getSourceDateFormat() |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Return's the source directory that has to be watched for new files. |
||
| 352 | * |
||
| 353 | * @return string The source directory |
||
| 354 | */ |
||
| 355 | public function getSourceDir() |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Return's the target directory with the files that has been imported. |
||
| 362 | * |
||
| 363 | * @return string The target directory |
||
| 364 | */ |
||
| 365 | public function getTargetDir() |
||
| 369 | |||
| 370 | /** |
||
| 371 | * Queries whether or not debug mode is enabled or not, default is TRUE. |
||
| 372 | * |
||
| 373 | * @return boolean TRUE if debug mode is enabled, else FALSE |
||
| 374 | */ |
||
| 375 | public function isDebugMode() |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Return's the subject's unique DI identifier. |
||
| 382 | * |
||
| 383 | * @return string The subject's unique DI identifier |
||
| 384 | */ |
||
| 385 | public function getId() |
||
| 389 | |||
| 390 | /** |
||
| 391 | * Return's the subject's name or the ID, if the name is NOT set. |
||
| 392 | * |
||
| 393 | * @return string The subject's name |
||
| 394 | * @see \TechDivision\Import\Configuration\SubjectConfigurationInterface::getId() |
||
| 395 | */ |
||
| 396 | public function getName() |
||
| 400 | |||
| 401 | /** |
||
| 402 | * Set's the reference to the configuration instance. |
||
| 403 | * |
||
| 404 | * @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance |
||
| 405 | * |
||
| 406 | * @return void |
||
| 407 | */ |
||
| 408 | public function setConfiguration(ConfigurationInterface $configuration) |
||
| 412 | |||
| 413 | /** |
||
| 414 | * Return's the reference to the configuration instance. |
||
| 415 | * |
||
| 416 | * @return \TechDivision\Import\ConfigurationInterface The configuration instance |
||
| 417 | */ |
||
| 418 | public function getConfiguration() |
||
| 422 | |||
| 423 | /** |
||
| 424 | * Set's the reference to the parent plugin configuration instance. |
||
| 425 | * |
||
| 426 | * @param \TechDivision\Import\Configuration\PluginConfigurationInterface $pluginConfiguration The parent plugin configuration instance |
||
| 427 | * |
||
| 428 | * @return void |
||
| 429 | */ |
||
| 430 | public function setPluginConfiguration(PluginConfigurationInterface $pluginConfiguration) |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Return's the reference to the parent plugin configuration instance. |
||
| 437 | * |
||
| 438 | * @return \TechDivision\Import\ConfigurationInterface The parent plugin configuration instance |
||
| 439 | */ |
||
| 440 | public function getPluginConfiguration() |
||
| 444 | |||
| 445 | /** |
||
| 446 | * Return's the prefix for the import files. |
||
| 447 | * |
||
| 448 | * @return string The prefix |
||
| 449 | */ |
||
| 450 | public function getPrefix() |
||
| 454 | |||
| 455 | /** |
||
| 456 | * Return's the array with the subject's observers. |
||
| 457 | * |
||
| 458 | * @return array The subject's observers |
||
| 459 | */ |
||
| 460 | public function getObservers() |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Return's the array with the subject's callbacks. |
||
| 467 | * |
||
| 468 | * @return array The subject's callbacks |
||
| 469 | */ |
||
| 470 | public function getCallbacks() |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Return's the array with the subject's frontend input callbacks. |
||
| 477 | * |
||
| 478 | * @return array The subject's frontend input callbacks |
||
| 479 | */ |
||
| 480 | public function getFrontendInputCallbacks() |
||
| 484 | |||
| 485 | /** |
||
| 486 | * Set's the flag to signal that the an OK file is needed for the subject |
||
| 487 | * to be processed. |
||
| 488 | * |
||
| 489 | * @param boolean $okFileNeeded TRUE if the subject needs an OK file, else FALSE |
||
| 490 | * |
||
| 491 | * @return void |
||
| 492 | */ |
||
| 493 | public function setOkFileNeeded($okFileNeeded) |
||
| 497 | |||
| 498 | /** |
||
| 499 | * Queries whether or not that the subject needs an OK file to be processed. |
||
| 500 | * |
||
| 501 | * @return boolean TRUE if the subject needs an OK file, else FALSE |
||
| 502 | */ |
||
| 503 | public function isOkFileNeeded() |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Queries whether or not the subject should create a .imported flagfile |
||
| 510 | * |
||
| 511 | * @return boolean TRUE if subject has to create the .imported flagfile, else FALSE |
||
| 512 | */ |
||
| 513 | public function isCreatingImportedFile() |
||
| 517 | |||
| 518 | /** |
||
| 519 | * Return's the import adapter configuration instance. |
||
| 520 | * |
||
| 521 | * @return \TechDivision\Import\Configuration\Subject\ImportAdapterConfigurationInterface The import adapter configuration instance |
||
| 522 | */ |
||
| 523 | public function getImportAdapter() |
||
| 527 | |||
| 528 | /** |
||
| 529 | * Return's the export adapter configuration instance. |
||
| 530 | * |
||
| 531 | * @return \TechDivision\Import\Configuration\Subject\ExportAdapterConfigurationInterface The export adapter configuration instance |
||
| 532 | */ |
||
| 533 | public function getExportAdapter() |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Return's the filesystem adapter configuration instance. |
||
| 540 | * |
||
| 541 | * @return \TechDivision\Import\Configuration\Subject\FilesystemAdapterConfigurationInterface The filesystem adapter configuration instance |
||
| 542 | */ |
||
| 543 | public function getFilesystemAdapter() |
||
| 547 | |||
| 548 | /** |
||
| 549 | * Return's the file resolver configuration instance. |
||
| 550 | * |
||
| 551 | * @return \TechDivision\Import\Configuration\Subject\FileResolverConfigurationInterface The file resolver configuration instance |
||
| 552 | */ |
||
| 553 | public function getFileResolver() |
||
| 557 | |||
| 558 | /** |
||
| 559 | * Return's the number converter configuration instance. |
||
| 560 | * |
||
| 561 | * @return \TechDivision\Import\Configuration\Subject\NumberConverterConfigurationInterface The number converter configuration instance |
||
| 562 | */ |
||
| 563 | public function getNumberConverter() |
||
| 567 | |||
| 568 | /** |
||
| 569 | * Return's the date converter configuration instance. |
||
| 570 | * |
||
| 571 | * @return \TechDivision\Import\Configuration\Subject\DateConverterConfigurationInterface The date converter configuration instance |
||
| 572 | */ |
||
| 573 | public function getDateConverter() |
||
| 577 | |||
| 578 | /** |
||
| 579 | * The array with the subject's custom header mappings. |
||
| 580 | * |
||
| 581 | * @return array The custom header mappings |
||
| 582 | */ |
||
| 583 | public function getHeaderMappings() |
||
| 587 | |||
| 588 | /** |
||
| 589 | * The array with the subject's custom image types. |
||
| 590 | * |
||
| 591 | * @return array The custom image types |
||
| 592 | */ |
||
| 593 | public function getImageTypes() |
||
| 597 | } |
||
| 598 |