We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 40 |
| Total Lines | 291 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
Complex classes like AbstractController 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 AbstractController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 34 | abstract class AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController implements LoggerAwareInterface |
||
| 35 | { |
||
| 36 | use LoggerAwareTrait; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var DocumentRepository |
||
| 40 | */ |
||
| 41 | protected $documentRepository; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param DocumentRepository $documentRepository |
||
| 45 | */ |
||
| 46 | public function injectDocumentRepository(DocumentRepository $documentRepository) |
||
| 47 | { |
||
| 48 | $this->documentRepository = $documentRepository; |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * This holds the current document |
||
| 53 | * |
||
| 54 | * @var \Kitodo\Dlf\Domain\Model\Document |
||
| 55 | * @access protected |
||
| 56 | */ |
||
| 57 | protected $document; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var array |
||
| 61 | * @access protected |
||
| 62 | */ |
||
| 63 | protected $extConf; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * This holds the request parameter |
||
| 67 | * |
||
| 68 | * @var array |
||
| 69 | * @access protected |
||
| 70 | */ |
||
| 71 | protected $requestData; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * This holds some common data for the fluid view |
||
| 75 | * |
||
| 76 | * @var array |
||
| 77 | * @access protected |
||
| 78 | */ |
||
| 79 | protected $viewData; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Initialize the plugin controller |
||
| 83 | * |
||
| 84 | * @access protected |
||
| 85 | * @return void |
||
| 86 | */ |
||
| 87 | protected function initialize() |
||
| 101 | ]; |
||
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Loads the current document into $this->document |
||
| 106 | * |
||
| 107 | * @access protected |
||
| 108 | * |
||
| 109 | * @param int $documentId: The document's UID (fallback: $this->requestData[id]) |
||
| 110 | * |
||
| 111 | * @return void |
||
| 112 | */ |
||
| 113 | protected function loadDocument(int $documentId = 0) |
||
| 176 | } |
||
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Configure URL for proxy. |
||
| 181 | * |
||
| 182 | * @access protected |
||
| 183 | * |
||
| 184 | * @param string $url URL for proxy configuration |
||
| 185 | * |
||
| 186 | * @return void |
||
| 187 | */ |
||
| 188 | protected function configureProxyUrl(&$url) { |
||
| 189 | $this->uriBuilder->reset() |
||
| 190 | ->setTargetPageUid($GLOBALS['TSFE']->id) |
||
| 191 | ->setCreateAbsoluteUri(!empty($this->settings['forceAbsoluteUrl'])) |
||
| 192 | ->setArguments([ |
||
| 193 | 'eID' => 'tx_dlf_pageview_proxy', |
||
| 194 | 'url' => $url, |
||
| 195 | 'uHash' => GeneralUtility::hmac($url, 'PageViewProxy') |
||
| 196 | ]) |
||
| 197 | ->build(); |
||
| 198 | } |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Checks if doc is missing or is empty (no pages) |
||
| 202 | * |
||
| 203 | * @return boolean |
||
| 204 | */ |
||
| 205 | protected function isDocMissingOrEmpty() |
||
| 206 | { |
||
| 207 | return $this->isDocMissing() || $this->document->getDoc()->numPages < 1; |
||
| 208 | } |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Checks if doc is missing |
||
| 212 | * |
||
| 213 | * @return boolean |
||
| 214 | */ |
||
| 215 | protected function isDocMissing() |
||
| 216 | { |
||
| 217 | return $this->document === null || $this->document->getDoc() === null; |
||
| 218 | } |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Returns the LanguageService |
||
| 222 | * |
||
| 223 | * @return LanguageService |
||
| 224 | */ |
||
| 225 | protected function getLanguageService(): LanguageService |
||
| 226 | { |
||
| 227 | return $GLOBALS['LANG']; |
||
| 228 | } |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Safely gets Parameters from request |
||
| 232 | * if they exist |
||
| 233 | * |
||
| 234 | * @param string $parameterName |
||
| 235 | * |
||
| 236 | * @return null|string|array |
||
| 237 | */ |
||
| 238 | protected function getParametersSafely($parameterName) |
||
| 239 | { |
||
| 240 | if ($this->request->hasArgument($parameterName)) { |
||
| 241 | return $this->request->getArgument($parameterName); |
||
| 242 | } |
||
| 243 | return null; |
||
| 244 | } |
||
| 245 | |||
| 246 | /** |
||
| 247 | * Sanitize input variables. |
||
| 248 | * |
||
| 249 | * @access protected |
||
| 250 | * |
||
| 251 | * @return void |
||
| 252 | */ |
||
| 253 | protected function sanitizeRequestData() |
||
| 254 | { |
||
| 255 | // tx_dlf[id] may only be an UID or URI. |
||
| 256 | if ( |
||
| 257 | !empty($this->requestData['id']) |
||
| 258 | && !MathUtility::canBeInterpretedAsInteger($this->requestData['id']) |
||
| 259 | && !GeneralUtility::isValidUrl($this->requestData['id']) |
||
| 260 | ) { |
||
| 261 | $this->logger->warning('Invalid ID or URI "' . $this->requestData['id'] . '" for document loading'); |
||
| 262 | unset($this->requestData['id']); |
||
| 263 | } |
||
| 264 | |||
| 265 | // tx_dlf[page] may only be a positive integer or valid XML ID. |
||
| 266 | if ( |
||
| 267 | !empty($this->requestData['page']) |
||
| 268 | && !MathUtility::canBeInterpretedAsInteger($this->requestData['page']) |
||
| 269 | && !Helper::isValidXmlId($this->requestData['page']) |
||
| 270 | ) { |
||
| 271 | $this->requestData['page'] = 1; |
||
| 272 | } |
||
| 273 | |||
| 274 | // tx_dlf[double] may only be 0 or 1. |
||
| 275 | $this->requestData['double'] = MathUtility::forceIntegerInRange($this->requestData['double'], 0, 1, 0); |
||
| 276 | } |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Sets page value. |
||
| 280 | * |
||
| 281 | * @access protected |
||
| 282 | * |
||
| 283 | * @return void |
||
| 284 | */ |
||
| 285 | protected function setPage() { |
||
| 286 | if (!empty($this->requestData['logicalPage'])) { |
||
| 287 | $this->requestData['page'] = $this->document->getDoc()->getPhysicalPage($this->requestData['logicalPage']); |
||
| 288 | // The logical page parameter should not appear again |
||
| 289 | unset($this->requestData['logicalPage']); |
||
| 290 | } |
||
| 291 | |||
| 292 | $this->setDefaultPage(); |
||
| 293 | } |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Sets default page value. |
||
| 297 | * |
||
| 298 | * @access protected |
||
| 299 | * |
||
| 300 | * @return void |
||
| 301 | */ |
||
| 302 | protected function setDefaultPage() { |
||
| 303 | // Set default values if not set. |
||
| 304 | // $this->requestData['page'] may be integer or string (physical structure @ID) |
||
| 305 | if ( |
||
| 306 | (int) $this->requestData['page'] > 0 |
||
| 307 | || empty($this->requestData['page']) |
||
| 308 | ) { |
||
| 309 | $this->requestData['page'] = MathUtility::forceIntegerInRange((int) $this->requestData['page'], 1, $this->document->getDoc()->numPages, 1); |
||
| 310 | } else { |
||
| 311 | $this->requestData['page'] = array_search($this->requestData['page'], $this->document->getDoc()->physicalStructure); |
||
| 312 | } |
||
| 313 | } |
||
| 314 | |||
| 315 | /** |
||
| 316 | * This is the constructor |
||
| 317 | * |
||
| 318 | * @access public |
||
| 319 | * |
||
| 320 | * @return void |
||
| 321 | */ |
||
| 322 | public function __construct() |
||
| 325 | } |
||
| 326 | } |
||
| 327 |