| Conditions | 21 |
| Paths | 76 |
| Total Lines | 61 |
| Code Lines | 55 |
| 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 | $gpus[] = make_gpu('nvidia', $x); |
||
| 75 | break; |
||
| 76 | case 'CAL': |
||
| 77 | $gpus[] = make_gpu('amd', $x); |
||
| 78 | break; |
||
| 79 | case 'INTEL': |
||
| 80 | $gpus[] = make_gpu('intel', $x); |
||
| 81 | break; |
||
| 82 | case 'ARM': |
||
| 83 | $gpus[] = make_gpu('arm', $x); |
||
| 84 | break; |
||
| 85 | case 'Microsoft': |
||
| 86 | break; |
||
| 87 | case 'apple_gpu': |
||
| 88 | case 'Apple': |
||
| 89 | $g = make_gpu('apple', $x); |
||
| 90 | $gpus[] = $g; |
||
| 91 | break; |
||
| 92 | case 'opencl_gpu': |
||
| 93 | if (stristr($x[1], 'apple')) { |
||
| 94 | break; |
||
| 95 | } |
||
| 96 | if (stristr($x[1], 'amd')) { |
||
| 97 | break; |
||
| 98 | } |
||
| 99 | $g = make_gpu('opencl', $x); |
||
| 100 | if ($g) $gpus[] = $g; |
||
| 101 | break; |
||
| 102 | case 'vbox': |
||
| 103 | $s->vbox = make_vbox($x); |
||
| 104 | break; |
||
| 105 | case 'docker': |
||
| 106 | $s->docker = make_docker($x); |
||
| 107 | break; |
||
| 108 | case 'dont_use_docker': |
||
| 109 | $config['dont_use_docker'] = true; |
||
| 110 | break; |
||
| 111 | case 'dont_use_wsl': |
||
| 112 | $config['dont_use_wsl'] = true; |
||
| 113 | break; |
||
| 114 | default: |
||
| 115 | echo "unrecognized: ".$x[0]."\n"; |
||
| 116 | continue; |
||
| 117 | } |
||
| 118 | } |
||
| 119 | if ($gpus) $s->gpus = $gpus; |
||
| 120 | if ($config) $s->config = $config; |
||
| 121 | return $s; |
||
| 122 | } |
||
| 155 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.