Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
33 | class Driver extends DriverAbstract |
||
34 | { |
||
35 | /** |
||
36 | * the connection link |
||
37 | * |
||
38 | * @var \PDO |
||
39 | * @access protected |
||
40 | */ |
||
41 | protected $link; |
||
42 | |||
43 | /** |
||
44 | * Default PDO attributes |
||
45 | * |
||
46 | * @var array |
||
47 | * @access protected |
||
48 | */ |
||
49 | protected $attributes = [ |
||
50 | 'PDO::ATTR_ERRMODE' => \PDO::ERRMODE_SILENT, |
||
51 | 'PDO::ATTR_CASE' => \PDO::CASE_NATURAL, |
||
52 | 'PDO::ATTR_ORACLE_NULLS' => \PDO::NULL_NATURAL, |
||
53 | 'PDO::ATTR_DEFAULT_FETCH_MODE' => \PDO::FETCH_ASSOC, |
||
54 | 'PDO::ATTR_EMULATE_PREPARES' => false, |
||
55 | ]; |
||
56 | |||
57 | /** |
||
58 | * Driver constructor |
||
59 | * |
||
60 | * @param array $connectInfo |
||
61 | * @param StatementInterface $statementPrototype |
||
62 | * @throws InvalidArgumentException if link type not right |
||
63 | * @throws LogicException driver specific extension not loaded |
||
64 | * @access public |
||
65 | */ |
||
66 | public function __construct( |
||
75 | |||
76 | /** |
||
77 | * {@inheritDoc} |
||
78 | */ |
||
79 | protected function extensionLoaded()/*# : bool */ |
||
83 | |||
84 | /** |
||
85 | * {@inheritDoc} |
||
86 | */ |
||
87 | protected function realLastId($name) |
||
91 | |||
92 | /** |
||
93 | * {@inheritDoc} |
||
94 | */ |
||
95 | protected function realQuote( |
||
101 | |||
102 | /** |
||
103 | * {@inheritDoc} |
||
104 | */ |
||
105 | protected function realConnect(array $parameters) |
||
115 | |||
116 | /** |
||
117 | * Disconnect the \PDO link |
||
118 | * |
||
119 | * {@inheritDoc} |
||
120 | */ |
||
121 | protected function realDisconnect() |
||
124 | |||
125 | /** |
||
126 | * {@inheritDoc} |
||
127 | */ |
||
128 | protected function realPing()/*# : bool */ |
||
136 | |||
137 | /** |
||
138 | * {@inheritDoc} |
||
139 | */ |
||
140 | View Code Duplication | protected function realSetAttribute(/*# string */ $attribute, $value) |
|
150 | |||
151 | /** |
||
152 | * {@inheritDoc} |
||
153 | */ |
||
154 | View Code Duplication | protected function realGetAttribute(/*# string */ $attribute) |
|
163 | |||
164 | /** |
||
165 | * {@inheritDoc} |
||
166 | */ |
||
167 | protected function realBegin() |
||
172 | |||
173 | /** |
||
174 | * {@inheritDoc} |
||
175 | */ |
||
176 | protected function realCommit() |
||
181 | |||
182 | /** |
||
183 | * {@inheritDoc} |
||
184 | */ |
||
185 | protected function realRollback() |
||
190 | |||
191 | /** |
||
192 | * Is attribute defined ? |
||
193 | * |
||
194 | * @param string $attribute |
||
195 | * @throws LogicException |
||
196 | * @access protected |
||
197 | */ |
||
198 | protected function checkAttribute(/*# string */ $attribute) |
||
207 | } |
||
208 |