| Conditions | 11 |
| Paths | 42 |
| Total Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 getPath($name, $parameters = [], $relative = false) |
||
| 55 | { |
||
| 56 | $requestLocale = $this->request ? $this->request->getLocale() : $this->locale; |
||
| 57 | if ($name == 'victoire_core_page_show_by_id') { |
||
| 58 | $params = [ |
||
| 59 | 'viewId' => $parameters['viewId'], |
||
| 60 | 'locale' => $requestLocale, |
||
| 61 | ]; |
||
| 62 | unset($parameters['viewId']); |
||
| 63 | if (!empty($parameters['entityId'])) { |
||
| 64 | $params['entityId'] = $parameters['entityId']; |
||
| 65 | unset($parameters['entityId']); |
||
| 66 | } |
||
| 67 | |||
| 68 | try { |
||
| 69 | $page = $this->pageHelper->findPageByParameters($params); |
||
| 70 | $parameters['url'] = $page->getReference($requestLocale)->getUrl(); |
||
| 71 | } catch (ViewReferenceNotFoundException $e) { |
||
| 72 | $this->logger->error($e->getMessage(), [ |
||
| 73 | 'params' => $params, |
||
| 74 | ]); |
||
| 75 | $errorPage = $this->errorPageRepository->findOneByCode(404); |
||
| 76 | $parameters['url'] = $this->generator->generate( |
||
| 77 | 'victoire_core_page_show', |
||
| 78 | array_merge( |
||
| 79 | [ |
||
| 80 | '_locale' => $requestLocale, |
||
| 81 | 'url' => $errorPage ? $errorPage->getSlug() : '', |
||
| 82 | ], |
||
| 83 | $parameters |
||
| 84 | ) |
||
| 85 | ); |
||
| 86 | } |
||
| 87 | |||
| 88 | $name = 'victoire_core_page_show'; |
||
| 89 | } |
||
| 90 | |||
| 91 | $prefix = ''; |
||
| 92 | //if locale is passed (and different) and i18n strategy is "domain" |
||
| 93 | if (!empty($parameters['_locale']) |
||
| 94 | && $parameters['_locale'] != $requestLocale |
||
| 95 | && $this->localeResolver->localePattern === LocaleResolver::PATTERN_DOMAIN |
||
| 96 | ) { |
||
| 97 | $prefix = $this->getPrefix($parameters['_locale']); |
||
| 98 | //if we set a prefix, we don't want an absolute path |
||
| 99 | if ($prefix) { |
||
| 100 | $relative = true; |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | return $prefix.$this->generator->generate($name, $parameters, $relative ? UrlGeneratorInterface::ABSOLUTE_PATH : UrlGeneratorInterface::ABSOLUTE_URL); |
||
| 105 | } |
||
| 106 | |||
| 128 |