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 |
||
| 44 | class Subject implements SubjectConfigurationInterface |
||
| 45 | { |
||
| 46 | |||
| 47 | /** |
||
| 48 | * The trait that provides parameter handling functionality. |
||
| 49 | * |
||
| 50 | * @var \TechDivision\Import\Configuration\Jms\Configuration\ParamsTrait |
||
| 51 | */ |
||
| 52 | use ParamsTrait; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * The subject's unique DI identifier. |
||
| 56 | * |
||
| 57 | * @var string |
||
| 58 | * @Type("string") |
||
| 59 | * @SerializedName("id") |
||
| 60 | */ |
||
| 61 | protected $id; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * The array with the subject's observers. |
||
| 65 | * |
||
| 66 | * @var array |
||
| 67 | * @Type("array") |
||
| 68 | */ |
||
| 69 | protected $observers = array(); |
||
| 70 | |||
| 71 | /** |
||
| 72 | * The array with the subject's callbacks. |
||
| 73 | * |
||
| 74 | * @var array |
||
| 75 | * @Type("array<string, array>") |
||
| 76 | */ |
||
| 77 | protected $callbacks = array(); |
||
| 78 | |||
| 79 | /** |
||
| 80 | * The array with the subject's frontend input callbacks. |
||
| 81 | * |
||
| 82 | * @var array |
||
| 83 | * @Type("array<string, array>") |
||
| 84 | * @SerializedName("frontend-input-callbacks") |
||
| 85 | */ |
||
| 86 | protected $frontendInputCallbacks = array(); |
||
| 87 | |||
| 88 | /** |
||
| 89 | * A reference to the parent configuration instance. |
||
| 90 | * |
||
| 91 | * @var \TechDivision\Import\ConfigurationInterface |
||
| 92 | */ |
||
| 93 | protected $configuration; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * The flag to signal that the subjects needs a OK file to be processed or not. |
||
| 97 | * |
||
| 98 | * @var boolean |
||
| 99 | * @Type("boolean") |
||
| 100 | * @SerializedName("ok-file-needed") |
||
| 101 | */ |
||
| 102 | protected $okFileNeeded = false; |
||
| 103 | |||
| 104 | /** |
||
| 105 | *The flag to signal that the subject has to create a .imported flagfile or not. |
||
| 106 | * |
||
| 107 | * @var boolean |
||
| 108 | * @Type("boolean") |
||
| 109 | * @SerializedName("create-imported-file") |
||
| 110 | */ |
||
| 111 | protected $createImportedFile = true; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * The import adapter configuration instance. |
||
| 115 | * |
||
| 116 | * @var \TechDivision\Import\Configuration\Subject\ImportAdapterConfigurationInterface |
||
| 117 | * @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\ImportAdapter") |
||
| 118 | * @SerializedName("import-adapter") |
||
| 119 | */ |
||
| 120 | protected $importAdapter; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * The export adapter configuration instance. |
||
| 124 | * |
||
| 125 | * @var \TechDivision\Import\Configuration\Subject\ExportAdapterConfigurationInterface |
||
| 126 | * @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\ExportAdapter") |
||
| 127 | * @SerializedName("export-adapter") |
||
| 128 | */ |
||
| 129 | protected $exportAdapter; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * The filesystem adapter configuration instance. |
||
| 133 | * |
||
| 134 | * @var \TechDivision\Import\Configuration\Subject\FilesystemAdapterConfigurationInterface |
||
| 135 | * @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\FilesystemAdapter") |
||
| 136 | * @SerializedName("filesystem-adapter") |
||
| 137 | */ |
||
| 138 | protected $filesystemAdapter; |
||
| 139 | |||
| 140 | /** |
||
| 141 | * The file resolver configuration instance. |
||
| 142 | * |
||
| 143 | * @var \TechDivision\Import\Configuration\Subject\FileResolverConfigurationInterface |
||
| 144 | * @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\FileResolver") |
||
| 145 | * @SerializedName("file-resolver") |
||
| 146 | */ |
||
| 147 | protected $fileResolver; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * The number converter configuration instance. |
||
| 151 | * |
||
| 152 | * @var \TechDivision\Import\Configuration\Subject\NumberConverterConfigurationInterface |
||
| 153 | * @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\NumberConverter") |
||
| 154 | * @SerializedName("number-converter") |
||
| 155 | */ |
||
| 156 | protected $numberConverter; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * The date converter configuration instance. |
||
| 160 | * |
||
| 161 | * @var \TechDivision\Import\Configuration\Subject\DateConverterConfigurationInterface |
||
| 162 | * @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\DateConverter") |
||
| 163 | * @SerializedName("date-converter") |
||
| 164 | */ |
||
| 165 | protected $dateConverter; |
||
| 166 | |||
| 167 | /** |
||
| 168 | * The source directory that has to be watched for new files. |
||
| 169 | * |
||
| 170 | * @var string |
||
| 171 | * @Type("string") |
||
| 172 | * @SerializedName("source-dir") |
||
| 173 | */ |
||
| 174 | protected $sourceDir; |
||
| 175 | |||
| 176 | /** |
||
| 177 | * The target directory with the files that has been imported. |
||
| 178 | * |
||
| 179 | * @var string |
||
| 180 | * @Type("string") |
||
| 181 | * @SerializedName("target-dir") |
||
| 182 | */ |
||
| 183 | protected $targetDir; |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Lifecycle callback that will be invoked after deserialization. |
||
| 187 | * |
||
| 188 | * @return void |
||
| 189 | * @PostDeserialize |
||
| 190 | */ |
||
| 191 | public function postDeserialize() |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Return's the multiple field delimiter character to use, default value is comma (,). |
||
| 227 | * |
||
| 228 | * @return string The multiple field delimiter character |
||
| 229 | */ |
||
| 230 | public function getMultipleFieldDelimiter() |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Return's the multiple value delimiter character to use, default value is comma (|). |
||
| 237 | * |
||
| 238 | * @return string The multiple value delimiter character |
||
| 239 | */ |
||
| 240 | public function getMultipleValueDelimiter() |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Return's the delimiter character to use, default value is comma (,). |
||
| 247 | * |
||
| 248 | * @return string The delimiter character |
||
| 249 | */ |
||
| 250 | public function getDelimiter() |
||
| 254 | |||
| 255 | /** |
||
| 256 | * The enclosure character to use, default value is double quotation ("). |
||
| 257 | * |
||
| 258 | * @return string The enclosure character |
||
| 259 | */ |
||
| 260 | public function getEnclosure() |
||
| 264 | |||
| 265 | /** |
||
| 266 | * The escape character to use, default value is backslash (\). |
||
| 267 | * |
||
| 268 | * @return string The escape character |
||
| 269 | */ |
||
| 270 | public function getEscape() |
||
| 274 | |||
| 275 | /** |
||
| 276 | * The file encoding of the CSV source file, default value is UTF-8. |
||
| 277 | * |
||
| 278 | * @return string The charset used by the CSV source file |
||
| 279 | */ |
||
| 280 | public function getFromCharset() |
||
| 284 | |||
| 285 | /** |
||
| 286 | * The file encoding of the CSV targetfile, default value is UTF-8. |
||
| 287 | * |
||
| 288 | * @return string The charset used by the CSV target file |
||
| 289 | */ |
||
| 290 | public function getToCharset() |
||
| 294 | |||
| 295 | /** |
||
| 296 | * The file mode of the CSV target file, either one of write or append, default is write. |
||
| 297 | * |
||
| 298 | * @return string The file mode of the CSV target file |
||
| 299 | */ |
||
| 300 | public function getFileMode() |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Queries whether or not strict mode is enabled or not, default is TRUE. |
||
| 307 | * |
||
| 308 | * @return boolean TRUE if strict mode is enabled, else FALSE |
||
| 309 | */ |
||
| 310 | public function isStrictMode() |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Return's the subject's source date format to use. |
||
| 317 | * |
||
| 318 | * @return string The source date format |
||
| 319 | */ |
||
| 320 | public function getSourceDateFormat() |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Return's the source directory that has to be watched for new files. |
||
| 327 | * |
||
| 328 | * @return string The source directory |
||
| 329 | */ |
||
| 330 | public function getSourceDir() |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Return's the target directory with the files that has been imported. |
||
| 337 | * |
||
| 338 | * @return string The target directory |
||
| 339 | */ |
||
| 340 | public function getTargetDir() |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Queries whether or not debug mode is enabled or not, default is TRUE. |
||
| 347 | * |
||
| 348 | * @return boolean TRUE if debug mode is enabled, else FALSE |
||
| 349 | */ |
||
| 350 | public function isDebugMode() |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Return's the subject's unique DI identifier. |
||
| 357 | * |
||
| 358 | * @return string The subject's unique DI identifier |
||
| 359 | */ |
||
| 360 | public function getId() |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Set's the reference to the configuration instance. |
||
| 367 | * |
||
| 368 | * @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance |
||
| 369 | * |
||
| 370 | * @return void |
||
| 371 | */ |
||
| 372 | public function setConfiguration(ConfigurationInterface $configuration) |
||
| 376 | |||
| 377 | /** |
||
| 378 | * Return's the reference to the configuration instance. |
||
| 379 | * |
||
| 380 | * @return \TechDivision\Import\ConfigurationInterface The configuration instance |
||
| 381 | */ |
||
| 382 | public function getConfiguration() |
||
| 386 | |||
| 387 | /** |
||
| 388 | * Return's the prefix for the import files. |
||
| 389 | * |
||
| 390 | * @return string The prefix |
||
| 391 | */ |
||
| 392 | public function getPrefix() |
||
| 396 | |||
| 397 | /** |
||
| 398 | * Return's the array with the subject's observers. |
||
| 399 | * |
||
| 400 | * @return array The subject's observers |
||
| 401 | */ |
||
| 402 | public function getObservers() |
||
| 406 | |||
| 407 | /** |
||
| 408 | * Return's the array with the subject's callbacks. |
||
| 409 | * |
||
| 410 | * @return array The subject's callbacks |
||
| 411 | */ |
||
| 412 | public function getCallbacks() |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Return's the array with the subject's frontend input callbacks. |
||
| 419 | * |
||
| 420 | * @return array The subject's frontend input callbacks |
||
| 421 | */ |
||
| 422 | public function getFrontendInputCallbacks() |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Set's the flag to signal that the an OK file is needed for the subject |
||
| 429 | * to be processed. |
||
| 430 | * |
||
| 431 | * @param boolean $okFileNeeded TRUE if the subject needs an OK file, else FALSE |
||
| 432 | * |
||
| 433 | * @return void |
||
| 434 | */ |
||
| 435 | public function setOkFileNeeded($okFileNeeded) |
||
| 439 | |||
| 440 | /** |
||
| 441 | * Queries whether or not that the subject needs an OK file to be processed. |
||
| 442 | * |
||
| 443 | * @return boolean TRUE if the subject needs an OK file, else FALSE |
||
| 444 | */ |
||
| 445 | public function isOkFileNeeded() |
||
| 449 | |||
| 450 | /** |
||
| 451 | * Queries whether or not the subject should create a .imported flagfile |
||
| 452 | * |
||
| 453 | * @return boolean TRUE if subject has to create the .imported flagfile, else FALSE |
||
| 454 | */ |
||
| 455 | public function isCreatingImportedFile() |
||
| 459 | |||
| 460 | /** |
||
| 461 | * Return's the import adapter configuration instance. |
||
| 462 | * |
||
| 463 | * @return \TechDivision\Import\Configuration\Subject\ImportAdapterConfigurationInterface The import adapter configuration instance |
||
| 464 | */ |
||
| 465 | public function getImportAdapter() |
||
| 469 | |||
| 470 | /** |
||
| 471 | * Return's the export adapter configuration instance. |
||
| 472 | * |
||
| 473 | * @return \TechDivision\Import\Configuration\Subject\ExportAdapterConfigurationInterface The export adapter configuration instance |
||
| 474 | */ |
||
| 475 | public function getExportAdapter() |
||
| 479 | |||
| 480 | /** |
||
| 481 | * Return's the filesystem adapter configuration instance. |
||
| 482 | * |
||
| 483 | * @return \TechDivision\Import\Configuration\Subject\FilesystemAdapterConfigurationInterface The filesystem adapter configuration instance |
||
| 484 | */ |
||
| 485 | public function getFilesystemAdapter() |
||
| 489 | |||
| 490 | /** |
||
| 491 | * Return's the file resolver configuration instance. |
||
| 492 | * |
||
| 493 | * @return \TechDivision\Import\Configuration\Subject\FileResolverConfigurationInterface The file resolver configuration instance |
||
| 494 | */ |
||
| 495 | public function getFileResolver() |
||
| 499 | |||
| 500 | /** |
||
| 501 | * Return's the number converter configuration instance. |
||
| 502 | * |
||
| 503 | * @return \TechDivision\Import\Configuration\Subject\NumberConverterConfigurationInterface The number converter configuration instance |
||
| 504 | */ |
||
| 505 | public function getNumberConverter() |
||
| 509 | |||
| 510 | /** |
||
| 511 | * Return's the date converter configuration instance. |
||
| 512 | * |
||
| 513 | * @return \TechDivision\Import\Configuration\Subject\DateConverterConfigurationInterface The date converter configuration instance |
||
| 514 | */ |
||
| 515 | public function getDateConverter() |
||
| 519 | |||
| 520 | /** |
||
| 521 | * The array with the subject's custom header mappings. |
||
| 522 | * |
||
| 523 | * @return array The custom header mappings |
||
| 524 | */ |
||
| 525 | public function getHeaderMappings() |
||
| 529 | |||
| 530 | /** |
||
| 531 | * The array with the subject's custom image types. |
||
| 532 | * |
||
| 533 | * @return array The custom image types |
||
| 534 | */ |
||
| 535 | public function getImageTypes() |
||
| 539 | } |
||
| 540 |