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 |
||
| 26 | class SlugRouter implements RouterInterface |
||
| 27 | { |
||
| 28 | public static $SLUG = '_slug'; |
||
| 29 | |||
| 30 | public static $SLUG_PREVIEW = '_slug_preview'; |
||
| 31 | |||
| 32 | /** @var DomainConfigurationInterface */ |
||
| 33 | protected $domainConfiguration; |
||
| 34 | |||
| 35 | /** @var RequestStack */ |
||
| 36 | private $requestStack; |
||
| 37 | |||
| 38 | /** @var EntityManagerInterface */ |
||
| 39 | private $em; |
||
| 40 | |||
| 41 | /** @var string */ |
||
| 42 | protected $adminKey; |
||
| 43 | |||
| 44 | /** @var RequestContext */ |
||
| 45 | protected $context; |
||
| 46 | |||
| 47 | /** @var RouteCollection */ |
||
| 48 | protected $routeCollection; |
||
| 49 | |||
| 50 | /** @var UrlGenerator */ |
||
| 51 | protected $urlGenerator; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var ContainerInterface |
||
| 55 | * |
||
| 56 | * @deprecated in KunstmaanNodeBundle 5.1 and will be removed in KunstmaanNodeBundle 6.0. |
||
| 57 | */ |
||
| 58 | protected $container; |
||
| 59 | |||
| 60 | /** @var string */ |
||
| 61 | protected $slugPattern; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * The constructor for this service |
||
| 65 | * |
||
| 66 | * @param ContainerInterface $container |
||
|
|
|||
| 67 | */ |
||
| 68 | 12 | View Code Duplication | public function __construct( |
| 69 | /* DomainConfigurationInterface */ $domainConfiguration, |
||
| 70 | RequestStack $requestStack = null, |
||
| 71 | EntityManagerInterface $em = null, |
||
| 72 | $adminKey = null |
||
| 73 | ) { |
||
| 74 | 12 | $this->slugPattern = "[a-zA-Z0-9\-_\/]*"; |
|
| 75 | |||
| 76 | 12 | if ($domainConfiguration instanceof ContainerInterface) { |
|
| 77 | @trigger_error('Container injection and the usage of the container is deprecated in KunstmaanNodeBundle 5.1 and will be removed in KunstmaanNodeBundle 6.0.', E_USER_DEPRECATED); |
||
| 78 | |||
| 79 | $this->container = $domainConfiguration; |
||
| 80 | $this->domainConfiguration = $this->container->get('kunstmaan_admin.domain_configuration'); |
||
| 81 | $this->adminKey = $this->container->getParameter('kunstmaan_admin.admin_prefix'); |
||
| 82 | $this->requestStack = $this->container->get('request_stack'); |
||
| 83 | $this->em = $this->container->get('doctrine.orm.entity_manager'); |
||
| 84 | |||
| 85 | return; |
||
| 86 | } |
||
| 87 | |||
| 88 | 12 | $this->domainConfiguration = $domainConfiguration; |
|
| 89 | 12 | $this->adminKey = $adminKey; |
|
| 90 | 12 | $this->requestStack = $requestStack; |
|
| 91 | 12 | $this->em = $em; |
|
| 92 | 12 | } |
|
| 93 | |||
| 94 | /** |
||
| 95 | * Match given urls via the context to the routes we defined. |
||
| 96 | * This functionality re-uses the default Symfony way of routing and its |
||
| 97 | * components |
||
| 98 | * |
||
| 99 | * @param string $pathinfo |
||
| 100 | * |
||
| 101 | * @throws ResourceNotFoundException |
||
| 102 | * |
||
| 103 | * @return array |
||
| 104 | */ |
||
| 105 | 2 | public function match($pathinfo) |
|
| 123 | |||
| 124 | /** |
||
| 125 | * Gets the request context. |
||
| 126 | * |
||
| 127 | * @return RequestContext The context |
||
| 128 | * |
||
| 129 | * @api |
||
| 130 | */ |
||
| 131 | 10 | public function getContext() |
|
| 143 | |||
| 144 | /** |
||
| 145 | * Sets the request context. |
||
| 146 | * |
||
| 147 | * @param RequestContext $context The context |
||
| 148 | * |
||
| 149 | * @api |
||
| 150 | */ |
||
| 151 | 1 | public function setContext(RequestContext $context) |
|
| 155 | |||
| 156 | /** |
||
| 157 | * Generate an url for a supplied route. |
||
| 158 | * |
||
| 159 | * @param string $name The path |
||
| 160 | * @param array $parameters The route parameters |
||
| 161 | * @param int|bool $referenceType The type of reference to be generated (one of the UrlGeneratorInterface constants) |
||
| 162 | * |
||
| 163 | * @return null|string |
||
| 164 | */ |
||
| 165 | 2 | public function generate($name, $parameters = array(), $referenceType = UrlGenerator::ABSOLUTE_PATH) |
|
| 174 | |||
| 175 | /** |
||
| 176 | * Getter for routeCollection |
||
| 177 | * |
||
| 178 | * @return \Symfony\Component\Routing\RouteCollection |
||
| 179 | */ |
||
| 180 | 4 | public function getRouteCollection() |
|
| 191 | |||
| 192 | /** |
||
| 193 | * @return null|\Symfony\Component\HttpFoundation\Request |
||
| 194 | */ |
||
| 195 | 9 | protected function getMasterRequest() |
|
| 203 | |||
| 204 | /** |
||
| 205 | * Add the preview route to the route collection |
||
| 206 | */ |
||
| 207 | 5 | protected function addPreviewRoute() |
|
| 212 | |||
| 213 | /** |
||
| 214 | * Add the slug route to the route collection |
||
| 215 | */ |
||
| 216 | 4 | protected function addSlugRoute() |
|
| 221 | |||
| 222 | /** |
||
| 223 | * Return preview route parameters |
||
| 224 | * |
||
| 225 | * @return array |
||
| 226 | */ |
||
| 227 | 11 | View Code Duplication | protected function getPreviewRouteParameters() |
| 252 | |||
| 253 | /** |
||
| 254 | * Return slug route parameters |
||
| 255 | * |
||
| 256 | * @return array |
||
| 257 | */ |
||
| 258 | 4 | View Code Duplication | protected function getSlugRouteParameters() |
| 283 | |||
| 284 | /** |
||
| 285 | * @return bool |
||
| 286 | */ |
||
| 287 | 11 | protected function isMultiLanguage($host = null) |
|
| 291 | |||
| 292 | /** |
||
| 293 | * @return array |
||
| 294 | */ |
||
| 295 | 7 | protected function getFrontendLocales() |
|
| 299 | |||
| 300 | /** |
||
| 301 | * @return array |
||
| 302 | */ |
||
| 303 | 8 | protected function getBackendLocales() |
|
| 307 | |||
| 308 | /** |
||
| 309 | * @return string |
||
| 310 | */ |
||
| 311 | 11 | protected function getDefaultLocale() |
|
| 315 | |||
| 316 | /** |
||
| 317 | * @return string |
||
| 318 | */ |
||
| 319 | protected function getHost() |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @return string |
||
| 326 | */ |
||
| 327 | 11 | protected function getSlugPattern() |
|
| 331 | |||
| 332 | /** |
||
| 333 | * @param string $name |
||
| 334 | * @param array $parameters |
||
| 335 | */ |
||
| 336 | 5 | View Code Duplication | protected function addRoute($name, array $parameters = array()) |
| 347 | |||
| 348 | /** |
||
| 349 | * @param array $matchResult |
||
| 350 | * |
||
| 351 | * @return \Kunstmaan\NodeBundle\Entity\NodeTranslation |
||
| 352 | */ |
||
| 353 | 2 | protected function getNodeTranslation($matchResult) |
|
| 366 | |||
| 367 | /** |
||
| 368 | * @return \Kunstmaan\NodeBundle\Repository\NodeTranslationRepository |
||
| 369 | */ |
||
| 370 | 4 | protected function getNodeTranslationRepository() |
|
| 379 | |||
| 380 | /** |
||
| 381 | * @param array $locales |
||
| 382 | * |
||
| 383 | * @return string |
||
| 384 | */ |
||
| 385 | 8 | protected function getEscapedLocales($locales) |
|
| 394 | } |
||
| 395 |
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.