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 InvitationHandler |
||
| 19 | { |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var EntityManager |
||
| 23 | */ |
||
| 24 | protected $entityManager; |
||
| 25 | /** |
||
| 26 | * @var InvitationFactory |
||
| 27 | */ |
||
| 28 | protected $invitationFactory; |
||
| 29 | /** |
||
| 30 | * @var InvitationRepository |
||
| 31 | */ |
||
| 32 | protected $invitationRepository; |
||
| 33 | /** |
||
| 34 | * @var EntityRepository |
||
| 35 | */ |
||
| 36 | protected $userRepository; |
||
| 37 | /** |
||
| 38 | * @var TenantUserHandler |
||
| 39 | */ |
||
| 40 | protected $tenantUserHandler; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param $entityManager |
||
| 44 | * @param $invitationFactory |
||
| 45 | * @param $invitationRepository |
||
| 46 | * @param $tenantUserHandler |
||
| 47 | * @param $userRepository |
||
| 48 | */ |
||
| 49 | function __construct( |
||
| 62 | |||
| 63 | View Code Duplication | public function acceptInvitationById($invitationId) |
|
| 76 | |||
| 77 | /** |
||
| 78 | * @param InvitationInterface $invitation |
||
| 79 | * |
||
| 80 | * @return \Tahoe\Bundle\MultiTenancyBundle\Entity\TenantUser |
||
| 81 | */ |
||
| 82 | public function acceptInvitation(InvitationInterface $invitation) |
||
| 96 | |||
| 97 | public function delete($invitation, $withFlush = false) |
||
| 105 | |||
| 106 | View Code Duplication | public function rejectInvitationById($invitationId) |
|
| 119 | |||
| 120 | public function rejectInvitation(InvitationInterface $invitation) |
||
| 126 | } |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.