| Conditions | 6 |
| Paths | 16 |
| Total Lines | 57 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 99 | public function destroy(Request $request) |
||
| 100 | { |
||
| 101 | try { |
||
| 102 | $ids = $request->input('select'); |
||
| 103 | if (!empty($ids)) { |
||
| 104 | foreach ($ids as $id) { |
||
| 105 | if ($id != 1) { |
||
| 106 | $category = $this->productCategory->where('id', $id)->first(); |
||
| 107 | if ($category) { |
||
| 108 | $category->delete(); |
||
| 109 | } else { |
||
| 110 | echo "<div class='alert alert-danger alert-dismissable'> |
||
| 111 | <i class='fa fa-ban'></i> |
||
| 112 | <b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '. |
||
| 113 | /* @scrutinizer ignore-type */\Lang::get('message.failed').' |
||
| 114 | <button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
||
| 115 | './* @scrutinizer ignore-type */\Lang::get('message.no-record').' |
||
| 116 | </div>'; |
||
| 117 | //echo \Lang::get('message.no-record') . ' [id=>' . $id . ']'; |
||
| 118 | } |
||
| 119 | echo "<div class='alert alert-success alert-dismissable'> |
||
| 120 | <i class='fa fa-ban'></i> |
||
| 121 | |||
| 122 | <b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '. |
||
| 123 | /* @scrutinizer ignore-type */\Lang::get('message.success').' |
||
| 124 | |||
| 125 | <button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
||
| 126 | './* @scrutinizer ignore-type */\Lang::get('message.deleted-successfully').' |
||
| 127 | </div>'; |
||
| 128 | } else { |
||
| 129 | echo "<div class='alert alert-danger alert-dismissable'> |
||
| 130 | <i class='fa fa-ban'></i> |
||
| 131 | <b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '. |
||
| 132 | /* @scrutinizer ignore-type */\Lang::get('message.failed').' |
||
| 133 | <button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
||
| 134 | './* @scrutinizer ignore-type */\Lang::get('message.can-not-delete-default').' |
||
| 135 | </div>'; |
||
| 136 | } |
||
| 137 | } |
||
| 138 | } else { |
||
| 139 | echo "<div class='alert alert-danger alert-dismissable'> |
||
| 140 | <i class='fa fa-ban'></i> |
||
| 141 | <b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '. |
||
| 142 | /* @scrutinizer ignore-type */\Lang::get('message.failed').' |
||
| 143 | <button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
||
| 144 | './* @scrutinizer ignore-type */\Lang::get('message.select-a-row').' |
||
| 145 | </div>'; |
||
| 146 | //echo \Lang::get('message.select-a-row'); |
||
| 147 | } |
||
| 148 | } catch (\Exception $e) { |
||
| 149 | echo "<div class='alert alert-danger alert-dismissable'> |
||
| 150 | <i class='fa fa-ban'></i> |
||
| 151 | <b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '. |
||
| 152 | /* @scrutinizer ignore-type */ |
||
| 153 | \Lang::get('message.failed').' |
||
| 154 | <button type=button class=close data-dismiss=alert aria-hidden=true>×</button> |
||
| 155 | '.$e->getMessage().' |
||
| 156 | </div>'; |
||
| 160 |