Conditions | 14 |
Paths | 192 |
Total Lines | 65 |
Code Lines | 41 |
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 |
||
25 | public function getServers($recordset = false, $group = false) |
||
26 | { |
||
27 | $logins = isset($_SESSION['webdbLogin']) && is_array($_SESSION['webdbLogin']) ? $_SESSION['webdbLogin'] : []; |
||
28 | $srvs = []; |
||
29 | |||
30 | if (($group !== false) && ($group !== 'all')) { |
||
31 | if (isset($this->conf['srv_groups'][$group]['servers'])) { |
||
32 | $group = array_fill_keys(explode(',', preg_replace( |
||
1 ignored issue
–
show
|
|||
33 | '/\s/', |
||
34 | '', |
||
35 | $this->conf['srv_groups'][$group]['servers'] |
||
36 | )), 1); |
||
1 ignored issue
–
show
|
|||
37 | } else { |
||
38 | $group = ''; |
||
39 | } |
||
40 | } |
||
41 | |||
42 | foreach ($this->conf['servers'] as $idx => $info) { |
||
43 | $server_id = $info['host'] . ':' . $info['port'] . ':' . $info['sslmode']; |
||
1 ignored issue
–
show
|
|||
44 | if ($group === false || isset($group[$idx]) || ($group === 'all')) { |
||
45 | $server_id = $info['host'] . ':' . $info['port'] . ':' . $info['sslmode']; |
||
46 | $server_sha = sha1($server_id); |
||
47 | |||
48 | if (isset($logins[$server_sha])) { |
||
49 | $srvs[$server_sha] = $logins[$server_sha]; |
||
50 | } else if (isset($logins[$server_id])) { |
||
51 | $srvs[$server_sha] = $logins[$server_id]; |
||
52 | } else { |
||
53 | $srvs[$server_sha] = $info; |
||
54 | } |
||
55 | |||
56 | $srvs[$server_sha]['id'] = $server_id; |
||
57 | $srvs[$server_sha]['sha'] = $server_sha; |
||
58 | $srvs[$server_sha]['action'] = Decorator::url( |
||
59 | '/redirect/server', |
||
60 | [ |
||
61 | 'server' => Decorator::field('sha'), |
||
62 | ] |
||
63 | ); |
||
64 | if (isset($srvs[$server_sha]['username'])) { |
||
65 | $srvs[$server_sha]['icon'] = 'Server'; |
||
66 | $srvs[$server_sha]['branch'] = Decorator::url( |
||
67 | '/src/views/alldb', |
||
68 | [ |
||
69 | 'action' => 'tree', |
||
70 | 'subject' => 'server', |
||
71 | 'server' => Decorator::field('sha'), |
||
72 | ] |
||
73 | ); |
||
74 | } else { |
||
75 | $srvs[$server_sha]['icon'] = 'DisconnectedServer'; |
||
76 | $srvs[$server_sha]['branch'] = false; |
||
77 | } |
||
78 | } |
||
79 | } |
||
80 | |||
81 | uasort($srvs, function ($a, $b) { |
||
1 ignored issue
–
show
|
|||
82 | return strcmp($a['desc'], $b['desc']); |
||
83 | }); |
||
1 ignored issue
–
show
|
|||
84 | |||
85 | if ($recordset) { |
||
86 | return new \PHPPgAdmin\ArrayRecordSet($srvs); |
||
87 | } |
||
88 | |||
89 | return $srvs; |
||
90 | } |
||
178 |