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 |
||
10 | class VendorController extends Controller |
||
11 | { |
||
12 | /** |
||
13 | * @var VendorRepository |
||
14 | */ |
||
15 | protected $vendors; |
||
16 | |||
17 | /** |
||
18 | * VendorController constructor. |
||
19 | * @param VendorRepository $vendorRepository |
||
20 | */ |
||
21 | public function __construct(VendorRepository $vendorRepository) |
||
25 | |||
26 | public function index() |
||
32 | |||
33 | /** |
||
34 | * Create vendor. |
||
35 | * |
||
36 | * @param VendorFormRequest $request |
||
37 | * @return \Illuminate\Http\RedirectResponse |
||
38 | */ |
||
39 | public function postCreate(VendorFormRequest $request) |
||
45 | |||
46 | /** |
||
47 | * Create form for vendor. |
||
48 | * |
||
49 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
50 | */ |
||
51 | public function getCreate() |
||
55 | |||
56 | /** |
||
57 | * Show vendor. |
||
58 | * |
||
59 | * @param $vendor |
||
60 | * @return mixed |
||
61 | */ |
||
62 | public function show($vendor) |
||
66 | |||
67 | /** |
||
68 | * Edit form for vendor. |
||
69 | * |
||
70 | * @param $vendor |
||
71 | * @return mixed |
||
72 | */ |
||
73 | public function edit($vendor) |
||
77 | |||
78 | /** |
||
79 | * Update vendor. |
||
80 | * |
||
81 | * @param VendorUpdateFormRequest $request |
||
82 | * @param $vendor |
||
83 | * @return \Illuminate\Http\RedirectResponse |
||
84 | */ |
||
85 | public function update(VendorUpdateFormRequest $request, $vendor) |
||
91 | |||
92 | public function vote_vendor(Request $request, $vendor) |
||
144 | } |
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.