| Total Complexity | 52 |
| Total Lines | 370 |
| Duplicated Lines | 0 % |
| Changes | 15 | ||
| Bugs | 0 | Features | 0 |
Complex classes like View 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 View, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | class View |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * Creates the view object for the HTML client. |
||
| 25 | * |
||
| 26 | * @param \Aimeos\MShop\ContextIface $context Context object |
||
| 27 | * @param \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder|\TYPO3\CMS\Core\Routing\RouterInterface $uriBuilder URL builder |
||
| 28 | * @param array $templatePaths List of base path names with relative template paths as key/value pairs |
||
| 29 | * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface|null $request Request object |
||
| 30 | * @param string|null $locale Code of the current language or null for no translation |
||
| 31 | * @return \Aimeos\Base\View\Iface View object |
||
| 32 | */ |
||
| 33 | public static function get(\Aimeos\MShop\ContextIface $context, $uriBuilder, array $templatePaths, |
||
| 34 | \TYPO3\CMS\Extbase\Mvc\RequestInterface $request = null, string $locale = null) : \Aimeos\Base\View\Iface |
||
| 35 | { |
||
| 36 | $configManager = GeneralUtility::makeInstance(ConfigurationManager::class); |
||
| 37 | $config = $configManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_FRAMEWORK); |
||
| 38 | |||
| 39 | $view = GeneralUtility::makeInstance(\TYPO3\CMS\Fluid\View\StandaloneView::class); |
||
| 40 | $view->setPartialRootPaths( $config['view']['partialRootPaths'] ?? [] ); |
||
| 41 | $view->setLayoutRootPaths( $config['view']['layoutRootPaths'] ?? [] ); |
||
| 42 | |||
| 43 | $engines = ['.html' => new \Aimeos\Base\View\Engine\Typo3($view)]; |
||
| 44 | |||
| 45 | $prefix = 'ai'; |
||
| 46 | if ($uriBuilder instanceof \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder) { |
||
| 47 | $prefix = $uriBuilder->getArgumentPrefix(); |
||
| 48 | } |
||
| 49 | |||
| 50 | $view = new \Aimeos\Base\View\Standard($templatePaths, $engines); |
||
| 51 | $view->prefix = $prefix; |
||
| 52 | |||
| 53 | $config = $context->config(); |
||
| 54 | $session = $context->session(); |
||
| 55 | |||
| 56 | self::addTranslate($view, $locale, $config->get('i18n', [])); |
||
| 57 | self::addParam($view, $request); |
||
| 58 | self::addConfig($view, $config); |
||
| 59 | self::addDate($view, $config, $locale); |
||
| 60 | self::addFormparam($view, [$prefix]); |
||
| 61 | self::addNumber($view, $config, $locale); |
||
| 62 | self::addUrl($view, $config, $uriBuilder, $request); |
||
| 63 | self::addSession($view, $session); |
||
| 64 | self::addRequest($view, $request); |
||
| 65 | self::addResponse($view); |
||
| 66 | self::addAccess($view); |
||
| 67 | |||
| 68 | return $view; |
||
| 69 | } |
||
| 70 | |||
| 71 | |||
| 72 | /** |
||
| 73 | * Adds the "access" helper to the view object |
||
| 74 | * |
||
| 75 | * @param \Aimeos\Base\View\Iface $view View object |
||
| 76 | * @return \Aimeos\Base\View\Iface Modified view object |
||
| 77 | */ |
||
| 78 | protected static function addAccess(\Aimeos\Base\View\Iface $view) : \Aimeos\Base\View\Iface |
||
| 79 | { |
||
| 80 | if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_access']) |
||
| 81 | && is_callable(($fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_access'])) |
||
| 82 | ) { |
||
| 83 | return $fcn($view); |
||
| 84 | } |
||
| 85 | |||
| 86 | $appType = null; |
||
| 87 | if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof \TYPO3\CMS\Core\Http\ServerRequest) { |
||
| 88 | $appType = \TYPO3\CMS\Core\Http\ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST']); |
||
| 89 | } |
||
| 90 | |||
| 91 | if ($appType && $appType->isBackend()) { |
||
| 92 | if ($GLOBALS['BE_USER']->isAdmin() === false) { |
||
| 93 | $groups = []; |
||
| 94 | foreach ((array) $GLOBALS['BE_USER']->userGroups as $entry) { |
||
| 95 | $groups[] = $entry['title']; |
||
| 96 | } |
||
| 97 | $helper = new \Aimeos\Base\View\Helper\Access\Standard($view, $groups); |
||
| 98 | } else { |
||
| 99 | $helper = new \Aimeos\Base\View\Helper\Access\All($view); |
||
| 100 | } |
||
| 101 | } else { |
||
| 102 | $t3context = GeneralUtility::makeInstance('TYPO3\CMS\Core\Context\Context'); |
||
| 103 | |||
| 104 | if ($t3context->getPropertyFromAspect('frontend.user', 'isLoggedIn')) { |
||
| 105 | $helper = new \Aimeos\Base\View\Helper\Access\Standard($view, $GLOBALS['TSFE']->fe_user->groupData['title']); |
||
| 106 | } else { |
||
| 107 | $helper = new \Aimeos\Base\View\Helper\Access\Standard($view, []); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | $view->addHelper('access', $helper); |
||
| 112 | |||
| 113 | return $view; |
||
| 114 | } |
||
| 115 | |||
| 116 | |||
| 117 | /** |
||
| 118 | * Adds the "config" helper to the view object |
||
| 119 | * |
||
| 120 | * @param \Aimeos\Base\View\Iface $view View object |
||
| 121 | * @param \Aimeos\Base\Config\Iface $config Configuration object |
||
| 122 | * @return \Aimeos\Base\View\Iface Modified view object |
||
| 123 | */ |
||
| 124 | protected static function addConfig(\Aimeos\Base\View\Iface $view, \Aimeos\Base\Config\Iface $config) : \Aimeos\Base\View\Iface |
||
| 125 | { |
||
| 126 | if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_config']) |
||
| 127 | && is_callable(($fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_config'])) |
||
| 128 | ) { |
||
| 129 | return $fcn($view, $config); |
||
| 130 | } |
||
| 131 | |||
| 132 | $conf = new \Aimeos\Base\Config\Decorator\Protect(clone $config, ['resource/*/baseurl'], ['resource']); |
||
| 133 | $helper = new \Aimeos\Base\View\Helper\Config\Standard($view, $conf); |
||
| 134 | $view->addHelper('config', $helper); |
||
| 135 | |||
| 136 | return $view; |
||
| 137 | } |
||
| 138 | |||
| 139 | |||
| 140 | /** |
||
| 141 | * Adds the "date" helper to the view object |
||
| 142 | * |
||
| 143 | * @param \Aimeos\Base\View\Iface $view View object |
||
| 144 | * @param \Aimeos\Base\Config\Iface $config Configuration object |
||
| 145 | * @param string|null $locale (Country specific) language code |
||
| 146 | * @return \Aimeos\Base\View\Iface Modified view object |
||
| 147 | */ |
||
| 148 | protected static function addDate(\Aimeos\Base\View\Iface $view, \Aimeos\Base\Config\Iface $config, |
||
| 149 | string $locale = null) : \Aimeos\Base\View\Iface |
||
| 150 | { |
||
| 151 | if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_date']) |
||
| 152 | && is_callable(($fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_date'])) |
||
| 153 | ) { |
||
| 154 | return $fcn($view, $config, $locale); |
||
| 155 | } |
||
| 156 | |||
| 157 | $format = $config->get('client/html/common/date/format'); |
||
| 158 | |||
| 159 | $helper = new \Aimeos\Base\View\Helper\Date\Standard($view, $format); |
||
| 160 | $view->addHelper('date', $helper); |
||
| 161 | |||
| 162 | return $view; |
||
| 163 | } |
||
| 164 | |||
| 165 | |||
| 166 | /** |
||
| 167 | * Adds the "formparam" helper to the view object |
||
| 168 | * |
||
| 169 | * @param \Aimeos\Base\View\Iface $view View object |
||
| 170 | * @param array $prefixes List of prefixes for the form name to build multi-dimensional arrays |
||
| 171 | * @return \Aimeos\Base\View\Iface Modified view object |
||
| 172 | */ |
||
| 173 | protected static function addFormparam(\Aimeos\Base\View\Iface $view, array $prefixes) : \Aimeos\Base\View\Iface |
||
| 185 | } |
||
| 186 | |||
| 187 | |||
| 188 | /** |
||
| 189 | * Adds the "number" helper to the view object |
||
| 190 | * |
||
| 191 | * @param \Aimeos\Base\View\Iface $view View object |
||
| 192 | * @param \Aimeos\Base\Config\Iface $config Configuration object |
||
| 193 | * @param string|null $locale (Country specific) language code |
||
| 194 | * @return \Aimeos\Base\View\Iface Modified view object |
||
| 195 | */ |
||
| 196 | protected static function addNumber(\Aimeos\Base\View\Iface $view, \Aimeos\Base\Config\Iface $config, |
||
| 197 | string $locale = null) : \Aimeos\Base\View\Iface |
||
| 198 | { |
||
| 199 | if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_number']) |
||
| 200 | && is_callable(($fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_number'])) |
||
| 201 | ) { |
||
| 202 | return $fcn($view, $config, $locale); |
||
| 203 | } |
||
| 204 | |||
| 205 | $format = $config->get('client/html/common/number/format'); |
||
| 206 | |||
| 207 | $helper = new \Aimeos\Base\View\Helper\Number\Locale($view, $locale ?? 'en', $format); |
||
| 208 | $view->addHelper('number', $helper); |
||
| 209 | |||
| 210 | return $view; |
||
| 211 | } |
||
| 212 | |||
| 213 | |||
| 214 | /** |
||
| 215 | * Adds the "param" helper to the view object |
||
| 216 | * |
||
| 217 | * @param \Aimeos\Base\View\Iface $view View object |
||
| 218 | * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface|null $request Request object or null if not available |
||
| 219 | * @return \Aimeos\Base\View\Iface Modified view object |
||
| 220 | */ |
||
| 221 | protected static function addParam(\Aimeos\Base\View\Iface $view, |
||
| 222 | \TYPO3\CMS\Extbase\Mvc\RequestInterface $request = null) : \Aimeos\Base\View\Iface |
||
| 223 | { |
||
| 224 | if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_param']) |
||
| 225 | && is_callable(($fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_param'])) |
||
| 226 | ) { |
||
| 227 | return $fcn($view, $request); |
||
| 228 | } |
||
| 229 | |||
| 230 | $params = $request ? $request->getArguments() : []; |
||
| 231 | $helper = new \Aimeos\Base\View\Helper\Param\Standard($view, $params['ai'] ?? $params); |
||
| 232 | $view->addHelper('param', $helper); |
||
| 233 | |||
| 234 | return $view; |
||
| 235 | } |
||
| 236 | |||
| 237 | |||
| 238 | /** |
||
| 239 | * Adds the "request" helper to the view object |
||
| 240 | * |
||
| 241 | * @param \Aimeos\Base\View\Iface $view View object |
||
| 242 | * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface|null $request Request object |
||
| 243 | * @return \Aimeos\Base\View\Iface Modified view object |
||
| 244 | */ |
||
| 245 | protected static function addRequest(\Aimeos\Base\View\Iface $view, |
||
| 246 | \TYPO3\CMS\Extbase\Mvc\RequestInterface $request = null) : \Aimeos\Base\View\Iface |
||
| 247 | { |
||
| 248 | if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_request']) |
||
| 249 | && is_callable(($fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_request'])) |
||
| 250 | ) { |
||
| 251 | return $fcn($view, $request); |
||
| 252 | } |
||
| 253 | |||
| 254 | $target = $GLOBALS["TSFE"]->id ?? null; |
||
| 255 | $get = GeneralUtility::_GET(); |
||
| 256 | $post = GeneralUtility::_POST(); |
||
| 257 | |||
| 258 | $helper = new \Aimeos\Base\View\Helper\Request\Typo3($view, $target, $_FILES, $get, $post, $_COOKIE, $_SERVER); |
||
| 259 | $view->addHelper('request', $helper); |
||
| 260 | |||
| 261 | return $view; |
||
| 262 | } |
||
| 263 | |||
| 264 | |||
| 265 | /** |
||
| 266 | * Adds the "response" helper to the view object |
||
| 267 | * |
||
| 268 | * @param \Aimeos\Base\View\Iface $view View object |
||
| 269 | * @return \Aimeos\Base\View\Iface Modified view object |
||
| 270 | */ |
||
| 271 | protected static function addResponse(\Aimeos\Base\View\Iface $view) : \Aimeos\Base\View\Iface |
||
| 272 | { |
||
| 273 | if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_response']) |
||
| 274 | && is_callable(($fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_response'])) |
||
| 275 | ) { |
||
| 276 | return $fcn($view); |
||
| 277 | } |
||
| 278 | |||
| 279 | $helper = new \Aimeos\Base\View\Helper\Response\Typo3($view); |
||
| 280 | $view->addHelper('response', $helper); |
||
| 281 | |||
| 282 | return $view; |
||
| 283 | } |
||
| 284 | |||
| 285 | |||
| 286 | /** |
||
| 287 | * Adds the "session" helper to the view object |
||
| 288 | * |
||
| 289 | * @param \Aimeos\Base\View\Iface $view View object |
||
| 290 | * @param \Aimeos\Base\Session\Iface $session Session object |
||
| 291 | * @return \Aimeos\Base\View\Iface Modified view object |
||
| 292 | */ |
||
| 293 | protected static function addSession(\Aimeos\Base\View\Iface $view, \Aimeos\Base\Session\Iface $session) : \Aimeos\Base\View\Iface |
||
| 294 | { |
||
| 295 | $helper = new \Aimeos\Base\View\Helper\Session\Standard($view, $session); |
||
| 296 | $view->addHelper('session', $helper); |
||
| 297 | |||
| 298 | return $view; |
||
| 299 | } |
||
| 300 | |||
| 301 | |||
| 302 | /** |
||
| 303 | * Adds the "translate" helper to the view object |
||
| 304 | * |
||
| 305 | * @param \Aimeos\Base\View\Iface $view View object |
||
| 306 | * @param string|null $langid ISO language code, e.g. "de" or "de_CH" |
||
| 307 | * @param array $local Local translations |
||
| 308 | * @return \Aimeos\Base\View\Iface Modified view object |
||
| 309 | */ |
||
| 310 | protected static function addTranslate(\Aimeos\Base\View\Iface $view, string $langid = null, array $local) : \Aimeos\Base\View\Iface |
||
| 311 | { |
||
| 312 | if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_translate']) |
||
| 313 | && is_callable(($fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_translate'])) |
||
| 314 | ) { |
||
| 315 | return $fcn($view, $langid, $local); |
||
| 316 | } |
||
| 317 | |||
| 318 | if ($langid) { |
||
| 319 | $i18n = \Aimeos\Aimeos\Base::i18n([$langid], $local); |
||
| 320 | $translation = $i18n[$langid]; |
||
| 321 | } else { |
||
| 322 | $translation = new \Aimeos\Base\Translation\None('en'); |
||
| 323 | } |
||
| 324 | |||
| 325 | $helper = new \Aimeos\Base\View\Helper\Translate\Standard($view, $translation); |
||
| 326 | $view->addHelper('translate', $helper); |
||
| 327 | |||
| 328 | return $view; |
||
| 329 | } |
||
| 330 | |||
| 331 | |||
| 332 | /** |
||
| 333 | * Adds the "url" helper to the view object |
||
| 334 | * |
||
| 335 | * @param \Aimeos\Base\View\Iface $view View object |
||
| 336 | * @param \Aimeos\Base\Config\Iface $config Configuration object |
||
| 337 | * @param \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder|\TYPO3\CMS\Core\Routing\RouterInterface $uriBuilder URI builder |
||
| 338 | * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface|null $request Request object |
||
| 339 | * @return \Aimeos\Base\View\Iface Modified view object |
||
| 340 | */ |
||
| 341 | protected static function addUrl(\Aimeos\Base\View\Iface $view, \Aimeos\Base\Config\Iface $config, $uriBuilder, |
||
| 391 | } |
||
| 392 | } |
||
| 393 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths