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 |
||
| 13 | abstract class AbstractDataCollector extends BaseDataCollector implements DataCollectionInterface |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var array |
||
| 17 | */ |
||
| 18 | protected $data = []; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | private $template; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var AdminRouteHelper |
||
| 27 | */ |
||
| 28 | protected $adminRouteHelper; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @return mixed |
||
|
|
|||
| 32 | */ |
||
| 33 | public function getTemplate() |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param $template |
||
| 40 | * |
||
| 41 | * @return $this |
||
| 42 | */ |
||
| 43 | public function setTemplate($template) |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param AdminRouteHelper $adminRouteHelper |
||
| 52 | */ |
||
| 53 | public function setAdminRouteHelper(AdminRouteHelper $adminRouteHelper) |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @param Request $request |
||
| 60 | * @param Response $response |
||
| 61 | * |
||
| 62 | * @return bool |
||
| 63 | */ |
||
| 64 | public function showDataCollection(Request $request, Response $response) |
||
| 82 | } |
||
| 83 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.