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 |
||
26 | class AgentProfileApiClient extends DocumentApiClient implements AgentProfileApiClientInterface |
||
27 | { |
||
28 | /** |
||
29 | * @var ActorSerializerInterface |
||
30 | */ |
||
31 | private $actorSerializer; |
||
32 | |||
33 | /** |
||
34 | * @param HandlerInterface $requestHandler The HTTP request handler |
||
35 | * @param string $version The xAPI version |
||
36 | * @param DocumentDataSerializerInterface $documentDataSerializer The document data serializer |
||
37 | * @param ActorSerializerInterface $actorSerializer The actor serializer |
||
38 | */ |
||
39 | public function __construct( |
||
49 | |||
50 | /** |
||
51 | * {@inheritDoc} |
||
52 | */ |
||
53 | View Code Duplication | public function createOrUpdateDocument(AgentProfileDocument $document) |
|
61 | |||
62 | /** |
||
63 | * {@inheritDoc} |
||
64 | */ |
||
65 | View Code Duplication | public function createOrReplaceDocument(AgentProfileDocument $document) |
|
73 | |||
74 | /** |
||
75 | * {@inheritDoc} |
||
76 | */ |
||
77 | public function deleteDocument(AgentProfile $profile) |
||
84 | |||
85 | /** |
||
86 | * {@inheritDoc} |
||
87 | */ |
||
88 | View Code Duplication | public function getDocument(AgentProfile $profile) |
|
98 | } |
||
99 |
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.