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 |
||
| 23 | class PageFacet implements FacetInterface |
||
| 24 | { |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | protected $name; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | protected $label; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | protected $dataType; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var bool |
||
| 43 | */ |
||
| 44 | protected $canModifyMatcher = false; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Constructor of a Generic Facet in Vidi. |
||
| 48 | * |
||
| 49 | * @param string $name |
||
| 50 | * @param string $label |
||
| 51 | */ |
||
| 52 | public function __construct($name, $label = '') |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return string |
||
| 60 | */ |
||
| 61 | public function getName(): string |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | public function getLabel(): string |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @return array |
||
| 76 | */ |
||
| 77 | public function getSuggestions(): array |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @return array |
||
| 90 | */ |
||
| 91 | protected function getStoragePages(): array |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @param string $tableName |
||
| 113 | * @return object|QueryBuilder |
||
| 114 | */ |
||
| 115 | protected function getQueryBuilder($tableName): QueryBuilder |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Returns a pointer to the database. |
||
| 124 | * |
||
| 125 | * @return \Fab\Vidi\Database\DatabaseConnection |
||
| 126 | */ |
||
| 127 | protected function getDatabaseConnection() |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @return LanguageService |
||
| 134 | */ |
||
| 135 | View Code Duplication | protected function getLanguageService(): LanguageService |
|
| 147 | |||
| 148 | /** |
||
| 149 | * @return bool |
||
| 150 | */ |
||
| 151 | public function hasSuggestions(): bool |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @param string $dataType |
||
| 158 | * @return $this |
||
| 159 | */ |
||
| 160 | public function setDataType($dataType): self |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @return bool |
||
| 168 | */ |
||
| 169 | public function canModifyMatcher(): bool |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @param Matcher $matcher |
||
| 176 | * @param $value |
||
| 177 | * @return Matcher |
||
| 178 | */ |
||
| 179 | public function modifyMatcher(Matcher $matcher, $value): Matcher |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Get the Vidi Module Loader. |
||
| 186 | * |
||
| 187 | * @return ModuleLoader|object |
||
| 188 | * @throws \InvalidArgumentException |
||
| 189 | */ |
||
| 190 | protected function getModuleLoader() |
||
| 194 | |||
| 195 | } |
||
| 196 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.