We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 58 |
| Total Lines | 366 |
| Duplicated Lines | 0 % |
| Changes | 6 | ||
| Bugs | 0 | Features | 0 |
Complex classes like CalendarController 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 CalendarController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | class CalendarController extends AbstractController |
||
| 21 | { |
||
| 22 | public $prefixId = 'tx_dlf'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * The main method of the plugin |
||
| 26 | * |
||
| 27 | * @return void |
||
| 28 | */ |
||
| 29 | public function mainAction() |
||
| 30 | { |
||
| 31 | $requestData = GeneralUtility::_GPmerged('tx_dlf'); |
||
| 32 | unset($requestData['__referrer'], $requestData['__trustedProperties']); |
||
| 33 | |||
| 34 | // Set initial document (anchor or year file) if configured. |
||
| 35 | if (empty($requestData['id']) && !empty($this->settings['initialDocument'])) { |
||
| 36 | $requestData['id'] = $this->settings['initialDocument']; |
||
| 37 | } |
||
| 38 | |||
| 39 | // Load current document. |
||
| 40 | $this->loadDocument($requestData); |
||
| 41 | if ($this->doc === null) { |
||
| 42 | // Quit without doing anything if required variables are not set. |
||
| 43 | return; |
||
| 44 | } |
||
| 45 | |||
| 46 | $metadata = $this->doc->getTitledata(); |
||
| 47 | if (!empty($metadata['type'][0])) { |
||
| 48 | $type = $metadata['type'][0]; |
||
| 49 | } else { |
||
| 50 | return; |
||
| 51 | } |
||
| 52 | |||
| 53 | switch ($type) { |
||
| 54 | case 'newspaper': |
||
| 55 | case 'ephemera': |
||
| 56 | $this->forward('years', NULL, NULL, $requestData); |
||
|
|
|||
| 57 | case 'year': |
||
| 58 | $this->forward('calendar', NULL, NULL, $requestData); |
||
| 59 | case 'issue': |
||
| 60 | default: |
||
| 61 | break; |
||
| 62 | } |
||
| 63 | |||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * The Calendar Method |
||
| 68 | * |
||
| 69 | * @access public |
||
| 70 | * |
||
| 71 | * @param string $content: The PlugIn content |
||
| 72 | * @param array $conf: The PlugIn configuration |
||
| 73 | * |
||
| 74 | * @return void |
||
| 75 | */ |
||
| 76 | public function calendarAction() |
||
| 191 | } |
||
| 192 | |||
| 193 | /** |
||
| 194 | * The Years Method |
||
| 195 | * |
||
| 196 | * @access public |
||
| 197 | * |
||
| 198 | * @return void |
||
| 199 | */ |
||
| 200 | public function yearsAction() |
||
| 201 | { |
||
| 202 | $requestData = GeneralUtility::_GPmerged('tx_dlf'); |
||
| 203 | unset($requestData['__referrer'], $requestData['__trustedProperties']); |
||
| 204 | |||
| 205 | // access arguments passed by the mainAction() |
||
| 206 | $mainrquestData = $this->request->getArguments(); |
||
| 207 | |||
| 208 | // merge both arguments together --> passing id by GET parameter tx_dlf[id] should win |
||
| 209 | $requestData = array_merge($requestData, $mainrquestData); |
||
| 210 | |||
| 211 | // Load current document. |
||
| 212 | $this->loadDocument($requestData); |
||
| 213 | if ($this->doc === null) { |
||
| 214 | // Quit without doing anything if required variables are not set. |
||
| 215 | return; |
||
| 216 | } |
||
| 217 | |||
| 218 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 219 | ->getQueryBuilderForTable('tx_dlf_documents'); |
||
| 220 | |||
| 221 | // Get all children of anchor. This should be the year anchor documents |
||
| 222 | $result = $queryBuilder |
||
| 223 | ->select( |
||
| 224 | 'tx_dlf_documents.uid AS uid', |
||
| 225 | 'tx_dlf_documents.title AS title', |
||
| 226 | 'tx_dlf_documents.mets_label AS label', |
||
| 227 | 'tx_dlf_documents.mets_orderlabel AS orderlabel' |
||
| 228 | ) |
||
| 229 | ->from('tx_dlf_documents') |
||
| 230 | ->where( |
||
| 231 | $queryBuilder->expr()->eq('tx_dlf_documents.structure', Helper::getUidFromIndexName('year', 'tx_dlf_structures', $this->doc->cPid)), |
||
| 232 | $queryBuilder->expr()->eq('tx_dlf_documents.partof', intval($this->doc->uid)), |
||
| 233 | Helper::whereExpression('tx_dlf_documents') |
||
| 234 | ) |
||
| 235 | ->orderBy('tx_dlf_documents.mets_orderlabel') |
||
| 236 | ->execute(); |
||
| 237 | |||
| 238 | $years = []; |
||
| 239 | // Process results. |
||
| 240 | while ($resArray = $result->fetch()) { |
||
| 241 | $years[] = [ |
||
| 242 | 'title' => !empty($resArray['label']) ? $resArray['label'] : (!empty($resArray['orderlabel']) ? $resArray['orderlabel'] : $resArray['title']), |
||
| 243 | 'uid' => $resArray['uid'] |
||
| 244 | ]; |
||
| 245 | } |
||
| 246 | $yearArray = []; |
||
| 247 | if (count($years) > 0) { |
||
| 248 | foreach ($years as $year) { |
||
| 249 | $yearArray[] = [ |
||
| 250 | 'documentId' => $year['uid'], |
||
| 251 | 'title' => $year['title'] |
||
| 252 | ]; |
||
| 253 | } |
||
| 254 | $this->view->assign('yearName', $yearArray); |
||
| 255 | } |
||
| 256 | |||
| 257 | $this->view->assign('documentId', $this->doc->uid); |
||
| 258 | $this->view->assign('allYearDocTitle', $this->doc->getTitle($this->doc->uid)); |
||
| 259 | } |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Build calendar for a certain year |
||
| 263 | * |
||
| 264 | * @access protected |
||
| 265 | * |
||
| 266 | * @param array $calendarIssuesByMonth All issues sorted by month => day |
||
| 267 | * @param int $year Gregorian year |
||
| 268 | * @param int $firstMonth 1 for January, 2 for February, ... 12 for December |
||
| 269 | * @param int $lastMonth 1 for January, 2 for February, ... 12 for December |
||
| 270 | * |
||
| 271 | * @return string Content for template subpart |
||
| 272 | */ |
||
| 273 | protected function getCalendarYear($calendarIssuesByMonth, $year, $firstMonth = 1, $lastMonth = 12) |
||
| 386 | } |
||
| 387 | } |
||
| 388 |