| Conditions | 13 | 
| Paths | 80 | 
| Total Lines | 54 | 
| 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  | 
            ||
| 83 | public function doGenerate($location, array $parameters)  | 
            ||
| 84 |     { | 
            ||
| 85 | $urlAliasService = $this->repository->getURLAliasService();  | 
            ||
| 86 | |||
| 87 | $siteaccess = null;  | 
            ||
| 88 |         if (isset($parameters['siteaccess'])) { | 
            ||
| 89 | $siteaccess = $parameters['siteaccess'];  | 
            ||
| 90 | unset($parameters['siteaccess']);  | 
            ||
| 91 | }  | 
            ||
| 92 | |||
| 93 |         if ($siteaccess) { | 
            ||
| 94 | // We generate for a different SiteAccess, so potentially in a different language.  | 
            ||
| 95 |             $languages = $this->configResolver->getParameter('languages', null, $siteaccess); | 
            ||
| 96 | $urlAliases = $urlAliasService->listLocationAliases($location, false, null, null, $languages);  | 
            ||
| 97 | // Use the target SiteAccess root location  | 
            ||
| 98 |             $rootLocationId = $this->configResolver->getParameter('content.tree_root.location_id', null, $siteaccess); | 
            ||
| 99 |         } else { | 
            ||
| 100 | $languages = null;  | 
            ||
| 101 | $urlAliases = $urlAliasService->listLocationAliases($location, false);  | 
            ||
| 102 | $rootLocationId = $this->rootLocationId;  | 
            ||
| 103 | }  | 
            ||
| 104 | |||
| 105 | $queryString = '';  | 
            ||
| 106 | unset($parameters['language'], $parameters['contentId']);  | 
            ||
| 107 |         if (!empty($parameters)) { | 
            ||
| 108 | $queryString = '?' . http_build_query($parameters, '', '&');  | 
            ||
| 109 | }  | 
            ||
| 110 | |||
| 111 |         if (!empty($urlAliases)) { | 
            ||
| 112 | $path = $urlAliases[0]->path;  | 
            ||
| 113 | // Remove rootLocation's prefix if needed.  | 
            ||
| 114 |             if ($rootLocationId !== null) { | 
            ||
| 115 | $pathPrefix = $this->getPathPrefixByRootLocationId($rootLocationId, $languages, $siteaccess);  | 
            ||
| 116 | // "/" cannot be considered as a path prefix since it's root, so we ignore it.  | 
            ||
| 117 |                 if ($pathPrefix !== '/' && ($path === $pathPrefix || mb_stripos($path, $pathPrefix . '/') === 0)) { | 
            ||
| 118 | $path = mb_substr($path, mb_strlen($pathPrefix));  | 
            ||
| 119 |                 } elseif ($pathPrefix !== '/' && !$this->isUriPrefixExcluded($path) && $this->logger !== null) { | 
            ||
| 120 | // Location path is outside configured content tree and doesn't have an excluded prefix.  | 
            ||
| 121 | // This is most likely an error (from content edition or link generation logic).  | 
            ||
| 122 |                     $this->logger->warning("Generating a link to a location outside root content tree: '$path' is outside tree starting to location #$rootLocationId"); | 
            ||
| 123 | }  | 
            ||
| 124 | }  | 
            ||
| 125 |         } else { | 
            ||
| 126 | $path = $this->defaultRouter->generate(  | 
            ||
| 127 | self::INTERNAL_CONTENT_VIEW_ROUTE,  | 
            ||
| 128 | ['contentId' => $location->contentId, 'locationId' => $location->id]  | 
            ||
| 129 | );  | 
            ||
| 130 | }  | 
            ||
| 131 | |||
| 132 | $path = $path ?: '/';  | 
            ||
| 133 | |||
| 134 | // replace potentially unsafe characters with url-encoded counterpart  | 
            ||
| 135 | return strtr($path . $queryString, $this->unsafeCharMap);  | 
            ||
| 136 | }  | 
            ||
| 137 | |||
| 227 | 
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.