Conditions | 10 |
Paths | 80 |
Total Lines | 32 |
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 |
||
54 | public function pdo_connect() { |
||
55 | |||
56 | $db_port = defined('DB_PORT') && DB_PORT ? ';port='.DB_PORT : ''; |
||
57 | $db_host = defined('DB_HOST') && DB_HOST ? ';host='.DB_HOST : ''; |
||
58 | |||
59 | try { |
||
60 | $pdo = new PDO(DB_TYPE.':dbname='.DB_NAME.$db_host.$db_port, |
||
61 | DB_USER, |
||
62 | DB_PASS); |
||
63 | } catch (Exception $e) { |
||
64 | print "<pre>Exception while creating PDO object:".$e->getMessage()."</pre>"; |
||
65 | exit(101); |
||
66 | } |
||
67 | |||
68 | $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
||
69 | |||
70 | if (DB_TYPE == "pgsql") { |
||
71 | |||
72 | $pdo->query("set client_encoding = 'UTF-8'"); |
||
73 | $pdo->query("set datestyle = 'ISO, european'"); |
||
74 | $pdo->query("set TIME ZONE 0"); |
||
75 | $pdo->query("set cpu_tuple_cost = 0.5"); |
||
76 | |||
77 | } else if (DB_TYPE == "mysql") { |
||
78 | $pdo->query("SET time_zone = '+0:0'"); |
||
79 | |||
80 | if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { |
||
81 | $pdo->query("SET NAMES ".MYSQL_CHARSET); |
||
82 | } |
||
83 | } |
||
84 | |||
85 | return $pdo; |
||
86 | } |
||
120 |