| Conditions | 12 |
| Paths | 49 |
| Total Lines | 62 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 156 |
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 |
||
| 57 | public static function groupOsimages($images, $ispSupported = false) |
||
| 58 | { |
||
| 59 | $softpacks = []; |
||
| 60 | $oses = []; |
||
| 61 | $vendors = []; |
||
| 62 | foreach ($images as $image) { |
||
| 63 | /** @var Osimage $image */ |
||
| 64 | $os = $image->os; |
||
| 65 | $name = $image->getFullOsName(); |
||
| 66 | $panel = $image->getPanelName(); |
||
| 67 | $system = $image->getFullOsName(''); |
||
| 68 | $softpack_name = $image->getSoftPackName(); |
||
| 69 | $softpack = $image->getSoftPack(); |
||
| 70 | |||
| 71 | if (!array_key_exists($system, $oses)) { |
||
| 72 | $vendors[$os]['name'] = $os; |
||
| 73 | $vendors[$os]['oses'][$system] = $name; |
||
| 74 | $oses[$system] = ['vendor' => $os, 'name' => $name]; |
||
| 75 | } |
||
| 76 | |||
| 77 | if ($panel !== 'isp' || ($panel === 'isp' && $ispSupported)) { |
||
| 78 | $data = [ |
||
| 79 | 'name' => $softpack_name, |
||
| 80 | 'description' => preg_replace('/^ISPmanager - /', '', $softpack['description']), |
||
| 81 | 'osimage' => $image->osimage, |
||
| 82 | ]; |
||
| 83 | |||
| 84 | if ($softpack['soft']) { |
||
| 85 | $html_desc = []; |
||
| 86 | foreach ($softpack['soft'] as $soft => $soft_info) { |
||
| 87 | $soft_info['description'] = preg_replace('/,([^\s])/', ', $1', $soft_info['description']); |
||
| 88 | |||
| 89 | $html_desc[] = "<b>{$soft_info['name']} {$soft_info['version']}</b>: <i>{$soft_info['description']}</i>"; |
||
| 90 | $data['soft'][$soft] = [ |
||
| 91 | 'name' => $soft_info['name'], |
||
| 92 | 'version' => $soft_info['version'], |
||
| 93 | 'description' => $soft_info['description'], |
||
| 94 | ]; |
||
| 95 | } |
||
| 96 | $data['html_desc'] = implode('<br />', $html_desc); |
||
| 97 | } |
||
| 98 | $oses[$system]['panel'][$panel]['softpack'][$softpack_name] = $data; |
||
| 99 | $softpacks[$panel][$softpack_name] = $data; |
||
| 100 | } else { |
||
| 101 | $oses[$system]['panel'][$panel] = false; |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | foreach ($oses as $system => $os) { |
||
| 106 | $delete = true; |
||
| 107 | foreach ($os['panel'] as $panel => $info) { |
||
| 108 | if ($info !== false) { |
||
| 109 | $delete = false; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | if ($delete) { |
||
| 113 | unset($vendors[$os['vendor']]['oses'][$system]); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | return compact('vendors', 'oses', 'softpacks'); |
||
| 118 | } |
||
| 119 | |||
| 220 |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.