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 |
||
| 19 | class DetailView |
||
| 20 | { |
||
| 21 | /** @var string Name of module. */ |
||
| 22 | protected $moduleName; |
||
| 23 | |||
| 24 | /** @var \YF\Modules\Base\Model\Record Record model. */ |
||
| 25 | protected $record; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Returns model for detail view. |
||
| 29 | * |
||
| 30 | * @param string $moduleName |
||
| 31 | * |
||
| 32 | * @return self |
||
|
|
|||
| 33 | */ |
||
| 34 | public static function getInstance(string $moduleName): self |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Constructor. |
||
| 42 | * |
||
| 43 | * @param string $moduleName |
||
| 44 | */ |
||
| 45 | public function __construct(string $moduleName) |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Sets record model. |
||
| 52 | * |
||
| 53 | * @param \YF\Modules\Base\Model\Record $recordModel |
||
| 54 | * |
||
| 55 | * @return void |
||
| 56 | */ |
||
| 57 | public function setRecordModel(Record $recordModel): void |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Get detail view header links. |
||
| 64 | * |
||
| 65 | * @return array |
||
| 66 | */ |
||
| 67 | public function getLinksHeader(): array |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Get tabs. |
||
| 115 | * |
||
| 116 | * @return array |
||
| 117 | */ |
||
| 118 | View Code Duplication | public function getTabsFromApi(): array |
|
| 131 | } |
||
| 132 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.