Conditions | 5 |
Paths | 12 |
Total Lines | 67 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
44 | public function getResult($config = null): array |
||
45 | { |
||
46 | $conn = DB::get_conn(); |
||
47 | // Assumes database class is like "MySQLDatabase" or "MSSQLDatabase" (eg. suffixed with "Database") |
||
48 | $dbType = substr(strrchr(get_class($conn), '\\'), 1, -8); |
||
49 | $dbVersion = $conn->getVersion(); |
||
50 | $databaseName = $conn->getSelectedDatabase(); |
||
51 | |||
52 | $info = [ |
||
53 | 'php' => [ |
||
54 | 'label' => _t(__CLASS__ . '.phpversion', 'PHP version'), |
||
55 | 'value' => phpversion() |
||
56 | ], |
||
57 | 'hostip' => [ |
||
58 | 'label' => _t(__CLASS__ . '.hostip', 'IP address'), |
||
59 | 'value' => $_SERVER['SERVER_ADDR'] |
||
60 | ], |
||
61 | 'memorylimit' => [ |
||
62 | 'label' => _t(__CLASS__ . '.memorylimit', 'Memory limit'), |
||
63 | 'value' => ini_get('memory_limit') |
||
64 | ], |
||
65 | 'uploadlimit' => [ |
||
66 | 'label' => _t(__CLASS__ . '.uploadlimit', 'Upload limit'), |
||
67 | 'value' => ini_get('upload_max_filesize') |
||
68 | ], |
||
69 | 'maxscripttime' => [ |
||
70 | 'label' => _t(__CLASS__ . '.scripttime', 'Script execution time limit'), |
||
71 | 'value' => ini_get('max_execution_time') |
||
72 | ], |
||
73 | 'dbengine' => [ |
||
74 | 'label' => _t(__CLASS__ . '.dbengine', 'Database engine'), |
||
75 | 'value' => $dbType |
||
76 | ], |
||
77 | 'dbversion' => [ |
||
78 | 'label' => _t(__CLASS__ . '.dbversion', 'Database version'), |
||
79 | 'value' => $dbVersion |
||
80 | ], |
||
81 | 'databasename' => [ |
||
82 | 'label' => _t(__CLASS__ . '.dbname', 'Database name'), |
||
83 | 'value' => $databaseName |
||
84 | ] |
||
85 | ]; |
||
86 | |||
87 | $envVars = $this->config()->get('env_variables'); |
||
88 | $env = []; |
||
89 | foreach ($envVars as $envVar) { |
||
90 | $envData = Environment::getEnv($envVar); |
||
91 | $value = ($envData) ? $envData : _t(__CLASS__ . '.EnvNotSet', 'Not set'); |
||
92 | $env[$envVar] = $value; |
||
93 | } |
||
94 | |||
95 | if (count($env) > 0) { |
||
96 | $info['environment'] = [ |
||
97 | 'label' => _t(__CLASS__ . '.environment', 'Environment variables'), |
||
98 | 'value' => $env |
||
99 | ]; |
||
100 | } |
||
101 | |||
102 | if ($this->config()->get('discover_public_ip') === true) { |
||
103 | $info['publicip'] = [ |
||
104 | 'label' => _t(__CLASS__ . '.publicip', 'Public IP address'), |
||
105 | 'value' => $this->getPublicIP() |
||
106 | ]; |
||
107 | } |
||
108 | |||
109 | return [ |
||
110 | $this->getClientName() => $info |
||
111 | ]; |
||
168 |