Conditions | 10 |
Paths | 6 |
Total Lines | 38 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
23 | public function open(string $database, string $schema = '') |
||
24 | { |
||
25 | $server = $this->driver->options('server'); |
||
26 | $options = $this->driver->options(); |
||
27 | $username = $options['username']; |
||
28 | $password = $options['password']; |
||
29 | $socket = null; |
||
30 | |||
31 | // Create the MySQLi client |
||
32 | $this->client = new MySQLi(); |
||
33 | |||
34 | mysqli_report(MYSQLI_REPORT_OFF); // stays between requests, not required since PHP 5.3.4 |
||
35 | list($host, $port) = explode(":", $server, 2); // part after : is used for port or socket |
||
36 | $ssl = $this->driver->options('ssl'); |
||
37 | if ($ssl) { |
||
38 | $this->client->ssl_set($ssl['key'], $ssl['cert'], $ssl['ca'], '', ''); |
||
39 | } |
||
40 | |||
41 | if (!@$this->client->real_connect( |
||
42 | ($server != "" ? $host : ini_get("mysqli.default_host")), |
||
43 | ($server . $username != "" ? $username : ini_get("mysqli.default_user")), |
||
44 | ($server . $username . $password != "" ? $password : ini_get("mysqli.default_pw")), |
||
45 | $database, |
||
46 | (is_numeric($port) ? intval($port) : intval(ini_get("mysqli.default_port"))), |
||
47 | (!is_numeric($port) ? $port : $socket), |
||
48 | ($ssl ? MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT : 0) // (not available before PHP 5.6.16) |
||
49 | )) { |
||
50 | return false; |
||
51 | } |
||
52 | |||
53 | $this->client->options(MYSQLI_OPT_LOCAL_INFILE, false); |
||
54 | if (($database)) { |
||
55 | $this->client->select_db($database); |
||
56 | } |
||
57 | // Available in MySQLi since PHP 5.0.5 |
||
58 | $this->setCharset($this->driver->charset()); |
||
59 | $this->query("SET sql_quote_show_create = 1, autocommit = 1"); |
||
60 | return true; |
||
61 | } |
||
150 |