| Conditions | 4 |
| Paths | 4 |
| Total Lines | 58 |
| Code Lines | 51 |
| 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 |
||
| 34 | public function buildRRDGraphParams($input) { |
||
| 35 | $device = $this->getDevice(); |
||
| 36 | if (isset($input->id) && is_numeric($input->id)) { |
||
| 37 | $port_ids = explode(',', $input->id); |
||
| 38 | $ports = $device->ports()->whereIn('port_id', $port_ids)->get(); |
||
| 39 | } else { |
||
| 40 | $ports = $device->ports()->get(); |
||
| 41 | } |
||
| 42 | $headers = []; |
||
| 43 | $defs = " COMMENT:' Now Avg Max' COMMENT:' \\n' "; |
||
| 44 | |||
| 45 | foreach ($ports as $port) { |
||
| 46 | $port_id = $port->port_id; |
||
| 47 | $rrd_file = get_port_rrdfile_path($device, $port->port_id); |
||
| 48 | $defs .= " DEF:outoctets$port_id=$rrd_file:OUTOCTETS:AVERAGE \ |
||
| 49 | DEF:inoctets$port_id=$rrd_file:INOCTETS:AVERAGE \ |
||
| 50 | DEF:outoctets_max$port_id=$rrd_file:OUTOCTETS:MAX \ |
||
| 51 | DEF:inoctets_max$port_id=$rrd_file:INOCTETS:MAX \ |
||
| 52 | CDEF:octets$port_id=inoctets$port_id,outoctets$port_id,+ \ |
||
| 53 | CDEF:doutoctets$port_id=outoctets$port_id,-1,* \ |
||
| 54 | CDEF:outbits$port_id=outoctets$port_id,8,* \ |
||
| 55 | CDEF:outbits_max$port_id=outoctets_max$port_id,8,* \ |
||
| 56 | CDEF:doutoctets_max$port_id=outoctets_max$port_id,-1,* \ |
||
| 57 | CDEF:doutbits$port_id=doutoctets$port_id,8,* \ |
||
| 58 | CDEF:doutbits_max$port_id=doutoctets_max$port_id,8,* \ |
||
| 59 | CDEF:inbits$port_id=inoctets$port_id,8,* \ |
||
| 60 | CDEF:inbits_max$port_id=inoctets_max$port_id,8,* \ |
||
| 61 | VDEF:totin$port_id=inoctets$port_id,TOTAL \ |
||
| 62 | VDEF:totout$port_id=outoctets$port_id,TOTAL \ |
||
| 63 | VDEF:tot$port_id=octets$port_id,TOTAL COMMENT:' \\n' \ |
||
| 64 | VDEF:95thin$port_id=inbits$port_id,95,PERCENT \ |
||
| 65 | VDEF:95thout$port_id=outbits$port_id,95,PERCENT \ |
||
| 66 | CDEF:d95thoutn$port_id=doutbits$port_id,-1,* \ |
||
| 67 | VDEF:d95thoutn95$port_id=d95thoutn$port_id,95,PERCENT \ |
||
| 68 | CDEF:d95thoutn95n$port_id=doutbits$port_id,doutbits$port_id,-,d95thoutn95$port_id,-1,*,+ \ |
||
| 69 | VDEF:d95thout$port_id=d95thoutn95n$port_id,FIRST \ |
||
| 70 | AREA:inbits_max$port_id#D7FFC7: \ |
||
| 71 | AREA:inbits$port_id#90B040: \ |
||
| 72 | LINE:inbits$port_id#608720:'In " . str_pad($port['ifDescr'], 6) . "' \ |
||
| 73 | GPRINT:inbits$port_id:LAST:%6.2lf%s \ |
||
| 74 | GPRINT:inbits$port_id:AVERAGE:%6.2lf%s \ |
||
| 75 | GPRINT:inbits_max$port_id:MAX:%6.2lf%s \ |
||
| 76 | AREA:doutbits_max$port_id#E0E0FF: \ |
||
| 77 | AREA:doutbits$port_id#8080C0: COMMENT:' \\n' \ |
||
| 78 | LINE:doutbits$port_id#606090:'Out ' \ |
||
| 79 | GPRINT:outbits$port_id:LAST:%6.2lf%s \ |
||
| 80 | GPRINT:outbits$port_id:AVERAGE:%6.2lf%s \ |
||
| 81 | GPRINT:outbits_max$port_id:MAX:%6.2lf%s COMMENT:'\n' \ |
||
| 82 | LINE1:95thin$port_id#aa0000 \ |
||
| 83 | LINE1:d95thout$port_id#aa0000"; |
||
| 84 | } |
||
| 85 | |||
| 86 | return [ |
||
| 87 | 'headers' => $headers, |
||
| 88 | 'defs' => $defs, |
||
| 89 | ]; |
||
| 90 | |||
| 91 | } |
||
| 92 | |||
| 130 |
Classes in PHP are usually named in CamelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes
DatabaseProvider.