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 |
||
| 15 | class DomainConfiguration implements DomainConfigurationInterface |
||
| 16 | { |
||
| 17 | /** @var ContainerInterface */ |
||
| 18 | protected $container; |
||
| 19 | |||
| 20 | /** @var RequestStack */ |
||
| 21 | private $requestStack; |
||
| 22 | |||
| 23 | /** @var bool */ |
||
| 24 | protected $multiLanguage; |
||
| 25 | |||
| 26 | /** @var array */ |
||
| 27 | protected $requiredLocales; |
||
| 28 | |||
| 29 | /** @var string */ |
||
| 30 | protected $defaultLocale; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param ContainerInterface|string $multilanguage |
||
|
|
|||
| 34 | */ |
||
| 35 | View Code Duplication | public function __construct(/*ContainerInterface|RequestStack*/ $requestStack, $multilanguage = null, $defaultLocale = null, $requiredLocales = null) |
|
| 36 | { |
||
| 37 | if ($requestStack instanceof ContainerInterface) { |
||
| 38 | @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); |
||
| 39 | |||
| 40 | $this->container = $requestStack; |
||
| 41 | $this->multiLanguage = $this->container->getParameter( |
||
| 42 | 'multilanguage' |
||
| 43 | ); |
||
| 44 | $this->defaultLocale = $this->container->getParameter( |
||
| 45 | 'defaultlocale' |
||
| 46 | ); |
||
| 47 | $this->requiredLocales = explode( |
||
| 48 | '|', |
||
| 49 | $this->container->getParameter('requiredlocales') |
||
| 50 | ); |
||
| 51 | $this->requestStack = $this->container->get('request_stack'); |
||
| 52 | |||
| 53 | return; |
||
| 54 | } |
||
| 55 | |||
| 56 | $this->requestStack = $requestStack; |
||
| 57 | $this->multiLanguage = $multilanguage; |
||
| 58 | $this->defaultLocale = $defaultLocale; |
||
| 59 | |||
| 60 | $this->requiredLocales = explode('|', $requiredLocales); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | public function getHost() |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @return array |
||
| 76 | */ |
||
| 77 | public function getHosts() |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @return string |
||
| 84 | */ |
||
| 85 | public function getDefaultLocale() |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @param string|null $host |
||
| 92 | * |
||
| 93 | * @return bool |
||
| 94 | */ |
||
| 95 | public function isMultiLanguage($host = null) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @param string|null $host |
||
| 102 | * |
||
| 103 | * @return array |
||
| 104 | */ |
||
| 105 | public function getFrontendLocales($host = null) |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @param string|null $host |
||
| 112 | * |
||
| 113 | * @return array |
||
| 114 | */ |
||
| 115 | public function getBackendLocales($host = null) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @return bool |
||
| 122 | */ |
||
| 123 | public function isMultiDomainHost() |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @param string|null $host |
||
| 130 | * |
||
| 131 | * @return null |
||
| 132 | */ |
||
| 133 | public function getRootNode($host = null) |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @return array |
||
| 140 | */ |
||
| 141 | public function getExtraData() |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @return array |
||
| 148 | */ |
||
| 149 | public function getLocalesExtraData() |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @return null|\Symfony\Component\HttpFoundation\Request |
||
| 156 | */ |
||
| 157 | protected function getMasterRequest() |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @return array |
||
| 164 | */ |
||
| 165 | public function getFullHostConfig() |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @param string|null $host |
||
| 172 | * |
||
| 173 | * @return null |
||
| 174 | */ |
||
| 175 | public function getFullHost($host = null) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @param int $id |
||
| 182 | * |
||
| 183 | * @return null |
||
| 184 | */ |
||
| 185 | public function getFullHostById($id) |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @return null |
||
| 192 | */ |
||
| 193 | public function getHostSwitched() |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @param string|null $host |
||
| 200 | * |
||
| 201 | * @return null |
||
| 202 | */ |
||
| 203 | public function getHostBaseUrl($host = null) |
||
| 207 | |||
| 208 | } |
||
| 209 |
This check looks for
@paramannotations 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.