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 |
||
| 15 | class Statement implements IteratorAggregate, DriverStatement |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | private $sql; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var \Doctrine\DBAL\Statement |
||
| 24 | */ |
||
| 25 | private $stmt; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var Connection |
||
| 29 | */ |
||
| 30 | private $conn; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var array binding values |
||
| 34 | */ |
||
| 35 | private $values = []; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var array binding parameters |
||
| 39 | */ |
||
| 40 | private $params = []; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param string $sql |
||
| 44 | * @param Connection $conn |
||
| 45 | */ |
||
| 46 | public function __construct($sql, Connection $conn) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * {@inheritdoc} |
||
| 56 | */ |
||
| 57 | private function createStatement() |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @param null $params |
||
| 72 | * @return bool|null |
||
| 73 | * @throws DBALException |
||
| 74 | */ |
||
| 75 | public function execute($params = null) |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @param mixed $param |
||
| 103 | * @param mixed $value |
||
| 104 | * @param null $type |
||
| 105 | * @return bool |
||
| 106 | */ |
||
| 107 | public function bindValue($param, $value, $type = null) |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @param mixed $column |
||
| 116 | * @param mixed $variable |
||
| 117 | * @param int|null $type |
||
| 118 | * @param null $length |
||
| 119 | * @return bool |
||
| 120 | */ |
||
| 121 | public function bindParam($column, &$variable, $type = PDO::PARAM_STR, $length = null) |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @return bool |
||
| 130 | */ |
||
| 131 | public function closeCursor() |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @return int |
||
| 138 | */ |
||
| 139 | public function columnCount() |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @return string |
||
| 146 | */ |
||
| 147 | public function errorCode() |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @return array |
||
| 154 | */ |
||
| 155 | public function errorInfo() |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @param int|null $fetchStyle |
||
| 162 | * @return mixed |
||
| 163 | */ |
||
| 164 | public function fetch($fetchStyle = PDO::FETCH_BOTH) |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @param int|null $fetchStyle |
||
| 171 | * @return array |
||
| 172 | */ |
||
| 173 | public function fetchAll($fetchStyle = PDO::FETCH_BOTH) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @param int $columnIndex |
||
| 180 | * @return mixed |
||
| 181 | */ |
||
| 182 | public function fetchColumn($columnIndex = 0) |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @return int |
||
| 189 | */ |
||
| 190 | public function rowCount() |
||
| 194 | |||
| 195 | /** |
||
| 196 | * {@inheritdoc} |
||
| 197 | */ |
||
| 198 | public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Required by interface IteratorAggregate. |
||
| 217 | * |
||
| 218 | * {@inheritdoc} |
||
| 219 | */ |
||
| 220 | public function getIterator() |
||
| 224 | } |
||
| 225 |
This method has been deprecated.