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 |
||
| 7 | class AutoCommitUpdate implements DeferrableUpdate { |
||
| 8 | /** @var IDatabase */ |
||
| 9 | private $dbw; |
||
| 10 | /** @var string */ |
||
| 11 | private $fname; |
||
| 12 | /** @var callable */ |
||
| 13 | private $callback; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @param IDatabase $dbw |
||
| 17 | * @param string $fname Caller name (usually __METHOD__) |
||
| 18 | * @param callable $callback Callback that takes (IDatabase, method name string) |
||
| 19 | */ |
||
| 20 | View Code Duplication | public function __construct( IDatabase $dbw, $fname, callable $callback ) { |
|
| 29 | |||
| 30 | public function doUpdate() { |
||
| 50 | |||
| 51 | public function cancelOnRollback( $trigger ) { |
||
| 56 | } |
||
| 57 |