| Conditions | 8 |
| Paths | 40 |
| Total Lines | 55 |
| Code Lines | 24 |
| 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 |
||
| 113 | public function getDriver(&$description) |
||
| 114 | { |
||
| 115 | $v = pg_version($this->conn->_connectionID); |
||
| 116 | |||
| 117 | //\PhpConsole\Handler::getInstance()->debug($v, 'pg_version'); |
||
| 118 | |||
| 119 | if (isset($v['server'])) { |
||
| 120 | $version = $v['server']; |
||
| 121 | } |
||
| 122 | |||
| 123 | // If we didn't manage to get the version without a query, query... |
||
| 124 | if (!isset($version)) { |
||
| 125 | $adodb = new ADOdbBase($this->conn, $this->container, $this->server_info); |
||
| 126 | |||
| 127 | $sql = 'SELECT VERSION() AS version'; |
||
| 128 | $field = $adodb->selectField($sql, 'version'); |
||
| 129 | |||
| 130 | // Check the platform, if it's mingw, set it |
||
| 131 | if (preg_match('/ mingw /i', $field)) { |
||
| 132 | $this->platform = 'MINGW'; |
||
| 133 | } |
||
| 134 | |||
| 135 | $params = explode(' ', $field); |
||
| 136 | if (!isset($params[1])) { |
||
| 137 | return -3; |
||
| 138 | } |
||
| 139 | |||
| 140 | $version = $params[1]; // eg. 8.4.4 |
||
| 141 | } |
||
| 142 | |||
| 143 | $description = "PostgreSQL {$version}"; |
||
| 144 | |||
| 145 | $version_parts = explode('.', $version); |
||
| 146 | |||
| 147 | if ($version_parts[0] == '10') { |
||
| 148 | $major_version = '10'; |
||
| 149 | } else { |
||
| 150 | $major_version = implode('.', [$version_parts[0], $version_parts[1]]); |
||
| 151 | } |
||
| 152 | |||
| 153 | //$this->prtrace(['pg_version' => pg_version($this->conn->_connectionID), 'version' => $version, 'major_version' => $major_version]); |
||
| 154 | // Detect version and choose appropriate database driver |
||
| 155 | if (array_key_exists($major_version, $this->version_dictionary)) { |
||
| 156 | return $this->version_dictionary[$major_version]; |
||
| 157 | } |
||
| 158 | |||
| 159 | /* All <7.4 versions are not supported */ |
||
| 160 | // if major version is 7 or less and wasn't cought in the |
||
| 161 | // switch/case block, we have an unsupported version. |
||
| 162 | if ((int) substr($version, 0, 1) < 8) { |
||
| 163 | return null; |
||
| 164 | } |
||
| 165 | |||
| 166 | // If unknown version, then default to latest driver |
||
| 167 | return 'Postgres'; |
||
| 168 | } |
||
| 180 |