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 |
||
21 | class DashboardController extends Controller |
||
22 | { |
||
23 | /** |
||
24 | * Start date. |
||
25 | * |
||
26 | * @var \Jenssegers\Date\Date |
||
27 | */ |
||
28 | protected $startDate; |
||
29 | |||
30 | /** |
||
31 | * The timezone the system is running in. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $timeZone; |
||
36 | |||
37 | /** |
||
38 | * Creates a new dashboard controller. |
||
39 | */ |
||
40 | public function __construct() |
||
41 | { |
||
42 | $this->startDate = new Date(); |
||
43 | $this->dateTimeZone = Setting::get('app_timezone'); |
||
|
|||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Shows the dashboard view. |
||
48 | * |
||
49 | * @return \Illuminate\View\View |
||
50 | */ |
||
51 | public function indexAction() |
||
63 | |||
64 | /** |
||
65 | * Shows the notifications view. |
||
66 | * |
||
67 | * @return \Illuminate\View\View |
||
68 | */ |
||
69 | public function showNotifications() |
||
74 | |||
75 | /** |
||
76 | * Fetches all of the issues over the last 30 days. |
||
77 | * |
||
78 | * @return \Illuminate\Support\Collection |
||
79 | */ |
||
80 | View Code Duplication | protected function getIssues() |
|
106 | |||
107 | /** |
||
108 | * Fetches all of the subscribers over the last 30 days. |
||
109 | * |
||
110 | * @return \Illuminate\Support\Collection |
||
111 | */ |
||
112 | View Code Duplication | protected function getSubscribers() |
|
138 | } |
||
139 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.