| Conditions | 5 |
| Paths | 10 |
| Total Lines | 70 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 56 | public function initializeTsfe($pageId, $language = 0) |
||
| 57 | { |
||
| 58 | |||
| 59 | // resetting, a TSFE instance with data from a different page Id could be set already |
||
| 60 | unset($GLOBALS['TSFE']); |
||
| 61 | |||
| 62 | $cacheId = $pageId . '|' . $language; |
||
| 63 | |||
| 64 | /** @var Context $context */ |
||
| 65 | $context = GeneralUtility::makeInstance(Context::class); |
||
| 66 | $this->changeLanguageContext((int)$pageId, (int)$language); |
||
| 67 | |||
| 68 | if (!isset($this->requestCache[$cacheId])) { |
||
| 69 | $siteFinder = GeneralUtility::makeInstance(SiteFinder::class); |
||
| 70 | $site = $siteFinder->getSiteByPageId($pageId); |
||
| 71 | $siteLanguage = $site->getLanguageById($language); |
||
| 72 | |||
| 73 | /** @var ServerRequest $request */ |
||
| 74 | $request = GeneralUtility::makeInstance(ServerRequest::class); |
||
| 75 | $request = $request->withAttribute('site', $site); |
||
| 76 | $this->requestCache[$cacheId] = $request->withAttribute('language', $siteLanguage); |
||
| 77 | } |
||
| 78 | $GLOBALS['TYPO3_REQUEST'] = $this->requestCache[$cacheId]; |
||
| 79 | |||
| 80 | |||
| 81 | if (!isset($this->tsfeCache[$cacheId])) { |
||
| 82 | |||
| 83 | if (Util::getIsTYPO3VersionBelow10()) { |
||
| 84 | $GLOBALS['TSFE'] = GeneralUtility::makeInstance(TypoScriptFrontendController::class, [], $pageId, 0); |
||
| 85 | } else { |
||
| 86 | $GLOBALS['TSFE'] = GeneralUtility::makeInstance(TypoScriptFrontendController::class, $context, $site, $siteLanguage); |
||
| 87 | $GLOBALS['TSFE']->id = $pageId; |
||
| 88 | $GLOBALS['TSFE']->type = 0; |
||
| 89 | } |
||
| 90 | |||
| 91 | // for certain situations we need to trick TSFE into granting us |
||
| 92 | // access to the page in any case to make getPageAndRootline() work |
||
| 93 | // see http://forge.typo3.org/issues/42122 |
||
| 94 | $pageRecord = BackendUtility::getRecord('pages', $pageId, 'fe_group'); |
||
| 95 | |||
| 96 | $feUser = GeneralUtility::makeInstance(FrontendUserAuthentication::class); |
||
| 97 | $userGroups = [0, -1]; |
||
| 98 | if (!empty($pageRecord['fe_group'])) { |
||
| 99 | $userGroups = array_unique(array_merge($userGroups, explode(',', $pageRecord['fe_group']))); |
||
| 100 | } |
||
| 101 | $context->setAspect('frontend.user', GeneralUtility::makeInstance(UserAspect::class, $feUser, $userGroups)); |
||
| 102 | |||
| 103 | // @extensionScannerIgnoreLine |
||
| 104 | $GLOBALS['TSFE']->sys_page = GeneralUtility::makeInstance(PageRepository::class); |
||
| 105 | $GLOBALS['TSFE']->getPageAndRootlineWithDomain($pageId, $GLOBALS['TYPO3_REQUEST']); |
||
| 106 | |||
| 107 | $template = GeneralUtility::makeInstance(TemplateService::class, $context); |
||
| 108 | $GLOBALS['TSFE']->tmpl = $template; |
||
| 109 | $GLOBALS['TSFE']->forceTemplateParsing = true; |
||
| 110 | $GLOBALS['TSFE']->no_cache = true; |
||
| 111 | $GLOBALS['TSFE']->tmpl->start($GLOBALS['TSFE']->rootLine); |
||
| 112 | $GLOBALS['TSFE']->no_cache = false; |
||
| 113 | $GLOBALS['TSFE']->getConfigArray(); |
||
| 114 | $GLOBALS['TSFE']->settingLanguage(); |
||
| 115 | |||
| 116 | $GLOBALS['TSFE']->newCObj(); |
||
| 117 | $GLOBALS['TSFE']->absRefPrefix = self::getAbsRefPrefixFromTSFE($GLOBALS['TSFE']); |
||
| 118 | $GLOBALS['TSFE']->calculateLinkVars([]); |
||
| 119 | |||
| 120 | $this->tsfeCache[$cacheId] = $GLOBALS['TSFE']; |
||
| 121 | } |
||
| 122 | |||
| 123 | $GLOBALS['TSFE'] = $this->tsfeCache[$cacheId]; |
||
| 124 | $GLOBALS['TSFE']->settingLocale(); |
||
| 125 | $this->changeLanguageContext((int)$pageId, (int)$language); |
||
| 126 | } |
||
| 147 |