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 |
||
| 18 | class EditFormHandler |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var Twig_Environment |
||
| 22 | */ |
||
| 23 | private $twig; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var Router |
||
| 27 | */ |
||
| 28 | private $router; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var RequestStack |
||
| 32 | */ |
||
| 33 | private $requestStack; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * EditFormHandler constructor. |
||
| 37 | * |
||
| 38 | * @param Twig_Environment $twig |
||
| 39 | * @param RouterInterface $router |
||
| 40 | * @param RequestStack $requestStack |
||
| 41 | */ |
||
| 42 | public function __construct(Twig_Environment $twig, RouterInterface $router, RequestStack $requestStack) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Save the entity if the form is valid, and redirect to the list action if |
||
| 51 | * required |
||
| 52 | * |
||
| 53 | * @param FormInterface $form |
||
| 54 | * @param AdminInterface $admin |
||
| 55 | * |
||
| 56 | * @return RedirectResponse|Response |
||
| 57 | */ |
||
| 58 | public function handle(FormInterface $form, AdminInterface $admin) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Return true if the user should be redirected to the list action. |
||
| 95 | * |
||
| 96 | * @param AdminInterface $admin |
||
| 97 | * |
||
| 98 | * @return bool |
||
| 99 | */ |
||
| 100 | private function shouldRedirect(AdminInterface $admin) |
||
| 122 | } |
||
| 123 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.