We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 43 |
| Total Lines | 293 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like BaseCommand 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 BaseCommand, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 40 | class BaseCommand extends Command |
||
| 41 | { |
||
| 42 | /** |
||
| 43 | * @var CollectionRepository |
||
| 44 | */ |
||
| 45 | protected $collectionRepository; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var DocumentRepository |
||
| 49 | */ |
||
| 50 | protected $documentRepository; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var LibraryRepository |
||
| 54 | */ |
||
| 55 | protected $libraryRepository; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var int |
||
| 59 | */ |
||
| 60 | protected $storagePid; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var \Kitodo\Dlf\Domain\Model\Library |
||
| 64 | */ |
||
| 65 | protected $owner; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Initialize the extbase repository based on the given storagePid. |
||
| 69 | * |
||
| 70 | * TYPO3 10+: Find a better solution e.g. based on Symfonie Dependancy Injection. |
||
| 71 | * |
||
| 72 | * @param int $storagePid The storage pid |
||
| 73 | * |
||
| 74 | * @return bool |
||
| 75 | */ |
||
| 76 | protected function initializeRepositories($storagePid) |
||
| 77 | { |
||
| 78 | if (MathUtility::canBeInterpretedAsInteger($storagePid)) { |
||
| 79 | $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class); |
||
| 80 | $frameworkConfiguration = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); |
||
| 81 | |||
| 82 | $frameworkConfiguration['persistence']['storagePid'] = MathUtility::forceIntegerInRange((int) $storagePid, 0); |
||
| 83 | $configurationManager->setConfiguration($frameworkConfiguration); |
||
| 84 | |||
| 85 | // TODO: When we drop support for TYPO3v9, we needn't/shouldn't use ObjectManager anymore |
||
| 86 | $objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
||
| 87 | |||
| 88 | $this->collectionRepository = $objectManager->get(CollectionRepository::class); |
||
| 89 | $this->documentRepository = $objectManager->get(DocumentRepository::class); |
||
| 90 | $this->libraryRepository = $objectManager->get(LibraryRepository::class); |
||
| 91 | } else { |
||
| 92 | return false; |
||
| 93 | } |
||
| 94 | $this->storagePid = MathUtility::forceIntegerInRange((int) $storagePid, 0); |
||
| 95 | |||
| 96 | return true; |
||
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Return matching uid of Solr core depending on the input value. |
||
| 101 | * |
||
| 102 | * @param array $solrCores array of the valid Solr cores |
||
| 103 | * @param string|bool|null $inputSolrId possible uid or name of Solr core |
||
| 104 | * |
||
| 105 | * @return int matching uid of Solr core |
||
| 106 | */ |
||
| 107 | protected function getSolrCoreUid(array $solrCores, $inputSolrId): int |
||
| 108 | { |
||
| 109 | if (MathUtility::canBeInterpretedAsInteger($inputSolrId)) { |
||
| 110 | $solrCoreUid = MathUtility::forceIntegerInRange((int) $inputSolrId, 0); |
||
| 111 | } else { |
||
| 112 | $solrCoreUid = $solrCores[$inputSolrId]; |
||
| 113 | } |
||
| 114 | return $solrCoreUid; |
||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Fetches all Solr cores on given page. |
||
| 119 | * |
||
| 120 | * @param int $pageId The UID of the Solr core or 0 to disable indexing |
||
| 121 | * |
||
| 122 | * @return array Array of valid Solr cores |
||
| 123 | */ |
||
| 124 | protected function getSolrCores(int $pageId): array |
||
| 146 | } |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Load XML file / IIIF resource from URL |
||
| 150 | * |
||
| 151 | * @access protected |
||
| 152 | * |
||
| 153 | * @param string $location: The URL of the file to load |
||
| 154 | * |
||
| 155 | * @return string|bool the found xml as string or false on failure |
||
| 156 | */ |
||
| 157 | protected function loadLocation($location) |
||
| 178 | } |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Update or insert document to database |
||
| 182 | * |
||
| 183 | * @param int|string $doc The document uid from DB OR the location of a mets document. |
||
| 184 | * |
||
| 185 | * @return bool true on success |
||
| 186 | */ |
||
| 187 | protected function saveToDatabase(Document $document) |
||
| 285 | } |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Get the ID of the parent document if the current document has one. |
||
| 289 | * Currently only applies to METS documents. |
||
| 290 | * |
||
| 291 | * @access protected |
||
| 292 | * |
||
| 293 | * @return int The parent document's id. |
||
| 294 | */ |
||
| 295 | protected function getParentDocumentUidForSaving(Document $document) |
||
| 336 |