| Conditions | 22 |
| Paths | 80 |
| Total Lines | 58 |
| Code Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 61 | function to_struct($p) { |
||
| 62 | $s = new StdClass; |
||
| 63 | $gpus = []; |
||
| 64 | $config = []; |
||
| 65 | foreach ($p as $x) { |
||
| 66 | switch ($x[0]) { |
||
| 67 | case 'BOINC': |
||
| 68 | $s->client_version = $x[1]; |
||
| 69 | if (!empty($x[2])) { |
||
| 70 | $s->client_brand = $x[2]; |
||
| 71 | } |
||
| 72 | break; |
||
| 73 | case 'CUDA': |
||
| 74 | $g = make_gpu('nvidia', $x); |
||
| 75 | if ($g) $gpus[] = $g; |
||
| 76 | break; |
||
| 77 | case 'CAL': |
||
| 78 | $g = make_gpu('amd', $x); |
||
| 79 | if ($g) $gpus[] = $g; |
||
| 80 | break; |
||
| 81 | case 'INTEL': |
||
| 82 | $g = make_gpu('intel', $x); |
||
| 83 | if ($g) $gpus[] = $g; |
||
| 84 | break; |
||
| 85 | case 'apple_gpu': |
||
| 86 | $g = make_gpu('apple', $x); |
||
| 87 | if ($g) $gpus[] = $g; |
||
| 88 | break; |
||
| 89 | case 'opencl_gpu': |
||
| 90 | if (stristr($x[1], 'apple')) { |
||
| 91 | break; |
||
| 92 | } |
||
| 93 | if (stristr($x[1], 'amd')) { |
||
| 94 | break; |
||
| 95 | } |
||
| 96 | $g = make_gpu('opencl', $x); |
||
| 97 | if ($g) $gpus[] = $g; |
||
| 98 | break; |
||
| 99 | case 'vbox': |
||
| 100 | $s->vbox = make_vbox($x); |
||
| 101 | break; |
||
| 102 | case 'docker': |
||
| 103 | $s->docker = make_docker($x); |
||
| 104 | break; |
||
| 105 | case 'dont_use_docker': |
||
| 106 | $config['dont_use_docker'] = true; |
||
| 107 | break; |
||
| 108 | case 'dont_use_wsl': |
||
| 109 | $config['dont_use_wsl'] = true; |
||
| 110 | break; |
||
| 111 | default: |
||
|
|
|||
| 112 | echo "unrecognized: ".$x[0]."\n"; |
||
| 113 | continue; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | if ($gpus) $s->gpus = $gpus; |
||
| 117 | if ($config) $s->config = $config; |
||
| 118 | return $s; |
||
| 119 | } |
||
| 139 |