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 StepReplacement |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var string |
||
| 12 | */ |
||
| 13 | private $idToReplace; |
||
| 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 | * StepReplacement constructor. |
||
| 32 | * |
||
| 33 | * @param string $idToReplace |
||
| 34 | * @param string $stepFqcn |
||
| 35 | * @param callable|null $factory |
||
| 36 | * @param string|null $description |
||
| 37 | */ |
||
| 38 | 12 | View Code Duplication | public function __construct($idToReplace, $stepFqcn, callable $factory = null, $description = null) |
| 48 | |||
| 49 | /** |
||
| 50 | * @param BuilderInterface $builder |
||
| 51 | */ |
||
| 52 | 2 | public function registerInBuilder(BuilderInterface $builder) |
|
| 58 | |||
| 59 | /** |
||
| 60 | * @return string |
||
| 61 | */ |
||
| 62 | 2 | public function getIdToReplace() |
|
| 66 | |||
| 67 | /** |
||
| 68 | * @return string |
||
| 69 | */ |
||
| 70 | 2 | public function getStepFqcn() |
|
| 74 | |||
| 75 | /** |
||
| 76 | * @return callable|null |
||
| 77 | */ |
||
| 78 | 2 | public function getFactory() |
|
| 82 | |||
| 83 | /** |
||
| 84 | * @return null|string |
||
| 85 | */ |
||
| 86 | 2 | public function getDescription() |
|
| 90 | } |
||
| 91 |