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 |
||
16 | class IntencaoVendaApi extends AbstractAPI |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * IntencaoVendaApi constructor. |
||
21 | */ |
||
22 | public function __construct(Client $client = null) |
||
26 | |||
27 | /** |
||
28 | * @param Contracts\IntencaoVenda\GetByFiltrosRequest $getByFiltrosRequest |
||
29 | * @return Contracts\IntencaoVenda\GetByFiltrosResponse |
||
30 | * @throws \Exception |
||
31 | */ |
||
32 | public function getByFiltros(Contracts\IntencaoVenda\GetByFiltrosRequest $getByFiltrosRequest) |
||
51 | |||
52 | /** |
||
53 | * @param Contracts\IntencaoVenda\GetByFiltrosRequest $getByFiltrosRequest |
||
54 | * @return Contracts\IntencaoVenda\GetByFiltrosResponse |
||
55 | * @throws \Exception |
||
56 | */ |
||
57 | public function getByFiltrosAsync(Contracts\IntencaoVenda\GetByFiltrosRequest $getByFiltrosRequest) |
||
76 | |||
77 | /** |
||
78 | * @param integer $intencaoVendaId |
||
79 | * @return Contracts\IntencaoVenda\GetByIdResponse |
||
80 | * @throws \Exception |
||
81 | */ |
||
82 | View Code Duplication | public function getById($intencaoVendaId) |
|
103 | |||
104 | // /** |
||
105 | // * API Provavelmente descontinuada |
||
106 | // * |
||
107 | // * @param Contracts\IntencaoVenda\GetByIntegracaoIdRequest $getByIntegracaoIdRequest |
||
108 | // * @return Contracts\IntencaoVenda\GetByIntegracaoIdResponse |
||
109 | // * @throws \Exception |
||
110 | // */ |
||
111 | // public function getByIntegracaoId(Contracts\IntencaoVenda\GetByIntegracaoIdRequest $getByIntegracaoIdRequest) |
||
112 | // { |
||
113 | // try{ |
||
114 | // $this->response = $this->_httpClient->post(__FUNCTION__,[ |
||
115 | // 'body' => json_encode($getByIntegracaoIdRequest), |
||
116 | // ]); |
||
117 | // |
||
118 | // return SerializerHelper::denormalize( |
||
119 | // $this->response->json(), |
||
120 | // Contracts\IntencaoVenda\GetByIntegracaoIdResponse::class |
||
121 | // ); |
||
122 | // }catch (RequestException $ex) { |
||
123 | // $this->response = $ex->getResponse(); |
||
124 | // $responseBody = $ex->getResponse()->json(); |
||
125 | // throw new \Exception($responseBody['message']); |
||
126 | // }catch (\Exception $ex){ |
||
127 | // throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
||
128 | // } |
||
129 | // } |
||
130 | |||
131 | } |
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.