| Conditions | 8 | 
| Paths | 1 | 
| Total Lines | 52 | 
| Code Lines | 39 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 6 | ||
| Bugs | 2 | Features | 1 | 
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 | ||
| 38 | public function ajax() | ||
| 39 |     { | ||
| 40 | return $this->datatables | ||
| 41 | ->eloquent($this->query()) | ||
| 42 |             ->editColumn('device.hostname', function($log) { | ||
|  | |||
| 43 |                 $hostname = is_null($log->device) ? trans('devices.text.deleted') : $log->device->hostname; | ||
| 44 |                 return '<a href="'.url("devices/".$log->device_id).'">'.$hostname.'</a>'; | ||
| 45 | }) | ||
| 46 |             ->editColumn('rule.name', function($log) { | ||
| 47 |                 if ($log->rule_id) { | ||
| 48 |                     return '<a href="'.url("alerting/rules/".$log->rule_id).'">'.$log->rule->name.'</a>'; | ||
| 49 | } | ||
| 50 |                 else { | ||
| 51 |                     return trans('alerting.general.text.invalid'); | ||
| 52 | } | ||
| 53 | }) | ||
| 54 |             ->editColumn('state', function($log) { | ||
| 55 | $icon = ''; | ||
| 56 | $colour = ''; | ||
| 57 | $text = ''; | ||
| 58 |                 if ($log->state == 0) { | ||
| 59 | $icon = 'check'; | ||
| 60 | $colour = 'green'; | ||
| 61 |                     $text   = trans('alerting.logs.text.ok'); | ||
| 62 | } | ||
| 63 |                 elseif ($log->state == 1) { | ||
| 64 | $icon = 'times'; | ||
| 65 | $colour = 'red'; | ||
| 66 |                     $text   = trans('alerting.logs.text.fail'); | ||
| 67 | } | ||
| 68 |                 elseif ($log->state == 2) { | ||
| 69 | $icon = 'volume-off'; | ||
| 70 | $colour = 'lightgrey'; | ||
| 71 |                     $text   = trans('alerting.logs.text.ack'); | ||
| 72 | } | ||
| 73 |                 elseif ($log->state == 3) { | ||
| 74 | $icon = 'arrow-down'; | ||
| 75 | $colour = 'orange'; | ||
| 76 |                     $text   = trans('alerting.logs.text.worse'); | ||
| 77 | } | ||
| 78 |                 elseif ($log->state == 4) { | ||
| 79 | $icon = 'arrow-up'; | ||
| 80 | $colour = 'khaki'; | ||
| 81 |                     $text   = trans('alerting.logs.text.better'); | ||
| 82 | } | ||
| 83 | return '<b><span class="fa fa-'.$icon.'" style="color:'.$colour.'"></span> '.$text.'</b>'; | ||
| 84 | }) | ||
| 85 |             ->editColumn('time_logged', function($log) { | ||
| 86 |                 return date('Y-m-d H:i:s', $log->time_logged / 1000); | ||
| 87 | }) | ||
| 88 | ->make(true); | ||
| 89 | } | ||
| 90 | |||
| 133 | 
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: