Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
22 | class NodeTwigExtension extends AbstractExtension |
||
23 | { |
||
24 | /** |
||
25 | * @var EntityManagerInterface |
||
26 | */ |
||
27 | private $em; |
||
28 | |||
29 | /** |
||
30 | * @var UrlGeneratorInterface |
||
31 | */ |
||
32 | private $generator; |
||
33 | |||
34 | /** |
||
35 | * @var NodeMenu |
||
36 | */ |
||
37 | private $nodeMenu; |
||
38 | |||
39 | /** |
||
40 | * @var RequestStack |
||
41 | */ |
||
42 | private $requestStack; |
||
43 | |||
44 | /** |
||
45 | * @param \Doctrine\ORM\EntityManagerInterface $em |
||
46 | * @param \Symfony\Component\Routing\Generator\UrlGeneratorInterface $generator |
||
47 | * @param \Kunstmaan\NodeBundle\Helper\NodeMenu $nodeMenu |
||
48 | * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack |
||
49 | */ |
||
50 | public function __construct( |
||
61 | |||
62 | /** |
||
63 | * Returns a list of functions to add to the existing list. |
||
64 | * |
||
65 | * @return array An array of functions |
||
|
|||
66 | */ |
||
67 | public function getFunctions() |
||
115 | |||
116 | /** |
||
117 | * Get the node translation object based on node id and language. |
||
118 | * |
||
119 | * @param int $nodeId |
||
120 | * @param string $lang |
||
121 | * |
||
122 | * @return NodeTranslation |
||
123 | */ |
||
124 | public function getNodeTranslationByNodeId($nodeId, $lang) |
||
130 | |||
131 | /** |
||
132 | * @param NodeTranslation $nodeTranslation |
||
133 | * |
||
134 | * @return null|object |
||
135 | */ |
||
136 | public function getPageByNodeTranslation(NodeTranslation $nodeTranslation) |
||
140 | |||
141 | /** |
||
142 | * @param PageInterface $page |
||
143 | * |
||
144 | * @return Node |
||
145 | */ |
||
146 | public function getNodeFor(PageInterface $page) |
||
150 | |||
151 | /** |
||
152 | * @param PageInterface $page |
||
153 | * |
||
154 | * @return NodeTranslation |
||
155 | */ |
||
156 | public function getNodeTranslationFor(PageInterface $page) |
||
160 | |||
161 | /** |
||
162 | * @param string $internalName |
||
163 | * @param string $locale |
||
164 | * |
||
165 | * @return Node|null |
||
166 | */ |
||
167 | public function getNodeByInternalName($internalName, $locale) |
||
177 | |||
178 | /** |
||
179 | * @param string $internalName Internal name of the node |
||
180 | * @param string $locale Locale |
||
181 | * @param array $parameters (optional) extra parameters |
||
182 | * @param bool $relative (optional) return relative path? |
||
183 | * |
||
184 | * @return string |
||
185 | */ |
||
186 | View Code Duplication | public function getPathByInternalName($internalName, $locale, $parameters = array(), $relative = false) |
|
196 | |||
197 | /** |
||
198 | * @param string $internalName Internal name of the node |
||
199 | * @param string $locale Locale |
||
200 | * @param array $parameters (optional) extra parameters |
||
201 | * @param bool $schemeRelative (optional) return relative scheme? |
||
202 | * |
||
203 | * @return string |
||
204 | */ |
||
205 | View Code Duplication | public function getUrlByInternalName($internalName, $locale, $parameters = array(), $schemeRelative = false) |
|
215 | |||
216 | /** |
||
217 | * @param string $locale |
||
218 | * @param Node $node |
||
219 | * @param bool $includeHiddenFromNav |
||
220 | * |
||
221 | * @return NodeMenu |
||
222 | */ |
||
223 | public function getNodeMenu($locale, Node $node = null, $includeHiddenFromNav = false) |
||
234 | |||
235 | public function isStructureNode($page) |
||
239 | |||
240 | public function fileExists($filename) |
||
244 | |||
245 | /** |
||
246 | * @param string $internalName |
||
247 | * @param string $locale |
||
248 | * @param array $parameters |
||
249 | * |
||
250 | * @return array |
||
251 | */ |
||
252 | private function getRouteParametersByInternalName($internalName, $locale, $parameters = array()) |
||
270 | |||
271 | public function getOverviewRoute($node) |
||
279 | } |
||
280 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.