| Conditions | 11 |
| Paths | 2 |
| Total Lines | 43 |
| Code Lines | 32 |
| Lines | 8 |
| Ratio | 18.6 % |
| Changes | 3 | ||
| Bugs | 0 | 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 |
||
| 44 | public function ajax() |
||
| 45 | { |
||
| 46 | if ($this->type !== "arp") |
||
| 47 | { |
||
| 48 | return $this->datatables |
||
| 49 | ->eloquent($this->query()) |
||
| 50 | ->editColumn('hostname', function($data) { |
||
|
|
|||
| 51 | $hostname = is_null($data->device) ? trans('devices.text.deleted') : $data->device->hostname; |
||
| 52 | return '<a href="'.url("devices/".$data->device_id).'">'.$hostname.'</a>'; |
||
| 53 | }) |
||
| 54 | View Code Duplication | ->editColumn('ifName', function($data) { |
|
| 55 | $ifName = is_null($data->ifName) ? trans('devices.text.deleted') : $data->ifName; |
||
| 56 | return '<a href="'.url("devices/".$data->device_id."/ports/".$data->port_id).'">'.$ifName.'</a>'; |
||
| 57 | }) |
||
| 58 | ->make(true); |
||
| 59 | } |
||
| 60 | else { |
||
| 61 | return $this->datatables |
||
| 62 | ->eloquent($this->query()) |
||
| 63 | ->editColumn('hostname', function($data) { |
||
| 64 | $hostname = is_null($data->device) ? trans('devices.text.deleted') : $data->device->hostname; |
||
| 65 | return '<a href="'.url("devices/".$data->device_id).'">'.$hostname.'</a>'; |
||
| 66 | }) |
||
| 67 | View Code Duplication | ->editColumn('ifName', function($data) { |
|
| 68 | $ifName = is_null($data->ifName) ? trans('devices.text.deleted') : $data->ifName; |
||
| 69 | return '<a href="'.url("devices/".$data->device_id."/ports/".$data->port_id).'">'.$ifName.'</a>'; |
||
| 70 | }) |
||
| 71 | ->addColumn('remote_device', function($data) { |
||
| 72 | $remote_device = IPv4::where('ipv4_addresses.ipv4_address', $data->ipv4_address)->with('port.device')->first(); |
||
| 73 | $remote_id = empty($remote_device->port->device->device_id) ? '' : $remote_device->port->device->device_id; |
||
| 74 | $remote_hostname = empty($remote_device->port->device->hostname) ? trans('devices.text.deleted') : $remote_device->port->device->hostname; |
||
| 75 | return '<a href="'.url("devices/".$remote_id).'">'.$remote_hostname.'</a>'; |
||
| 76 | }) |
||
| 77 | ->addColumn('remote_interface', function($data) { |
||
| 78 | $remote_device = IPv4::where('ipv4_addresses.ipv4_address', $data->ipv4_address)->with('port.device')->first(); |
||
| 79 | $remote_id = empty($remote_device->port->device->device_id) ? '' : $remote_device->port->device->device_id; |
||
| 80 | $remote_port_id = empty($remote_device->port->port_id) ? '' : $remote_device->port->port_id; |
||
| 81 | $remote_port = empty($remote_device->port->ifName) ? trans('devices.text.deleted') : $remote_device->port->ifName; |
||
| 82 | return '<a href="'.url("devices/".$remote_id."/ports/".$remote_port_id).'">'.$remote_port.'</a>'; |
||
| 83 | }) |
||
| 84 | ->make(true); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 237 |
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: