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 |
||
15 | class ActivityController extends Controller |
||
16 | { |
||
17 | /** |
||
18 | * @var ACSNodeRepository |
||
19 | */ |
||
20 | private $ACSNodeRepository; |
||
21 | /** |
||
22 | * @var EquipmentLogRepository |
||
23 | */ |
||
24 | private $equipmentLogRepository; |
||
25 | /** |
||
26 | * @var KeyFobAccess |
||
27 | */ |
||
28 | private $fobAccess; |
||
29 | |||
30 | /** |
||
31 | * NodeController constructor. |
||
32 | * |
||
33 | * @param ACSNodeRepository $ACSNodeRepository |
||
34 | */ |
||
35 | public function __construct(ACSNodeRepository $ACSNodeRepository, EquipmentLogRepository $equipmentLogRepository, KeyFobAccess $fobAccess) |
||
41 | |||
42 | /** |
||
43 | * Record the start of a new session |
||
44 | * |
||
45 | * @return \Illuminate\Http\Response |
||
46 | * |
||
47 | * @SWG\Post( |
||
48 | * path="/acs/activity", |
||
49 | * tags={"activity"}, |
||
50 | * description="Record the start of a period of activity, e.g. someone signing into the laser cutter. If an entry device is specified no equipment access record is started but an activity log is created", |
||
51 | * @SWG\Parameter(name="activity", in="body", required=true, @SWG\Schema(ref="#/definitions/Activity")), |
||
52 | * @SWG\Response(response="201", description="Activity started, the body will contain the new activityId"), |
||
53 | * @SWG\Response(response="404", description="Key fob not found"), |
||
54 | * security={{"api_key": {}}} |
||
55 | * ) |
||
56 | */ |
||
57 | public function store(Request $request) |
||
88 | |||
89 | /** |
||
90 | * Update an ongoing activity |
||
91 | * |
||
92 | * @return \Illuminate\Http\Response |
||
93 | * |
||
94 | * @SWG\Put( |
||
95 | * path="/acs/activity/{activityId}", |
||
96 | * tags={"activity"}, |
||
97 | * description="Record a heartbeat message for a period of activity, used to ensure activity periods are correctly recorded", |
||
98 | * @SWG\Parameter(name="activityId", in="path", type="string", required=true), |
||
99 | * @SWG\Response(response="200", description="Activity Heartbeat recorded"), |
||
100 | * security={{"api_key": {}}} |
||
101 | * ) |
||
102 | */ |
||
103 | View Code Duplication | public function update(Request $request, $activityId) |
|
111 | |||
112 | /** |
||
113 | * Show the form for creating a new resource. |
||
114 | * |
||
115 | * @return \Illuminate\Http\Response |
||
116 | * |
||
117 | * @SWG\Delete( |
||
118 | * path="/acs/activity/{activityId}", |
||
119 | * tags={"activity"}, |
||
120 | * description="End a period of an activity", |
||
121 | * @SWG\Parameter(name="activityId", in="path", type="string", required=true), |
||
122 | * @SWG\Response(response="204", description="Activity ended/deleted"), |
||
123 | * @SWG\Response(response="400", description="Session invalid"), |
||
124 | * security={{"api_key": {}}} |
||
125 | * ) |
||
126 | */ |
||
127 | View Code Duplication | public function destroy(Request $request, $activityId) |
|
135 | |||
136 | } |
||
137 |
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@property
annotation 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.