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 |
||
| 25 | class SlugRouter implements RouterInterface |
||
| 26 | { |
||
| 27 | |||
| 28 | public static $SLUG = "_slug"; |
||
| 29 | public static $SLUG_PREVIEW = "_slug_preview"; |
||
| 30 | |||
| 31 | /** @var DomainConfigurationInterface */ |
||
| 32 | protected $domainConfiguration; |
||
| 33 | |||
| 34 | /** @var RequestStack */ |
||
| 35 | private $requestStack; |
||
| 36 | |||
| 37 | /** @var EntityManagerInterface */ |
||
| 38 | private $em; |
||
| 39 | |||
| 40 | /** @var string */ |
||
| 41 | protected $adminKey; |
||
| 42 | |||
| 43 | /** @var RequestContext */ |
||
| 44 | protected $context; |
||
| 45 | |||
| 46 | /** @var RouteCollection */ |
||
| 47 | protected $routeCollection; |
||
| 48 | |||
| 49 | /** @var UrlGenerator */ |
||
| 50 | protected $urlGenerator; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var ContainerInterface |
||
| 54 | * @deprecated in KunstmaanNodeBundle 5.1 and will be removed in KunstmaanNodeBundle 6.0. |
||
| 55 | */ |
||
| 56 | protected $container; |
||
| 57 | |||
| 58 | /** @var string */ |
||
| 59 | protected $slugPattern; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * The constructor for this service |
||
| 63 | * |
||
| 64 | * @param ContainerInterface $container |
||
|
|
|||
| 65 | */ |
||
| 66 | public function __construct( |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Match given urls via the context to the routes we defined. |
||
| 95 | * This functionality re-uses the default Symfony way of routing and its |
||
| 96 | * components |
||
| 97 | * |
||
| 98 | * @param string $pathinfo |
||
| 99 | * |
||
| 100 | * @throws ResourceNotFoundException |
||
| 101 | * |
||
| 102 | * @return array |
||
| 103 | */ |
||
| 104 | public function match($pathinfo) |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Gets the request context. |
||
| 127 | * |
||
| 128 | * @return RequestContext The context |
||
| 129 | * |
||
| 130 | * @api |
||
| 131 | */ |
||
| 132 | public function getContext() |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Sets the request context. |
||
| 147 | * |
||
| 148 | * @param RequestContext $context The context |
||
| 149 | * |
||
| 150 | * @api |
||
| 151 | */ |
||
| 152 | public function setContext(RequestContext $context) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Generate an url for a supplied route. |
||
| 159 | * |
||
| 160 | * @param string $name The path |
||
| 161 | * @param array $parameters The route parameters |
||
| 162 | * @param int|bool $referenceType The type of reference to be generated (one of the UrlGeneratorInterface constants) |
||
| 163 | * |
||
| 164 | * @return null|string |
||
| 165 | */ |
||
| 166 | public function generate($name, $parameters = array(), $referenceType = UrlGenerator::ABSOLUTE_PATH) |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Getter for routeCollection |
||
| 178 | * |
||
| 179 | * @return \Symfony\Component\Routing\RouteCollection |
||
| 180 | */ |
||
| 181 | public function getRouteCollection() |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @return null|\Symfony\Component\HttpFoundation\Request |
||
| 195 | */ |
||
| 196 | protected function getMasterRequest() |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Add the preview route to the route collection |
||
| 207 | */ |
||
| 208 | protected function addPreviewRoute() |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Add the slug route to the route collection |
||
| 216 | */ |
||
| 217 | protected function addSlugRoute() |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Return preview route parameters |
||
| 225 | * |
||
| 226 | * @return array |
||
| 227 | */ |
||
| 228 | View Code Duplication | protected function getPreviewRouteParameters() |
|
| 253 | |||
| 254 | /** |
||
| 255 | * Return slug route parameters |
||
| 256 | * |
||
| 257 | * @return array |
||
| 258 | */ |
||
| 259 | View Code Duplication | protected function getSlugRouteParameters() |
|
| 284 | |||
| 285 | /** |
||
| 286 | * @return boolean |
||
| 287 | */ |
||
| 288 | protected function isMultiLanguage($host = null) |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @return array |
||
| 295 | */ |
||
| 296 | protected function getFrontendLocales() |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @return array |
||
| 303 | */ |
||
| 304 | protected function getBackendLocales() |
||
| 308 | |||
| 309 | /** |
||
| 310 | * @return string |
||
| 311 | */ |
||
| 312 | protected function getDefaultLocale() |
||
| 316 | |||
| 317 | /** |
||
| 318 | * @return string |
||
| 319 | */ |
||
| 320 | protected function getHost() |
||
| 324 | |||
| 325 | /** |
||
| 326 | * @return string |
||
| 327 | */ |
||
| 328 | protected function getSlugPattern() |
||
| 332 | |||
| 333 | /** |
||
| 334 | * @param string $name |
||
| 335 | * @param array $parameters |
||
| 336 | */ |
||
| 337 | View Code Duplication | protected function addRoute($name, array $parameters = array()) |
|
| 348 | |||
| 349 | /** |
||
| 350 | * @param array $matchResult |
||
| 351 | * |
||
| 352 | * @return \Kunstmaan\NodeBundle\Entity\NodeTranslation |
||
| 353 | */ |
||
| 354 | protected function getNodeTranslation($matchResult) |
||
| 367 | |||
| 368 | /** |
||
| 369 | * @return \Kunstmaan\NodeBundle\Repository\NodeTranslationRepository |
||
| 370 | */ |
||
| 371 | protected function getNodeTranslationRepository() |
||
| 380 | |||
| 381 | /** |
||
| 382 | * @param array $locales |
||
| 383 | * |
||
| 384 | * @return string |
||
| 385 | */ |
||
| 386 | protected function getEscapedLocales($locales) |
||
| 395 | } |
||
| 396 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.