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\Services; |
||
| 14 | class KeyFobAccess |
||
| 15 | { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * The key fob string |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | protected $keyFobId; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * The key fob record |
||
| 25 | * @var KeyFob |
||
| 26 | */ |
||
| 27 | protected $keyFob; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * The key for the selected device |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | protected $deviceKey; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * The selected device record |
||
| 37 | * The device that's being acted apon |
||
| 38 | * @var |
||
| 39 | */ |
||
| 40 | protected $device; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * The action of the current session |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | protected $action; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var User |
||
| 50 | */ |
||
| 51 | protected $user; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var ActivityRepository |
||
| 55 | */ |
||
| 56 | protected $activityRepository; |
||
| 57 | |||
| 58 | |||
| 59 | protected $messageDelayed = false; |
||
| 60 | |||
| 61 | |||
| 62 | protected $memberName; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var Carbon |
||
| 66 | */ |
||
| 67 | protected $time; |
||
| 68 | /** |
||
| 69 | * @var EquipmentRepository |
||
| 70 | */ |
||
| 71 | private $equipmentRepository; |
||
| 72 | /** |
||
| 73 | * @var InductionRepository |
||
| 74 | */ |
||
| 75 | private $inductionRepository; |
||
| 76 | /** |
||
| 77 | * @var Credit |
||
| 78 | */ |
||
| 79 | private $bbCredit; |
||
| 80 | |||
| 81 | |||
| 82 | View Code Duplication | public function __construct(ActivityRepository $activityRepository, EquipmentRepository $equipmentRepository, InductionRepository $inductionRepository, Credit $bbCredit) |
|
| 89 | |||
| 90 | |||
| 91 | /** |
||
| 92 | * @param string $keyFobId |
||
| 93 | */ |
||
| 94 | public function setKeyFobId($keyFobId) |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @param string $deviceKey |
||
| 101 | */ |
||
| 102 | public function setDeviceKey($deviceKey) |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @param string $action |
||
| 109 | */ |
||
| 110 | public function setAction($action) |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @return string |
||
| 117 | */ |
||
| 118 | public function getKeyFobId() |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @return |
||
| 125 | */ |
||
| 126 | public function getKeyFob() |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @return string |
||
| 133 | */ |
||
| 134 | public function getDeviceKey() |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @return string |
||
| 141 | */ |
||
| 142 | public function getAction() |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @return User |
||
| 149 | */ |
||
| 150 | public function getUser() |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Check a fob id is valid for door entry and return the member if it is |
||
| 157 | * @param $keyId |
||
| 158 | * @param string $doorName |
||
| 159 | * @param $time |
||
| 160 | * @return \User |
||
| 161 | * @throws ValidationException |
||
| 162 | */ |
||
| 163 | public function verifyForEntry($keyId, $doorName, $time) |
||
| 198 | |||
| 199 | |||
| 200 | public function verifyForDevice($keyId, $device, $time) |
||
| 237 | |||
| 238 | View Code Duplication | public function lookupKeyFob($keyId) |
|
| 253 | |||
| 254 | |||
| 255 | /** |
||
| 256 | * @param $keyId |
||
| 257 | * |
||
| 258 | * @return KeyFob |
||
| 259 | */ |
||
| 260 | public function extendedKeyFobLookup($keyId) |
||
| 284 | |||
| 285 | public function logFailure() |
||
| 297 | |||
| 298 | public function logSuccess() |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @return mixed |
||
| 314 | */ |
||
| 315 | public function getMemberName() |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Set the time to a specific timestamp - the new entry system will be passing a local time with the requests |
||
| 322 | * @param null $time |
||
| 323 | */ |
||
| 324 | protected function setAccessTime($time = null) |
||
| 333 | |||
| 334 | } |
||
| 335 |
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.