| Conditions | 2 |
| Paths | 2 |
| Total Lines | 57 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 38 |
| CRAP Score | 2 |
| Changes | 2 | ||
| 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 |
||
| 69 | 1 | public function show($id) |
|
| 70 | 1 | { |
|
| 71 | // Check if we are passing the customer slugged name, or customer ID number |
||
| 72 | if(is_numeric($id)) |
||
| 73 | 2 | { |
|
| 74 | 2 | // To keep things uniform, redirect to a link that has the customers name rather than the ID |
|
| 75 | 2 | $customer = Customer::findOrFail($id); |
|
| 76 | 2 | return redirect(route('customers.show', $customer->slug)); |
|
| 77 | 2 | } |
|
| 78 | 2 | ||
| 79 | 2 | // Pull the customers information |
|
| 80 | 2 | $customer = Customer::where('slug', $id) |
|
| 81 | 2 | ->orWhere('cust_id', $id) |
|
| 82 | 2 | ->with('Parent') |
|
| 83 | 2 | ->with('CustomerEquipment.CustomerEquipmentData') |
|
| 84 | 2 | ->with('ParentEquipment.CustomerEquipmentData') |
|
| 85 | 1 | ->with('CustomerContact.CustomerContactPhone.PhoneNumberType') |
|
| 86 | 1 | ->with('ParentContact.CustomerContactPhone.PhoneNumberType') |
|
| 87 | 1 | ->with('CustomerNote') |
|
| 88 | ->with('ParentNote') |
||
| 89 | 1 | ->with('CustomerFile.FileUpload') |
|
| 90 | 1 | ->with('ParentFile.FileUpload') |
|
| 91 | 1 | ->firstOrFail(); |
|
| 92 | 1 | // Determine if the customer is bookmarked by the user |
|
| 93 | $isFav = UserCustomerBookmark::where('user_id', Auth::user()->user_id) |
||
|
1 ignored issue
–
show
|
|||
| 94 | 1 | ->where('cust_id', $customer->cust_id) |
|
| 95 | 1 | ->count(); |
|
| 96 | 1 | ||
| 97 | 1 | return Inertia::render('Customers/Show', [ |
|
| 98 | 'details' => $customer, |
||
| 99 | 1 | 'phone_types' => PhoneNumberType::all(), |
|
| 100 | 1 | 'file_types' => CustomerFileType::all(), |
|
| 101 | 1 | // User Permissions for customers |
|
| 102 | 'user_data' => [ |
||
| 103 | 'fav' => $isFav, // Customer is bookmarked by the user |
||
| 104 | 1 | 'edit' => Auth::user()->can('update', $customer), // User is allowed to edit the customers basic details |
|
| 105 | 1 | 'manage' => Auth::user()->can('manage', $customer), // User can recover deleted items |
|
| 106 | 1 | 'deactivate' => Auth::user()->can('delete', $customer), // User can deactivate the customer profile |
|
| 107 | 'equipment' => [ |
||
| 108 | 'create' => Auth::user()->can('create', CustomerEquipment::class), // If user can add equipment |
||
| 109 | 1 | 'update' => Auth::user()->can('update', CustomerEquipment::class), // If user can edit equipment |
|
| 110 | 1 | 'delete' => Auth::user()->can('delete', CustomerEquipment::class), // If user can delete equipment |
|
| 111 | 1 | ], |
|
| 112 | 'contacts' => [ |
||
| 113 | 'create' => Auth::user()->can('create', CustomerContact::class), // If user can add contact |
||
| 114 | 1 | 'update' => Auth::user()->can('update', CustomerContact::class), // If user can edit contact |
|
| 115 | 1 | 'delete' => Auth::user()->can('delete', CustomerContact::class), // If user can delete contact |
|
| 116 | 1 | ], |
|
| 117 | 'notes' => [ |
||
| 118 | 'create' => Auth::user()->can('create', CustomerNote::class), // If user can add note |
||
| 119 | 'update' => Auth::user()->can('update', CustomerNote::class), // If user can edit note |
||
| 120 | 'delete' => Auth::user()->can('delete', CustomerNote::class), // If user can delete note |
||
| 121 | ], |
||
| 122 | 'files' => [ |
||
| 123 | 'create' => Auth::user()->can('create', CustomerFile::class), // If user can add file |
||
| 124 | 'update' => Auth::user()->can('update', CustomerFile::class), // If user can edit file |
||
| 125 | 1 | 'delete' => Auth::user()->can('delete', CustomerFile::class), // If user can delete file |
|
| 126 | ], |
||
| 218 |