Conditions | 13 |
Paths | 768 |
Total Lines | 48 |
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 |
||
75 | private function _constructPdoDsn(array $params) |
||
76 | { |
||
77 | $dsn = 'pgsql:'; |
||
78 | |||
79 | if (isset($params['host']) && $params['host'] !== '') { |
||
80 | $dsn .= 'host=' . $params['host'] . ';'; |
||
81 | } |
||
82 | |||
83 | if (isset($params['port']) && $params['port'] !== '') { |
||
84 | $dsn .= 'port=' . $params['port'] . ';'; |
||
85 | } |
||
86 | |||
87 | if (isset($params['dbname'])) { |
||
88 | $dsn .= 'dbname=' . $params['dbname'] . ';'; |
||
89 | } elseif (isset($params['default_dbname'])) { |
||
90 | $dsn .= 'dbname=' . $params['default_dbname'] . ';'; |
||
91 | } else { |
||
92 | // Used for temporary connections to allow operations like dropping the database currently connected to. |
||
93 | // Connecting without an explicit database does not work, therefore "postgres" database is used |
||
94 | // as it is mostly present in every server setup. |
||
95 | $dsn .= 'dbname=postgres;'; |
||
96 | } |
||
97 | |||
98 | if (isset($params['sslmode'])) { |
||
99 | $dsn .= 'sslmode=' . $params['sslmode'] . ';'; |
||
100 | } |
||
101 | |||
102 | if (isset($params['sslrootcert'])) { |
||
103 | $dsn .= 'sslrootcert=' . $params['sslrootcert'] . ';'; |
||
104 | } |
||
105 | |||
106 | if (isset($params['sslcert'])) { |
||
107 | $dsn .= 'sslcert=' . $params['sslcert'] . ';'; |
||
108 | } |
||
109 | |||
110 | if (isset($params['sslkey'])) { |
||
111 | $dsn .= 'sslkey=' . $params['sslkey'] . ';'; |
||
112 | } |
||
113 | |||
114 | if (isset($params['sslcrl'])) { |
||
115 | $dsn .= 'sslcrl=' . $params['sslcrl'] . ';'; |
||
116 | } |
||
117 | |||
118 | if (isset($params['application_name'])) { |
||
119 | $dsn .= 'application_name=' . $params['application_name'] . ';'; |
||
120 | } |
||
121 | |||
122 | return $dsn; |
||
123 | } |
||
135 |