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 |
||
| 8 | class StepRegistration |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var string |
||
| 12 | */ |
||
| 13 | private $stepId; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | private $stepFqcn; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var callable|null |
||
| 22 | */ |
||
| 23 | private $factory; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var null|string |
||
| 27 | */ |
||
| 28 | private $description; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var StepRegistrationDependency[] |
||
| 32 | */ |
||
| 33 | private $befores = []; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var StepRegistrationDependency[] |
||
| 37 | */ |
||
| 38 | private $afters = []; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param string $stepId |
||
| 42 | * @param string $stepFqcn |
||
| 43 | * @param callable|null $factory |
||
| 44 | * @param string|null $description |
||
| 45 | */ |
||
| 46 | 32 | View Code Duplication | public function __construct($stepId, $stepFqcn, callable $factory = null, $description = null) |
| 56 | |||
| 57 | /** |
||
| 58 | * @param StepReplacement $replacement |
||
| 59 | */ |
||
| 60 | 1 | public function replaceWith(StepReplacement $replacement) |
|
| 66 | |||
| 67 | /** |
||
| 68 | * @param BuilderInterface $builder |
||
| 69 | */ |
||
| 70 | 2 | public function registerInBuilder(BuilderInterface $builder) |
|
| 76 | |||
| 77 | /** |
||
| 78 | * @return string |
||
| 79 | */ |
||
| 80 | 17 | public function getStepId() |
|
| 84 | |||
| 85 | /** |
||
| 86 | * @return string |
||
| 87 | */ |
||
| 88 | 11 | public function getStepFqcn() |
|
| 92 | |||
| 93 | /** |
||
| 94 | * @return callable|null |
||
| 95 | */ |
||
| 96 | 2 | public function getFactory() |
|
| 100 | |||
| 101 | /** |
||
| 102 | * @return null|string |
||
| 103 | */ |
||
| 104 | 2 | public function getDescription() |
|
| 108 | |||
| 109 | /** |
||
| 110 | * @return StepRegistrationDependency[] |
||
| 111 | */ |
||
| 112 | 14 | public function getBefores() |
|
| 116 | |||
| 117 | /** |
||
| 118 | * @return StepRegistrationDependency[] |
||
| 119 | */ |
||
| 120 | 13 | public function getAfters() |
|
| 124 | |||
| 125 | /** |
||
| 126 | * @param string $id |
||
| 127 | */ |
||
| 128 | 1 | public function insertBeforeIfExists($id) |
|
| 133 | |||
| 134 | /** |
||
| 135 | * @param string $id |
||
| 136 | */ |
||
| 137 | 5 | public function insertBefore($id) |
|
| 142 | |||
| 143 | /** |
||
| 144 | * @param string $id |
||
| 145 | */ |
||
| 146 | 1 | public function insertAfterIfExists($id) |
|
| 151 | |||
| 152 | /** |
||
| 153 | * @param string $id |
||
| 154 | */ |
||
| 155 | 5 | public function insertAfter($id) |
|
| 160 | } |
||
| 161 |