| Total Complexity | 67 |
| Total Lines | 406 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like ClientConfigurationManager 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.
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 ClientConfigurationManager, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class ClientConfigurationManager |
||
| 25 | { |
||
| 26 | |||
| 27 | /** |
||
| 28 | * objectManager |
||
| 29 | * |
||
| 30 | * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface |
||
| 31 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
| 32 | */ |
||
| 33 | protected $objectManager; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * clientRepository |
||
| 37 | * |
||
| 38 | * @var \EWW\Dpf\Domain\Repository\ClientRepository |
||
| 39 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
| 40 | */ |
||
| 41 | protected $clientRepository; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * settings |
||
| 45 | * |
||
| 46 | * @var array |
||
| 47 | */ |
||
| 48 | protected $settings = array(); |
||
| 49 | |||
| 50 | |||
| 51 | /** |
||
| 52 | * settings |
||
| 53 | * |
||
| 54 | * @var \EWW\Dpf\Domain\Model\Client |
||
| 55 | */ |
||
| 56 | protected $client = null; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * extensionConfiguration |
||
| 60 | * |
||
| 61 | * @var array |
||
| 62 | */ |
||
| 63 | protected $extensionConfiguration = array(); |
||
| 64 | |||
| 65 | public function __construct() |
||
| 66 | { |
||
| 67 | $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class); |
||
| 68 | $clientRepository = $objectManager->get(ClientRepository::class); |
||
| 69 | |||
| 70 | if (TYPO3_MODE === 'BE') { |
||
| 71 | $selectedPageId = (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id'); |
||
| 72 | if ($selectedPageId) { |
||
| 73 | $this->client = $clientRepository->findAll()->current(); |
||
| 74 | |||
| 75 | $configurationManager = $objectManager->get(BackendConfigurationManager::class); |
||
| 76 | $settings = $configurationManager->getConfiguration(null, null); |
||
| 77 | $this->settings = $settings; //['settings']; |
||
| 78 | } |
||
| 79 | |||
| 80 | } else { |
||
| 81 | $this->client = $clientRepository->findAll()->current(); |
||
| 82 | |||
| 83 | $configurationManager = $objectManager->get(ConfigurationManager::class); |
||
| 84 | $this->settings = $configurationManager->getConfiguration( |
||
| 85 | \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS |
||
| 86 | ); |
||
| 87 | |||
| 88 | } |
||
| 89 | |||
| 90 | $this->extensionConfiguration = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( |
||
| 91 | \TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class |
||
| 92 | )->get('dpf'); |
||
| 93 | |||
| 94 | } |
||
| 95 | |||
| 96 | public function setConfigurationPid($pid) |
||
| 97 | { |
||
| 98 | $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class); |
||
| 99 | $clientRepository = $objectManager->get(ClientRepository::class); |
||
| 100 | |||
| 101 | $this->client = $clientRepository->findAllByPid($pid)->current(); |
||
| 102 | } |
||
| 103 | |||
| 104 | |||
| 105 | /** |
||
| 106 | * Get setting from client or extension configuration. |
||
| 107 | * |
||
| 108 | * @var array |
||
| 109 | */ |
||
| 110 | public function getSetting($settingName, $extConfig = null) |
||
| 111 | { |
||
| 112 | $setting = null; |
||
| 113 | if ($this->client) { |
||
| 114 | $setting = trim($this->client->{"get" . ucfirst($settingName)}()); |
||
| 115 | } |
||
| 116 | |||
| 117 | // use global extConfig if client settings is empty |
||
| 118 | if (empty($setting) && $extConfig) { |
||
| 119 | $setting = trim($this->extensionConfiguration[$extConfig]); |
||
| 120 | } |
||
| 121 | |||
| 122 | return $setting; |
||
| 123 | } |
||
| 124 | |||
| 125 | |||
| 126 | public function getOwnerId() |
||
| 127 | { |
||
| 128 | return $this->getSetting("ownerId"); |
||
| 129 | } |
||
| 130 | |||
| 131 | public function getSwordHost() |
||
| 132 | { |
||
| 133 | return $this->getSetting("swordHost", "swordHost"); |
||
| 134 | } |
||
| 135 | |||
| 136 | public function getSwordUser() |
||
| 137 | { |
||
| 138 | return $this->getSetting("swordUser", "swordUser"); |
||
| 139 | } |
||
| 140 | |||
| 141 | public function getSwordPassword() |
||
| 142 | { |
||
| 143 | return $this->getSetting("swordPassword", "swordPassword"); |
||
| 144 | } |
||
| 145 | |||
| 146 | public function getSwordCollectionNamespace() |
||
| 147 | { |
||
| 148 | return $this->getSetting("swordCollectionNamespace", "swordCollectionNamespace"); |
||
| 149 | } |
||
| 150 | |||
| 151 | public function getFedoraHost() |
||
| 152 | { |
||
| 153 | return $this->getSetting("fedoraHost", "fedoraHost"); |
||
| 154 | } |
||
| 155 | |||
| 156 | public function getFedoraUser() |
||
| 157 | { |
||
| 158 | return $this->getSetting("fedoraUser", "fedoraUser"); |
||
| 159 | } |
||
| 160 | |||
| 161 | public function getFedoraPassword() |
||
| 162 | { |
||
| 163 | return $this->getSetting("fedoraPassword", "fedoraPassword"); |
||
| 164 | } |
||
| 165 | |||
| 166 | public function getElasticSearchHost() |
||
| 167 | { |
||
| 168 | return $this->getSetting("elasticSearchHost", "elasticSearchHost"); |
||
| 169 | } |
||
| 170 | |||
| 171 | public function getElasticSearchPort() |
||
| 172 | { |
||
| 173 | return $this->getSetting("elasticSearchPort", "elasticSearchPort"); |
||
| 174 | } |
||
| 175 | |||
| 176 | public function getUploadDirectory() |
||
| 177 | { |
||
| 178 | return $this->getSetting("uploadDirectory", "uploadDirectory"); |
||
| 179 | } |
||
| 180 | |||
| 181 | public function getUploadDomain() |
||
| 182 | { |
||
| 183 | return $this->getSetting("uploadDomain", "uploadDomain"); |
||
| 184 | } |
||
| 185 | |||
| 186 | public function getSuggestionFlashMessage() |
||
| 187 | { |
||
| 188 | return $this->getSetting("suggestionFlashmessage", "suggestionFlashmessage"); |
||
| 189 | } |
||
| 190 | |||
| 191 | public function getFileXpath() |
||
| 192 | { |
||
| 193 | return $this->getSetting("fileXpath", "fileXpath"); |
||
| 194 | } |
||
| 195 | |||
| 196 | public function getStateXpath() |
||
| 197 | { |
||
| 198 | return $this->getSetting("stateXpath", "stateXpath"); |
||
| 199 | } |
||
| 200 | |||
| 201 | public function getTypeXpath() |
||
| 204 | } |
||
| 205 | |||
| 206 | public function getTypeXpathInput() |
||
| 207 | { |
||
| 208 | return $this->getSetting("typeXpathInput", "typeXpathInput"); |
||
| 209 | } |
||
| 210 | |||
| 211 | public function getUrnXpath() |
||
| 212 | { |
||
| 213 | return $this->getSetting("urnXpath", "urnXpath"); |
||
| 214 | } |
||
| 215 | |||
| 216 | public function getPrimaryUrnXpath() |
||
| 217 | { |
||
| 218 | return $this->getSetting("primaryUrnXpath", "primaryUrnXpath"); |
||
| 219 | } |
||
| 220 | |||
| 221 | public function getDateXpath() |
||
| 222 | { |
||
| 223 | return $this->getSetting("dateXpath", "dateXpath"); |
||
| 224 | } |
||
| 225 | |||
| 226 | public function getPublishingYearXpath() |
||
| 227 | { |
||
| 228 | return $this->getSetting("publishingYearXpath", "publishingYearXpath"); |
||
| 229 | } |
||
| 230 | |||
| 231 | public function getNamespaces() |
||
| 232 | { |
||
| 233 | return $this->getSetting("namespaces", "namespaces"); |
||
| 234 | } |
||
| 235 | |||
| 236 | public function getTitleXpath() |
||
| 237 | { |
||
| 238 | return $this->getSetting("titleXpath", "titleXpath"); |
||
| 239 | } |
||
| 240 | |||
| 241 | public function getOriginalSourceTitleXpath() |
||
| 242 | { |
||
| 243 | return $this->getSetting("originalSourceTitleXpath", "originalSourceTitleXpath"); |
||
| 244 | } |
||
| 245 | |||
| 246 | public function getProcessNumberXpath() |
||
| 247 | { |
||
| 248 | return $this->getSetting("processnumberXpath", "processnumberXpath"); |
||
| 249 | } |
||
| 250 | |||
| 251 | public function getSubmitterNameXpath() |
||
| 252 | { |
||
| 253 | return $this->getSetting("submitterNameXpath", "submitterNameXpath"); |
||
| 254 | } |
||
| 255 | |||
| 256 | public function getSubmitterEmailXpath() |
||
| 257 | { |
||
| 258 | return $this->getSetting("submitterEmailXpath", "submitterEmailXpath"); |
||
| 259 | } |
||
| 260 | |||
| 261 | public function getSubmitterNoticeXpath() |
||
| 262 | { |
||
| 263 | return $this->getSetting("submitterNoticeXpath", "submitterNoticeXpath"); |
||
| 264 | } |
||
| 265 | |||
| 266 | public function getCreatorXpath() |
||
| 267 | { |
||
| 268 | return $this->getSetting("creatorXpath", "creatorXpath"); |
||
| 269 | } |
||
| 270 | |||
| 271 | public function getCreationDateXpath() |
||
| 272 | { |
||
| 273 | return $this->getSetting("creationDateXpath", "creationDateXpath"); |
||
| 274 | } |
||
| 275 | |||
| 276 | public function getRepositoryCreationDateXpath() |
||
| 277 | { |
||
| 278 | return $this->getSetting("repositoryCreationDateXpath", "repositoryCreationDateXpath"); |
||
| 279 | } |
||
| 280 | |||
| 281 | public function getRepositoryLastModDateXpath() |
||
| 282 | { |
||
| 283 | return $this->getSetting("repositoryLastModDateXpath", "repositoryLastModDateXpath"); |
||
| 284 | } |
||
| 285 | |||
| 286 | public function getDepositLicenseXpath() |
||
| 287 | { |
||
| 288 | return $this->getSetting("depositLicenseXpath", "depositLicenseXpath"); |
||
| 289 | } |
||
| 290 | |||
| 291 | public function getAllNotesXpath() |
||
| 292 | { |
||
| 293 | return $this->getSetting("allNotesXpath", "allNotesXpath"); |
||
| 294 | } |
||
| 295 | |||
| 296 | public function getPrivateNotesXpath() |
||
| 297 | { |
||
| 298 | return $this->getSetting("privateNotesXpath", "privateNotesXpath"); |
||
| 299 | } |
||
| 300 | |||
| 301 | public function getInputTransformation() |
||
| 302 | { |
||
| 303 | return $this->client->getInputTransformation()->current(); |
||
| 304 | } |
||
| 305 | |||
| 306 | public function getOutputTransformation() |
||
| 307 | { |
||
| 308 | return $this->client->getOutputTransformation()->current(); |
||
| 309 | } |
||
| 310 | |||
| 311 | public function getPersonXpath() |
||
| 312 | { |
||
| 313 | return $this->getSetting("personXpath", "personXpath"); |
||
| 314 | } |
||
| 315 | |||
| 316 | public function getPersonFamilyXpath() |
||
| 317 | { |
||
| 318 | return $this->getSetting("personFamilyXpath", "personFamilyXpath"); |
||
| 319 | } |
||
| 320 | |||
| 321 | public function getPersonGivenXpath() |
||
| 324 | } |
||
| 325 | |||
| 326 | public function getPersonRoleXpath() |
||
| 327 | { |
||
| 328 | return $this->getSetting("personRoleXpath", "personRoleXpath"); |
||
| 329 | } |
||
| 330 | |||
| 331 | public function getPersonFisIdentifierXpath() |
||
| 332 | { |
||
| 333 | return $this->getSetting("personFisIdentifierXpath", "personFisIdentifierXpath"); |
||
| 334 | } |
||
| 335 | |||
| 336 | public function getPersonAffiliationXpath() |
||
| 337 | { |
||
| 338 | return $this->getSetting("personAffiliationXpath", "personAffiliationXpath"); |
||
| 339 | } |
||
| 340 | |||
| 341 | public function getPersonAffiliationIdentifierXpath() |
||
| 342 | { |
||
| 343 | return $this->getSetting("personAffiliationIdentifierXpath", "personAffiliationIdentifierXpath"); |
||
| 344 | } |
||
| 345 | |||
| 346 | public function getPersonAuthorRole() |
||
| 347 | { |
||
| 348 | return $this->getSetting("personAuthorRole", "personAuthorRole"); |
||
| 349 | } |
||
| 350 | |||
| 351 | public function getPersonPublisherRole() |
||
| 352 | { |
||
| 353 | return $this->getSetting("personPublisherRole", "personPublisherRole"); |
||
| 354 | } |
||
| 355 | |||
| 356 | public function getValidationXpath() |
||
| 357 | { |
||
| 358 | return $this->getSetting("validationXpath", "validationXpath"); |
||
| 359 | } |
||
| 360 | |||
| 361 | public function fisIdXpath() |
||
| 362 | { |
||
| 363 | return $this->getSetting("fisIdXpath", "fisIdXpath"); |
||
| 364 | } |
||
| 365 | |||
| 366 | public function getSourceDetailsXpaths() |
||
| 367 | { |
||
| 368 | return $this->getSetting("sourceDetailsXpaths", "sourceDetailsXpaths"); |
||
| 369 | } |
||
| 370 | |||
| 371 | public function getFedoraNamespace() |
||
| 372 | { |
||
| 373 | $settings = $this->getTypoScriptSettings(); |
||
| 374 | return $settings['fedoraNamespace']; |
||
| 375 | } |
||
| 376 | |||
| 377 | public function getTypoScriptSettings() |
||
| 386 | } |
||
| 387 | |||
| 388 | public function getFileIdXpath() |
||
| 389 | { |
||
| 390 | return $this->trimFileXpath($this->getSetting("fileIdXpath", "fileIdXpath")); |
||
|
|
|||
| 391 | } |
||
| 392 | |||
| 393 | public function getFileMimetypeXpath() |
||
| 394 | { |
||
| 395 | return $this->trimFileXpath($this->getSetting("fileMimetypeXpath", "fileMimetypeXpath")); |
||
| 396 | } |
||
| 397 | |||
| 398 | public function getFileHrefXpath() |
||
| 399 | { |
||
| 400 | return $this->trimFileXpath($this->getSetting("fileHrefXpath", "fileHrefXpath")); |
||
| 401 | } |
||
| 402 | |||
| 403 | public function getFileDownloadXpath() |
||
| 404 | { |
||
| 405 | return $this->trimFileXpath($this->getSetting("fileDownloadXpath", "fileDownloadXpath")); |
||
| 406 | } |
||
| 407 | |||
| 408 | public function getFileArchiveXpath() |
||
| 409 | { |
||
| 410 | return $this->trimFileXpath($this->getSetting("fileArchiveXpath", "fileArchiveXpath")); |
||
| 411 | } |
||
| 412 | |||
| 413 | public function getFileDeletedXpath() |
||
| 414 | { |
||
| 415 | return$this->trimFileXpath($this->getSetting("fileDeletedXpath", "fileDeletedXpath")); |
||
| 416 | } |
||
| 417 | |||
| 418 | public function getFileTitleXpath() |
||
| 419 | { |
||
| 420 | return $this->trimFileXpath($this->getSetting("fileTitleXpath", "fileTitleXpath")); |
||
| 421 | } |
||
| 422 | |||
| 423 | /** |
||
| 424 | * @param string $xpath |
||
| 425 | * @return string |
||
| 426 | */ |
||
| 427 | protected function trimFileXpath(string $xpath): ?string |
||
| 428 | { |
||
| 429 | return trim($xpath, "@/ "); |
||
| 430 | } |
||
| 431 | } |
||
| 432 |