Conditions | 9 |
Paths | 60 |
Total Lines | 60 |
Code Lines | 28 |
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 |
||
117 | public function getDriver(&$description) |
||
118 | { |
||
119 | $version = null; |
||
120 | |||
121 | if ($this->conn->_connectionID) { |
||
122 | $v = \pg_version($this->conn->_connectionID); |
||
123 | |||
124 | //\PhpConsole\Handler::getInstance()->debug($v, 'pg_version'); |
||
125 | |||
126 | if (isset($v['server'])) { |
||
127 | $version = $v['server']; |
||
128 | } |
||
129 | } |
||
130 | // If we didn't manage to get the version without a query, query... |
||
131 | if (!isset($version)) { |
||
132 | $adodb = new ADOdbBase($this->conn, $this->container, $this->server_info); |
||
133 | |||
134 | $sql = 'SELECT VERSION() AS version'; |
||
135 | $field = $adodb->selectField($sql, 'version'); |
||
136 | |||
137 | // Check the platform, if it's mingw, set it |
||
138 | if (\preg_match('/ mingw /i', $field)) { |
||
139 | $this->platform = 'MINGW'; |
||
140 | } |
||
141 | |||
142 | $params = \explode(' ', $field); |
||
143 | |||
144 | if (!isset($params[1])) { |
||
145 | return null; |
||
146 | } |
||
147 | |||
148 | $version = $params[1]; // eg. 8.4.4 |
||
149 | } |
||
150 | |||
151 | $description = \sprintf( |
||
152 | 'PostgreSQL %s', |
||
153 | $version |
||
154 | ); |
||
155 | |||
156 | $version_parts = \explode('.', $version); |
||
157 | |||
158 | if ((int) (10 <= $version_parts[0])) { |
||
159 | $major_version = $version_parts[0]; |
||
160 | } else { |
||
161 | $major_version = \implode('.', [$version_parts[0], $version_parts[1]]); |
||
162 | } |
||
163 | |||
164 | //$this->prtrace(['pg_version' => pg_version($this->conn->_connectionID), 'version' => $version, 'major_version' => $major_version]); |
||
165 | // Detect version and choose appropriate database driver |
||
166 | if (\array_key_exists($major_version, $this->version_dictionary)) { |
||
167 | return $this->version_dictionary[$major_version]; |
||
168 | } |
||
169 | |||
170 | // if major version is less than 9 return null, we don't support it |
||
171 | if (9 > (int) \mb_substr($version, 0, 1)) { |
||
172 | return null; |
||
173 | } |
||
174 | |||
175 | // If unknown version, then default to latest driver |
||
176 | return 'Postgres'; |
||
177 | } |
||
189 |