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) |
||
| 68 | { |
||
| 69 | if ($showPrivateMembers) { |
||
| 70 | return $this->model->with('profile', 'roles')->active()->where('status', '!=', 'leaving')->orderBy('given_name')->get(); |
||
| 71 | } else { |
||
| 72 | return $this->model->with('profile', 'roles')->active()->where('status', '!=', 'leaving')->where('profile_private', 0)->orderBy('given_name')->get(); |
||
| 73 | } |
||
| 74 | } |
||
| 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) |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @param integer $userId The ID of the user to be updated |
||
| 163 | * @param array $recordData The data to be updated |
||
| 164 | * @param boolean $isAdminUpdating Is the user making the change an admin |
||
| 165 | */ |
||
| 166 | public function updateMember($userId, array $recordData, $isAdminUpdating) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * The member has left, disable their account and cancel any out stand sub charge records |
||
| 184 | * The payment day is also cleared so when they start again the payment is charge happens at restart time |
||
| 185 | * |
||
| 186 | * @param $userId |
||
| 187 | */ |
||
| 188 | public function memberLeft($userId) |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Record the new gocardless preauth id against the user and make sure their payment method reflects this |
||
| 201 | * |
||
| 202 | * @param integer $userId |
||
| 203 | * @param string $subscriptionId |
||
| 204 | */ |
||
| 205 | public function recordGoCardlessVariableDetails($userId, $subscriptionId) |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Record the fact that the user has agreed to the member induction and the rules |
||
| 219 | * |
||
| 220 | * @param $userId |
||
| 221 | */ |
||
| 222 | public function recordInductionCompleted($userId) |
||
| 232 | |||
| 233 | public function getPendingInductionConfirmation() |
||
| 241 | |||
| 242 | } |
||
| 243 |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.