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 Resetter implements ResetterInterface |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * @var AliasProcessor |
||
| 30 | */ |
||
| 31 | private $aliasProcessor; |
||
| 32 | |||
| 33 | /*** |
||
| 34 | * @var ManagerInterface |
||
| 35 | */ |
||
| 36 | private $configManager; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var EventDispatcherInterface |
||
| 40 | */ |
||
| 41 | private $dispatcher; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var IndexManager |
||
| 45 | */ |
||
| 46 | private $indexManager; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var MappingBuilder |
||
| 50 | */ |
||
| 51 | private $mappingBuilder; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param ManagerInterface $configManager |
||
| 55 | * @param IndexManager $indexManager |
||
| 56 | * @param AliasProcessor $aliasProcessor |
||
| 57 | * @param MappingBuilder $mappingBuilder |
||
| 58 | * @param EventDispatcherInterface $eventDispatcher |
||
| 59 | * @param Client $client |
||
|
|
|||
| 60 | */ |
||
| 61 | 20 | View Code Duplication | public function __construct( |
| 79 | |||
| 80 | /** |
||
| 81 | * Deletes and recreates all indexes. |
||
| 82 | * |
||
| 83 | * @param bool $populating |
||
| 84 | * @param bool $force |
||
| 85 | */ |
||
| 86 | 1 | public function resetAllIndexes($populating = false, $force = false) |
|
| 92 | |||
| 93 | /** |
||
| 94 | * Deletes and recreates the named index. If populating, creates a new index |
||
| 95 | * with a randomised name for an alias to be set after population. |
||
| 96 | * |
||
| 97 | * @param string $indexName |
||
| 98 | * @param bool $populating |
||
| 99 | * @param bool $force If index exists with same name as alias, remove it |
||
| 100 | * |
||
| 101 | * @throws \InvalidArgumentException if no index exists for the given name |
||
| 102 | */ |
||
| 103 | 12 | public function resetIndex($indexName, $populating = false, $force = false) |
|
| 124 | |||
| 125 | /** |
||
| 126 | * Deletes and recreates a mapping type for the named index. |
||
| 127 | * |
||
| 128 | * @param string $indexName |
||
| 129 | * @param string $typeName |
||
| 130 | * |
||
| 131 | * @throws \InvalidArgumentException if no index or type mapping exists for the given names |
||
| 132 | * @throws ResponseException |
||
| 133 | */ |
||
| 134 | 5 | public function resetIndexType($indexName, $typeName) |
|
| 155 | |||
| 156 | /** |
||
| 157 | * A command run when a population has finished. |
||
| 158 | * |
||
| 159 | * @param string $indexName |
||
| 160 | * |
||
| 161 | * @deprecated |
||
| 162 | */ |
||
| 163 | public function postPopulate($indexName) |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Switching aliases. |
||
| 170 | * |
||
| 171 | * @param string $indexName |
||
| 172 | * @param bool $delete Delete or close index |
||
| 173 | * |
||
| 174 | * @throws \FOS\ElasticaBundle\Exception\AliasIsIndexException |
||
| 175 | */ |
||
| 176 | 2 | public function switchIndexAlias($indexName, $delete = true) |
|
| 185 | } |
||
| 186 |
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.