Conditions | 10 |
Paths | 48 |
Total Lines | 34 |
Code Lines | 20 |
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 |
||
43 | public function connect($suppress_error = false) |
||
44 | { |
||
45 | $params = $this->getParams(); |
||
46 | |||
47 | $dsn = 'mysql:'; |
||
48 | if (isset($params['host']) && $params['host'] != '') { |
||
49 | $dsn .= 'host=' . $params['host'] . ';'; |
||
50 | } |
||
51 | if (isset($params['port'])) { |
||
52 | $dsn .= 'port=' . $params['port'] . ';'; |
||
53 | } |
||
54 | if (isset($params['charset'])) { |
||
55 | $dsn .= 'charset=' . $params['charset'] . ';'; |
||
56 | } |
||
57 | |||
58 | if (isset($params['socket']) && $params['socket'] != '') { |
||
59 | $dsn .= 'unix_socket=' . $params['socket'] . ';'; |
||
60 | } |
||
61 | |||
62 | try { |
||
63 | $con = new \Pdo($dsn); |
||
64 | } catch (\PDOException $exception) { |
||
65 | if (!$suppress_error && !$this->silence_connection_warning) { |
||
66 | trigger_error('connection error', E_USER_WARNING); |
||
67 | } |
||
68 | |||
69 | throw new ConnectionException($exception->getMessage()); |
||
70 | } |
||
71 | |||
72 | $this->connection = $con; |
||
73 | $this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
||
74 | |||
75 | return true; |
||
76 | } |
||
77 | |||
119 |