Conditions | 9 |
Paths | 42 |
Total Lines | 62 |
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 |
||
114 | public function show(string $productKey, string $version, string $page = null) |
||
115 | { |
||
116 | // ensure product exists |
||
117 | $product = $this->productFinder->findProduct($productKey); |
||
118 | if (empty($product)) { |
||
119 | abort(404); |
||
120 | } |
||
121 | |||
122 | // get default version for product |
||
123 | $defaultVersion = $product->getDefaultVersion(); |
||
124 | if (!$product->hasVersion($version)) { |
||
125 | return redirect(route( |
||
126 | $this->configProvider->getProductPageRouteName(), |
||
127 | [$product->getKey(), $defaultVersion] |
||
128 | ), 301); |
||
129 | } |
||
130 | |||
131 | // get page content |
||
132 | $page = $page ?: self::DEFAULT_PAGE; |
||
133 | $content = $this->documentationProvider->getPage($product, $version, $page); |
||
134 | |||
135 | // ensure page has content |
||
136 | if (empty($content)) { |
||
137 | $this->logger->warning( |
||
138 | sprintf('Documentation page (%s) for %s has no content.', $page, $product->getName()), |
||
139 | ['product' => $product] |
||
140 | ); |
||
141 | abort(404); |
||
142 | } |
||
143 | |||
144 | $title = (new Crawler($content))->filterXPath('//h1'); |
||
145 | $section = ''; |
||
146 | |||
147 | // ensure section exists |
||
148 | if ($this->documentationProvider->sectionExists($product, $version, $page)) { |
||
149 | $section .= "/${page}"; |
||
150 | } elseif (!empty($page)) { |
||
151 | // section does not exist, go to version index |
||
152 | return redirect()->route($this->configProvider->getProductPageRouteName(), [$product->getKey(), $version]); |
||
153 | } |
||
154 | |||
155 | // set canonical |
||
156 | $canonical = null; |
||
157 | if ($this->documentationProvider->sectionExists($product, $defaultVersion, $page)) { |
||
158 | $canonical = route( |
||
159 | $this->configProvider->getProductPageRouteName(), |
||
160 | [$product->getKey(), $defaultVersion, $page] |
||
161 | ); |
||
162 | } |
||
163 | |||
164 | return view('docweaver::page', [ |
||
165 | 'canonical' => $canonical, |
||
166 | 'content' => $content, |
||
167 | 'currentProduct' => $product, |
||
168 | 'currentSection' => $section, |
||
169 | 'currentVersion' => $version, |
||
170 | 'index' => $this->documentationProvider->getPage($product, $version), |
||
171 | 'page' => $page, |
||
172 | 'title' => count($title) ? $title->text() : null, |
||
173 | 'versions' => $product->getVersions(), |
||
174 | ]); |
||
175 | } |
||
176 | } |
||
177 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.