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 |
||
23 | class SoftLayer implements Simulator |
||
24 | { |
||
25 | /** |
||
26 | * SoftLayer user |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $user; |
||
31 | |||
32 | /** |
||
33 | * SoftLayer secret |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $secret; |
||
38 | |||
39 | /** |
||
40 | * SoftLayer container |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $container; |
||
45 | |||
46 | /** |
||
47 | * SoftLayer host |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $host; |
||
52 | |||
53 | /** |
||
54 | * SoftLayer remote path |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $path; |
||
59 | |||
60 | /** |
||
61 | * (non-PHPDoc) |
||
62 | * |
||
63 | * @see \phpbu\App\Backup\Sync::setup() |
||
64 | * @param array $config |
||
65 | * @throws \phpbu\App\Backup\Sync\Exception |
||
66 | */ |
||
67 | 7 | public function setup(array $config) |
|
87 | |||
88 | /** |
||
89 | * (non-PHPDoc) |
||
90 | * |
||
91 | * @see \phpbu\App\Backup\Sync::sync() |
||
92 | * @param \phpbu\App\backup\Target $target |
||
93 | * @param \phpbu\App\Result $result |
||
94 | * @throws \phpbu\App\Backup\Sync\Exception |
||
95 | */ |
||
96 | public function sync(Target $target, Result $result) |
||
120 | |||
121 | /** |
||
122 | * Simulate the sync execution. |
||
123 | * |
||
124 | * @param \phpbu\App\Backup\Target $target |
||
125 | * @param \phpbu\App\Result $result |
||
126 | */ |
||
127 | 1 | public function simulate(Target $target, Result $result) |
|
138 | |||
139 | /** |
||
140 | * Execute the remote clean up if needed |
||
141 | * |
||
142 | * @param \phpbu\App\Backup\Target $target |
||
143 | * @param \phpbu\App\Result $result |
||
144 | */ |
||
145 | public function cleanup(Target $target, Result $result) |
||
149 | } |
||
150 |