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 |
||
| 29 | class AdminStatsController extends XtoolsController |
||
| 30 | { |
||
| 31 | /** @var Project The project being queried. */ |
||
| 32 | protected $project; |
||
| 33 | |||
| 34 | /** @var AdminStats The admin stats instance that does all the work. */ |
||
| 35 | protected $adminStats; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Get the tool's shortname. |
||
| 39 | * @return string |
||
| 40 | * @codeCoverageIgnore |
||
| 41 | */ |
||
| 42 | public function getToolShortname() |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Every action in this controller (other than 'index') calls this first. |
||
| 49 | * If a response is returned, the calling action is expected to return it. |
||
| 50 | * @param string $project |
||
| 51 | * @param string $start |
||
| 52 | * @param string $end |
||
| 53 | * @return AdminStats|RedirectResponse |
||
| 54 | */ |
||
| 55 | public function setUpAdminStats($project, $start = null, $end = null) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Method for rendering the AdminStats Main Form. |
||
| 78 | * This method redirects if valid parameters are found, making it a |
||
| 79 | * valid form endpoint as well. |
||
| 80 | * |
||
| 81 | * @param Request $request Generated by Symfony |
||
| 82 | * |
||
| 83 | * @Route("/adminstats", name="adminstats") |
||
| 84 | * @Route("/adminstats/", name="AdminStatsSlash") |
||
| 85 | * @Route("/adminstats/index.php", name="AdminStatsIndexPhp") |
||
| 86 | * |
||
| 87 | * @return Route|\Symfony\Component\HttpFoundation\Response |
||
| 88 | */ |
||
| 89 | View Code Duplication | public function indexAction(Request $request) |
|
| 105 | |||
| 106 | /** |
||
| 107 | * Method for rendering the AdminStats Results |
||
| 108 | * |
||
| 109 | * @param Request $request The HTTP request. |
||
| 110 | * @param string $project Project to run the results against |
||
| 111 | * @param string $start Date to start on. Must parse by strtotime. |
||
| 112 | * @param string $end Date to end on. Must parse by strtotime. |
||
| 113 | * |
||
| 114 | * @Route( |
||
| 115 | * "/adminstats/{project}/{start}/{end}", name="AdminStatsResult", |
||
| 116 | * requirements={"start" = "|\d{4}-\d{2}-\d{2}", "end" = "|\d{4}-\d{2}-\d{2}"} |
||
| 117 | * ) |
||
| 118 | * |
||
| 119 | * @return Route|\Symfony\Component\HttpFoundation\Response |
||
| 120 | * @todo Move SQL to a model. |
||
| 121 | * @codeCoverageIgnore |
||
| 122 | */ |
||
| 123 | public function resultAction(Request $request, $project, $start = null, $end = null) |
||
| 140 | |||
| 141 | /************************ API endpoints ************************/ |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Get users of the project that are capable of making 'admin actions', |
||
| 145 | * keyed by user name with a list of the relevant user groups as the values. |
||
| 146 | * @Route("/api/project/admins_groups/{project}", name="ProjectApiAdminsGroups") |
||
| 147 | * @param string $project Project domain or database name. |
||
| 148 | * @return Response |
||
| 149 | * @codeCoverageIgnore |
||
| 150 | */ |
||
| 151 | public function adminsGroupsApiAction($project) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Get users of the project that are capable of making 'admin actions', |
||
| 166 | * along with various stats about which actions they took. Time period is limited |
||
| 167 | * to one month. |
||
| 168 | * @Route("/api/project/adminstats/{project}/{days}", name="ProjectApiAdminStats") |
||
| 169 | * @param string $project Project domain or database name. |
||
| 170 | * @param int $days Number of days from present to grab data for. Maximum 30. |
||
| 171 | * @return Response |
||
| 172 | * @codeCoverageIgnore |
||
| 173 | */ |
||
| 174 | public function adminStatsApiAction($project, $days = 30) |
||
| 200 | } |
||
| 201 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..