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 |
||
25 | class StateApiClient extends DocumentApiClient implements StateApiClientInterface |
||
26 | { |
||
27 | /** |
||
28 | * @var ActorSerializerInterface |
||
29 | */ |
||
30 | private $actorSerializer; |
||
31 | |||
32 | /** |
||
33 | * @param HandlerInterface $requestHandler The HTTP request handler |
||
34 | * @param string $version The xAPI version |
||
35 | * @param DocumentDataSerializerInterface $documentDataSerializer The document data serializer |
||
36 | * @param ActorSerializerInterface $actorSerializer The actor serializer |
||
37 | */ |
||
38 | public function __construct( |
||
48 | |||
49 | /** |
||
50 | * {@inheritDoc} |
||
51 | */ |
||
52 | public function createOrUpdateDocument(StateDocument $document) |
||
56 | |||
57 | /** |
||
58 | * {@inheritDoc} |
||
59 | */ |
||
60 | public function createOrReplaceDocument(StateDocument $document) |
||
64 | |||
65 | /** |
||
66 | * {@inheritDoc} |
||
67 | */ |
||
68 | public function deleteDocument(State $state) |
||
76 | |||
77 | /** |
||
78 | * {@inheritDoc} |
||
79 | */ |
||
80 | View Code Duplication | public function getDocument(State $state) |
|
91 | |||
92 | /** |
||
93 | * Stores a state document. |
||
94 | * |
||
95 | * @param string $method HTTP method to use |
||
96 | * @param StateDocument $document The document to store |
||
97 | */ |
||
98 | View Code Duplication | private function doStoreStateDocument($method, StateDocument $document) |
|
112 | } |
||
113 |
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.