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 namespace BB\Repo; |
||
| 6 | class UserRepository extends DBRepository |
||
| 7 | { |
||
| 8 | |||
| 9 | /** |
||
| 10 | * @var User |
||
| 11 | */ |
||
| 12 | protected $model; |
||
| 13 | /** |
||
| 14 | * @var AddressRepository |
||
| 15 | */ |
||
| 16 | private $addressRepository; |
||
| 17 | /** |
||
| 18 | * @var ProfileDataRepository |
||
| 19 | */ |
||
| 20 | private $profileDataRepository; |
||
| 21 | /** |
||
| 22 | * @var SubscriptionChargeRepository |
||
| 23 | */ |
||
| 24 | private $subscriptionChargeRepository; |
||
| 25 | |||
| 26 | public function __construct(User $model, AddressRepository $addressRepository, ProfileDataRepository $profileDataRepository, SubscriptionChargeRepository $subscriptionChargeRepository) |
||
| 34 | |||
| 35 | public function getActive() |
||
| 39 | |||
| 40 | public function getBillableActive() |
||
| 44 | |||
| 45 | public function getPaginated(array $params) |
||
| 60 | |||
| 61 | |||
| 62 | /** |
||
| 63 | * Return a collection of members for public display |
||
| 64 | * @param bool $showPrivateMembers Some members don't want to listed on public pages, set to true to show everyone |
||
| 65 | * @return mixed |
||
| 66 | */ |
||
| 67 | public function getActivePublicList($showPrivateMembers = false) |
||
| 75 | |||
| 76 | public function getTrustedMissingPhotos() |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Get a list of active members suitable for use in a dropdown |
||
| 83 | * @return array |
||
| 84 | */ |
||
| 85 | public function getAllAsDropdown() |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @param array $memberData The new members details |
||
| 97 | * @param boolean $isAdminCreating Is the user making the change an admin |
||
| 98 | * @return User |
||
| 99 | */ |
||
| 100 | public function registerMember(array $memberData, $isAdminCreating) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * The user has setup a payment method of some kind so they are now considered active |
||
| 124 | * This will kick off the automated member checking processes |
||
| 125 | * |
||
| 126 | * @param integer $userId |
||
| 127 | */ |
||
| 128 | public function ensureMembershipActive($userId) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @param integer $userId The ID of the user to be updated |
||
| 157 | * @param array $recordData The data to be updated |
||
| 158 | * @param boolean $isAdminUpdating Is the user making the change an admin |
||
| 159 | */ |
||
| 160 | public function updateMember($userId, array $recordData, $isAdminUpdating) |
||
| 175 | |||
| 176 | /** |
||
| 177 | * The member has left, disable their account and cancel any out stand sub charge records |
||
| 178 | * The payment day is also cleared so when they start again the payment is charge happens at restart time |
||
| 179 | * |
||
| 180 | * @param $userId |
||
| 181 | */ |
||
| 182 | public function memberLeft($userId) |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Record the new gocardless preauth id against the user and make sure their payment method reflects this |
||
| 195 | * |
||
| 196 | * @param integer $userId |
||
| 197 | * @param string $subscriptionId |
||
| 198 | */ |
||
| 199 | public function recordGoCardlessVariableDetails($userId, $subscriptionId) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Record the fact that the user has agreed to the member induction and the rules |
||
| 212 | * |
||
| 213 | * @param $userId |
||
| 214 | */ |
||
| 215 | public function recordInductionCompleted($userId) |
||
| 225 | |||
| 226 | } |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.