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 |
||
| 19 | class ParameterBuilder extends AbstractDefinition implements ParameterBuilderInterface |
||
| 20 | {
|
||
| 21 | /** @var array */ |
||
| 22 | protected $parameterCollection = []; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Define parameter |
||
| 26 | * |
||
| 27 | * @param string $name |
||
| 28 | * @param ReferenceInterface $reference |
||
| 29 | * @return ParameterBuilderInterface |
||
| 30 | * @throws ParameterAlreadyExistsException |
||
| 31 | */ |
||
| 32 | 13 | public function defineParameter(string $name, ReferenceInterface $reference): ParameterBuilderInterface |
|
| 36 | |||
| 37 | /** |
||
| 38 | * Change parameter |
||
| 39 | * |
||
| 40 | * @param string $name |
||
| 41 | * @param ReferenceInterface $reference |
||
| 42 | * @return ParameterBuilder |
||
| 43 | * @throws ParameterNotFoundException |
||
| 44 | */ |
||
| 45 | 2 | View Code Duplication | public function changeParameter(string $name, ReferenceInterface $reference): ParameterBuilder |
| 54 | |||
| 55 | /** |
||
| 56 | * Add parameter to collection |
||
| 57 | * |
||
| 58 | * @param string $name |
||
| 59 | * @param ReferenceInterface $reference |
||
| 60 | * @return ParameterBuilder |
||
| 61 | * @throws ParameterAlreadyExistsException |
||
| 62 | */ |
||
| 63 | 15 | View Code Duplication | public function add(string $name, ReferenceInterface $reference): ParameterBuilder |
| 72 | |||
| 73 | /** |
||
| 74 | * Has parameter in collection |
||
| 75 | * |
||
| 76 | * @param string $name |
||
| 77 | * @return bool |
||
| 78 | */ |
||
| 79 | 15 | public function has(string $name): bool |
|
| 83 | |||
| 84 | /** |
||
| 85 | * Remove parameter |
||
| 86 | * |
||
| 87 | * @param string $name |
||
| 88 | * @throws ParameterNotFoundException |
||
| 89 | */ |
||
| 90 | 2 | View Code Duplication | public function remove(string $name) |
| 97 | |||
| 98 | /** |
||
| 99 | * Get parameter |
||
| 100 | * |
||
| 101 | * @param string $name |
||
| 102 | * @return ReferenceInterface |
||
| 103 | * @throws ParameterNotFoundException |
||
| 104 | */ |
||
| 105 | 5 | View Code Duplication | public function get(string $name): ReferenceInterface |
| 112 | |||
| 113 | /** |
||
| 114 | * Get parameter collection |
||
| 115 | * |
||
| 116 | * @return ReferenceInterface[] |
||
| 117 | */ |
||
| 118 | 9 | public function getParameterCollection(): array |
|
| 122 | |||
| 123 | /** |
||
| 124 | * Set parent definition |
||
| 125 | * |
||
| 126 | * @param AbstractDefinition $definition |
||
| 127 | */ |
||
| 128 | 18 | public function setParentDefinition(AbstractDefinition $definition) |
|
| 132 | } |
||
| 133 |