Conditions | 11 |
Paths | 18 |
Total Lines | 44 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
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 |
||
57 | public function __construct($server_info, $database, $container, $fetchMode = \ADODB_FETCH_ASSOC) |
||
58 | { |
||
59 | $host = $server_info['host']; |
||
60 | $port = $server_info['port']; |
||
61 | $sslmode = $server_info['sslmode']; |
||
62 | $user = $server_info['username']; |
||
63 | $password = $server_info['password']; |
||
64 | |||
65 | $this->server_info = $server_info; |
||
66 | |||
67 | $this->container = $container; |
||
68 | |||
69 | $this->conn = \ADONewConnection('postgres9'); |
||
70 | //$this->conn->debug = true; |
||
71 | $this->conn->setFetchMode($fetchMode); |
||
72 | |||
73 | // Ignore host if null |
||
74 | if (null === $host || '' === $host) { |
||
75 | if (null !== $port && '' !== $port) { |
||
76 | $pghost = ':' . $port; |
||
77 | } else { |
||
78 | $pghost = ''; |
||
79 | } |
||
80 | } else { |
||
81 | $pghost = \sprintf( |
||
82 | '%s:%s', |
||
83 | $host, |
||
84 | $port |
||
85 | ); |
||
86 | } |
||
87 | |||
88 | // Add sslmode to $pghost as needed |
||
89 | if (('disable' === $sslmode) || ('allow' === $sslmode) || ('prefer' === $sslmode) || ('require' === $sslmode)) { |
||
90 | $pghost .= ':' . $sslmode; |
||
91 | } elseif ('legacy' === $sslmode) { |
||
92 | $pghost .= ' requiressl=1'; |
||
93 | } |
||
94 | |||
95 | try { |
||
96 | $this->conn->connect($pghost, $user, $password, $database); |
||
97 | //$this->prtrace($this->conn); |
||
98 | } catch (Exception $e) { |
||
99 | dump($e); |
||
100 | $this->prtrace($e->getMessage(), $e->getTrace()); |
||
101 | } |
||
189 |