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 |
||
53 | public function connect($suppress_error = false) |
||
54 | { |
||
55 | $params = $this->getParams(); |
||
56 | |||
57 | $dsn = 'mysql:'; |
||
58 | if (isset($params['host']) && $params['host'] != '') { |
||
59 | $dsn .= 'host=' . $params['host'] . ';'; |
||
60 | } |
||
61 | if (isset($params['port'])) { |
||
62 | $dsn .= 'port=' . $params['port'] . ';'; |
||
63 | } |
||
64 | if (isset($params['charset'])) { |
||
65 | $dsn .= 'charset=' . $params['charset'] . ';'; |
||
66 | } |
||
67 | |||
68 | if (isset($params['socket']) && $params['socket'] != '') { |
||
69 | $dsn .= 'unix_socket=' . $params['socket'] . ';'; |
||
70 | } |
||
71 | |||
72 | try { |
||
73 | $con = new \Pdo($dsn); |
||
74 | } catch (\PDOException $exception) { |
||
75 | if (!$suppress_error && !$this->silence_connection_warning) { |
||
76 | trigger_error('connection error', E_USER_WARNING); |
||
77 | } |
||
78 | |||
79 | throw new ConnectionException($exception->getMessage()); |
||
80 | } |
||
81 | |||
82 | $this->connection = $con; |
||
83 | $this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
||
84 | |||
85 | return true; |
||
86 | } |
||
87 | |||
129 |