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 SQLServerQuery extends Query |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * The SQLServerConnector object that created this result set. |
||
20 | * |
||
21 | * @var SQLServerConnector |
||
22 | */ |
||
23 | protected $connector; |
||
24 | |||
25 | /** |
||
26 | * The internal MSSQL handle that points to the result set. |
||
27 | * |
||
28 | * @var resource |
||
29 | */ |
||
30 | protected $handle; |
||
31 | |||
32 | /** |
||
33 | * Hook the result-set given into a Query class, suitable for use by sapphire. |
||
34 | * @param SQLServerConnector $connector The database object that created this query. |
||
35 | * @param resource $handle the internal mssql handle that is points to the resultset. |
||
36 | */ |
||
37 | public function __construct(SQLServerConnector $connector, $handle) |
||
42 | |||
43 | public function __destruct() |
||
49 | |||
50 | public function numRecords() |
||
63 | |||
64 | View Code Duplication | public function nextRecord() |
|
76 | |||
77 | View Code Duplication | public function seek($row) |
|
89 | } |
||
90 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.