Conditions | 2 |
Paths | 2 |
Total Lines | 54 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Tests | 39 |
CRAP Score | 2 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
63 | 3 | public function show($id) |
|
64 | { |
||
65 | // Check if we are passing the customer slugged name, or customer ID number |
||
66 | 3 | if(is_numeric($id)) |
|
67 | { |
||
68 | // To keep things uniform, redirect to a link that has the customers name rather than the ID |
||
69 | 1 | $customer = Customer::findOrFail($id); |
|
70 | 1 | return redirect(route('customers.show', $customer->slug)); |
|
71 | } |
||
72 | |||
73 | 2 | $customer = Customer::where('slug', $id) |
|
74 | 2 | ->orWhere('cust_id', $id) |
|
75 | 2 | ->with('Parent') |
|
76 | 2 | ->with('CustomerEquipment.CustomerEquipmentData') |
|
77 | 2 | ->with('ParentEquipment.CustomerEquipmentData') |
|
78 | 2 | ->with('CustomerContact.CustomerContactPhone.PhoneNumberType') |
|
79 | 2 | ->with('ParentContact.CustomerContactPhone.PhoneNumberType') |
|
80 | 2 | ->with('CustomerNote') |
|
81 | 2 | ->with('ParentNote') |
|
82 | 2 | ->with('CustomerFile.FileUpload') |
|
83 | 2 | ->with('ParentFile.FileUpload') |
|
84 | 2 | ->firstOrFail(); |
|
85 | 1 | $isFav = UserCustomerBookmark::where('user_id', Auth::user()->user_id) |
|
1 ignored issue
–
show
|
|||
86 | 1 | ->where('cust_id', $customer->cust_id) |
|
87 | 1 | ->count(); |
|
88 | |||
89 | 1 | return Inertia::render('Customer/details', [ |
|
90 | 1 | 'details' => $customer, |
|
91 | 1 | 'phone_types' => PhoneNumberType::all(), |
|
92 | 1 | 'file_types' => CustomerFileType::all(), |
|
93 | 'user_functions' => [ |
||
94 | 1 | 'fav' => $isFav, // Customer is bookmarked by the user |
|
95 | 1 | 'edit' => Auth::user()->can('update', $customer), // User is allowed to edit the customers basic details |
|
96 | 1 | 'manage' => Auth::user()->can('manage', $customer), // User can recover deleted items |
|
97 | 1 | 'deactivate' => Auth::user()->can('delete', $customer), // User can deactivate the customer profile |
|
98 | 'equipment' => [ |
||
99 | 1 | 'create' => Auth::user()->can('create', CustomerEquipment::class), // If user can add equipment |
|
100 | 1 | 'update' => Auth::user()->can('update', CustomerEquipment::class), // If user can edit equipment |
|
101 | 1 | 'delete' => Auth::user()->can('delete', CustomerEquipment::class), // If user can delete eqipment |
|
102 | ], |
||
103 | 'contacts' => [ |
||
104 | 1 | 'create' => Auth::user()->can('create', CustomerContact::class), // If user can add contact |
|
105 | 1 | 'update' => Auth::user()->can('update', CustomerContact::class), // If user can edit contact |
|
106 | 1 | 'delete' => Auth::user()->can('delete', CustomerContact::class), // If user can delete contact |
|
107 | ], |
||
108 | 'notes' => [ |
||
109 | 1 | 'create' => Auth::user()->can('create', CustomerNote::class), // If user can add note |
|
110 | 1 | 'update' => Auth::user()->can('update', CustomerNote::class), // If user can edit note |
|
111 | 1 | 'delete' => Auth::user()->can('delete', CustomerNote::class), // If user can delete note |
|
112 | ], |
||
113 | 'files' => [ |
||
114 | 1 | 'create' => Auth::user()->can('create', CustomerFile::class), // If user can add file |
|
115 | 1 | 'update' => Auth::user()->can('update', CustomerFile::class), // If user can edit file |
|
116 | 1 | 'delete' => Auth::user()->can('delete', CustomerFile::class), // If user can delete file |
|
117 | ], |
||
178 |