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 Set implements SetInterface |
||
| 9 | { |
||
| 10 | use Type; |
||
| 11 | |||
| 12 | private $type; |
||
| 13 | private $spec; |
||
| 14 | private $values; |
||
| 15 | |||
| 16 | 24 | public function __construct(string $type) |
|
| 22 | |||
| 23 | /** |
||
| 24 | * {@inheritdoc} |
||
| 25 | */ |
||
| 26 | 13 | public function type(): StringPrimitive |
|
| 30 | |||
| 31 | /** |
||
| 32 | * {@inheritdoc} |
||
| 33 | */ |
||
| 34 | 2 | public function size(): int |
|
| 38 | |||
| 39 | /** |
||
| 40 | * {@inheritdoc} |
||
| 41 | */ |
||
| 42 | 1 | public function count(): int |
|
| 46 | |||
| 47 | /** |
||
| 48 | * {@inheritdoc} |
||
| 49 | */ |
||
| 50 | 13 | public function toPrimitive() |
|
| 54 | |||
| 55 | /** |
||
| 56 | * {@inheritdoc} |
||
| 57 | */ |
||
| 58 | 1 | public function current() |
|
| 62 | |||
| 63 | /** |
||
| 64 | * {@inheritdoc} |
||
| 65 | */ |
||
| 66 | 1 | public function key() |
|
| 70 | |||
| 71 | /** |
||
| 72 | * {@inheritdoc} |
||
| 73 | */ |
||
| 74 | 1 | public function next() |
|
| 78 | |||
| 79 | /** |
||
| 80 | * {@inheritdoc} |
||
| 81 | */ |
||
| 82 | 1 | public function rewind() |
|
| 86 | |||
| 87 | /** |
||
| 88 | * {@inheritdoc} |
||
| 89 | */ |
||
| 90 | 1 | public function valid() |
|
| 94 | |||
| 95 | /** |
||
| 96 | * {@inheritdoc} |
||
| 97 | */ |
||
| 98 | 2 | View Code Duplication | public function intersect(SetInterface $set): SetInterface |
| 109 | |||
| 110 | /** |
||
| 111 | * {@inheritdoc} |
||
| 112 | */ |
||
| 113 | 19 | public function add($element): SetInterface |
|
| 126 | |||
| 127 | /** |
||
| 128 | * {@inheritdoc} |
||
| 129 | */ |
||
| 130 | 18 | public function contains($element): bool |
|
| 134 | |||
| 135 | /** |
||
| 136 | * {@inheritdoc} |
||
| 137 | */ |
||
| 138 | 1 | public function remove($element): SetInterface |
|
| 152 | |||
| 153 | /** |
||
| 154 | * {@inheritdoc} |
||
| 155 | */ |
||
| 156 | 2 | View Code Duplication | public function diff(SetInterface $set): SetInterface |
| 167 | |||
| 168 | /** |
||
| 169 | * {@inheritdoc} |
||
| 170 | */ |
||
| 171 | 3 | public function equals(SetInterface $set): bool |
|
| 179 | |||
| 180 | /** |
||
| 181 | * {@inheritdoc} |
||
| 182 | */ |
||
| 183 | 1 | public function filter(callable $predicate): SetInterface |
|
| 190 | |||
| 191 | /** |
||
| 192 | * {@inheritdoc} |
||
| 193 | */ |
||
| 194 | public function foreach(callable $function): SetInterface |
||
| 200 | |||
| 201 | /** |
||
| 202 | * {@inheritdoc} |
||
| 203 | */ |
||
| 204 | 1 | public function groupBy(callable $discriminator): MapInterface |
|
| 208 | |||
| 209 | /** |
||
| 210 | * {@inheritdoc} |
||
| 211 | */ |
||
| 212 | 2 | public function map(callable $function): SetInterface |
|
| 224 | |||
| 225 | /** |
||
| 226 | * {@inheritdoc} |
||
| 227 | */ |
||
| 228 | 1 | public function partition(callable $predicate): MapInterface |
|
| 240 | |||
| 241 | /** |
||
| 242 | * {@inheritdoc} |
||
| 243 | */ |
||
| 244 | 1 | public function join(string $separator): StringPrimitive |
|
| 248 | |||
| 249 | /** |
||
| 250 | * {@inheritdoc} |
||
| 251 | */ |
||
| 252 | 1 | public function sort(callable $function): SequenceInterface |
|
| 256 | |||
| 257 | /** |
||
| 258 | * {@inheritdoc} |
||
| 259 | */ |
||
| 260 | 2 | public function merge(SetInterface $set): SetInterface |
|
| 271 | |||
| 272 | /** |
||
| 273 | * {@inheritdoc} |
||
| 274 | */ |
||
| 275 | 4 | public function reduce($carry, callable $reducer) |
|
| 279 | |||
| 280 | /** |
||
| 281 | * Make sure the set is compatible with the current one |
||
| 282 | * |
||
| 283 | * @param SetInterface $set |
||
| 284 | * |
||
| 285 | * @throws InvalidArgumentException |
||
| 286 | * |
||
| 287 | * @return void |
||
| 288 | */ |
||
| 289 | 8 | private function validate(SetInterface $set) |
|
| 297 | } |
||
| 298 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.