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 |
||
28 | class KeyValueStoreChangeStream implements ChangeStream |
||
29 | { |
||
30 | /** |
||
31 | * @var KeyValueStore |
||
32 | */ |
||
33 | private $store; |
||
34 | |||
35 | /** |
||
36 | * @param KeyValueStore $store |
||
37 | */ |
||
38 | 10 | public function __construct(KeyValueStore $store) |
|
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | 9 | public function append(PuliResource $resource) |
|
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | 3 | public function purge($path) |
|
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | 4 | public function contains($path) |
|
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | 1 | public function clear() |
|
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | 7 | public function getVersions($path, ResourceRepository $repository = null) |
|
100 | } |
||
101 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.