Conditions | 10 |
Paths | 9 |
Total Lines | 42 |
Code Lines | 21 |
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 |
||
56 | public function __construct($server_info, $database, $container, $fetchMode = ADODB_FETCH_ASSOC) |
||
57 | { |
||
58 | $host = $server_info['host']; |
||
59 | $port = $server_info['port']; |
||
60 | $sslmode = $server_info['sslmode']; |
||
61 | $user = $server_info['username']; |
||
62 | $password = $server_info['password']; |
||
63 | |||
64 | $this->server_info = $server_info; |
||
65 | |||
66 | $this->container = $container; |
||
67 | |||
68 | $this->conn = ADONewConnection('postgres9'); |
||
69 | //$this->conn->debug = true; |
||
70 | $this->conn->setFetchMode($fetchMode); |
||
71 | |||
72 | // Ignore host if null |
||
73 | if ($host === null || $host == '') { |
||
74 | if ($port !== null && $port != '') { |
||
75 | $pghost = ':'.$port; |
||
76 | } else { |
||
77 | $pghost = ''; |
||
78 | } |
||
79 | } else { |
||
80 | $pghost = "{$host}:{$port}"; |
||
81 | } |
||
82 | |||
83 | // Add sslmode to $pghost as needed |
||
84 | if (($sslmode == 'disable') || ($sslmode == 'allow') || ($sslmode == 'prefer') || ($sslmode == 'require')) { |
||
85 | $pghost .= ':'.$sslmode; |
||
86 | } elseif ($sslmode == 'legacy') { |
||
87 | $pghost .= ' requiressl=1'; |
||
88 | } |
||
89 | |||
90 | /*try { |
||
91 | $this->_connection_result = $this->conn->connect($pghost, $user, $password, $database); |
||
92 | $this->prtrace(['_connection_result' => $this->_connection_result, 'conn' => $this->conn]); |
||
93 | } catch (\PHPPgAdmin\ADOdbException $e) { |
||
94 | $this->prtrace(['message' => $e->getMessage(), 'trace' => $e->getTraceAsString()]); |
||
95 | */ |
||
96 | |||
97 | $this->conn->connect($pghost, $user, $password, $database); |
||
98 | } |
||
180 |