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