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