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 AtomicSectionUpdate implements DeferrableUpdate, DeferrableCallback { |
||
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 |
||
19 | * @see IDatabase::doAtomicSection() |
||
20 | */ |
||
21 | View Code Duplication | public function __construct( IDatabase $dbw, $fname, callable $callback ) { |
|
30 | |||
31 | public function doUpdate() { |
||
36 | |||
37 | public function cancelOnRollback( $trigger ) { |
||
42 | |||
43 | public function getOrigin() { |
||
46 | } |
||
47 |