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 |
||
15 | class TerminalApi extends AbstractAPI |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * TerminalApi constructor. |
||
20 | */ |
||
21 | public function __construct(Client $client = null) |
||
25 | |||
26 | /** |
||
27 | * @param integer $pessoaId |
||
28 | * @return Contracts\Terminal\GetByPessoaIdResponse |
||
29 | * @throws \Exception |
||
30 | */ |
||
31 | View Code Duplication | public function getByPessoaId($pessoaId) |
|
50 | |||
51 | /** |
||
52 | * @param integer $terminalId |
||
53 | * @return Contracts\Terminal\GetByIdResponse |
||
54 | * @throws \Exception |
||
55 | */ |
||
56 | View Code Duplication | public function getById($terminalId) |
|
75 | |||
76 | /** |
||
77 | * @param Contracts\Terminal\InsertRequest $insertRequest |
||
78 | * @return Contracts\Terminal\GetByIdResponse |
||
79 | * @throws \Exception |
||
80 | */ |
||
81 | View Code Duplication | public function insert(Contracts\Terminal\InsertRequest $insertRequest) |
|
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.