Conditions | 5 |
Paths | 10 |
Total Lines | 68 |
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 |
||
54 | public function initializeTsfe($pageId, $language = 0) |
||
55 | { |
||
56 | |||
57 | // resetting, a TSFE instance with data from a different page Id could be set already |
||
58 | unset($GLOBALS['TSFE']); |
||
59 | |||
60 | $cacheId = $pageId . '|' . $language; |
||
61 | |||
62 | /** @var Context $context */ |
||
63 | $context = GeneralUtility::makeInstance(Context::class); |
||
64 | $this->changeLanguageContext((int)$pageId, (int)$language); |
||
65 | |||
66 | if (!isset($this->requestCache[$cacheId])) { |
||
67 | $siteFinder = GeneralUtility::makeInstance(SiteFinder::class); |
||
68 | $site = $siteFinder->getSiteByPageId($pageId); |
||
69 | $siteLanguage = $site->getLanguageById($language); |
||
70 | |||
71 | $request = GeneralUtility::makeInstance(ServerRequest::class); |
||
72 | $request = $request->withAttribute('site', $site); |
||
73 | $this->requestCache[$cacheId] = $request->withAttribute('language', $siteLanguage); |
||
74 | } |
||
75 | $GLOBALS['TYPO3_REQUEST'] = $this->requestCache[$cacheId]; |
||
76 | |||
77 | if (!isset($this->tsfeCache[$cacheId])) { |
||
78 | |||
79 | if (Util::getIsTYPO3VersionBelow10()) { |
||
80 | $GLOBALS['TSFE'] = GeneralUtility::makeInstance(TypoScriptFrontendController::class, [], $pageId, 0); |
||
81 | } else { |
||
82 | $GLOBALS['TSFE'] = GeneralUtility::makeInstance(TypoScriptFrontendController::class, $context, $site, $siteLanguage); |
||
83 | $GLOBALS['TSFE']->id = $pageId; |
||
84 | $GLOBALS['TSFE']->type = 0; |
||
85 | } |
||
86 | |||
87 | // for certain situations we need to trick TSFE into granting us |
||
88 | // access to the page in any case to make getPageAndRootline() work |
||
89 | // see http://forge.typo3.org/issues/42122 |
||
90 | $pageRecord = BackendUtility::getRecord('pages', $pageId, 'fe_group'); |
||
91 | |||
92 | $feUser = GeneralUtility::makeInstance(FrontendUserAuthentication::class); |
||
93 | $userGroups = [0, -1]; |
||
94 | if (!empty($pageRecord['fe_group'])) { |
||
95 | $userGroups = array_unique(array_merge($userGroups, explode(',', $pageRecord['fe_group']))); |
||
96 | } |
||
97 | $context->setAspect('frontend.user', GeneralUtility::makeInstance(UserAspect::class, $feUser, $userGroups)); |
||
98 | |||
99 | // @extensionScannerIgnoreLine |
||
100 | $GLOBALS['TSFE']->sys_page = GeneralUtility::makeInstance(PageRepository::class); |
||
101 | $GLOBALS['TSFE']->getPageAndRootlineWithDomain($pageId); |
||
102 | |||
103 | $template = GeneralUtility::makeInstance(TemplateService::class, $context); |
||
104 | $GLOBALS['TSFE']->tmpl = $template; |
||
105 | $GLOBALS['TSFE']->forceTemplateParsing = true; |
||
106 | $GLOBALS['TSFE']->no_cache = true; |
||
107 | $GLOBALS['TSFE']->tmpl->start($GLOBALS['TSFE']->rootLine); |
||
108 | $GLOBALS['TSFE']->no_cache = false; |
||
109 | $GLOBALS['TSFE']->getConfigArray(); |
||
110 | $GLOBALS['TSFE']->settingLanguage(); |
||
111 | |||
112 | $GLOBALS['TSFE']->newCObj(); |
||
113 | $GLOBALS['TSFE']->absRefPrefix = self::getAbsRefPrefixFromTSFE($GLOBALS['TSFE']); |
||
114 | $GLOBALS['TSFE']->calculateLinkVars([]); |
||
115 | |||
116 | $this->tsfeCache[$cacheId] = $GLOBALS['TSFE']; |
||
117 | } |
||
118 | |||
119 | $GLOBALS['TSFE'] = $this->tsfeCache[$cacheId]; |
||
120 | $GLOBALS['TSFE']->settingLocale(); |
||
121 | $this->changeLanguageContext((int)$pageId, (int)$language); |
||
122 | } |
||
142 | } |