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 |
||
| 22 | class VendaApi extends AbstractAPI |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * @var PedidoApi |
||
| 26 | */ |
||
| 27 | private $pedidoApi; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * VenderApi constructor. |
||
| 31 | */ |
||
| 32 | public function __construct(Client $client = null) |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param Contracts\Venda\VenderRequest $venderRequest |
||
| 40 | * @return Contracts\Venda\VenderResponse |
||
| 41 | * @throws \Exception |
||
| 42 | */ |
||
| 43 | public function vender(Contracts\Venda\VenderRequest $venderRequest) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @param Contracts\Venda\VenderComPedidoRequest $venderComPedidoRequest |
||
| 91 | * @return Contracts\Venda\VenderResponse |
||
| 92 | * @throws \Exception |
||
| 93 | */ |
||
| 94 | public function venderComPedido(Contracts\Venda\VenderComPedidoRequest $venderComPedidoRequest) |
||
| 115 | |||
| 116 | // /** |
||
| 117 | // * API Provavelmente descontinuada |
||
| 118 | // * |
||
| 119 | // * @return Contracts\Venda\ConsultarVendasResponse |
||
| 120 | // * @throws \Exception |
||
| 121 | // */ |
||
| 122 | // public function consultarVendas(array $ids = []) |
||
| 123 | // { |
||
| 124 | // try{ |
||
| 125 | // $this->response = $this->_httpClient->post(__FUNCTION__, [ |
||
| 126 | // 'body' => json_encode(array_map(function($id){ |
||
| 127 | // return [ |
||
| 128 | // 'Id' => (string)$id |
||
| 129 | // ]; |
||
| 130 | // },$ids)) |
||
| 131 | // ]); |
||
| 132 | // |
||
| 133 | // return SerializerHelper::denormalize( |
||
| 134 | // $this->response->json(), |
||
| 135 | // Contracts\Venda\ConsultarVendasResponse::class |
||
| 136 | // ); |
||
| 137 | // }catch (RequestException $ex) { |
||
| 138 | // $this->response = $ex->getResponse(); |
||
| 139 | // $responseBody = $ex->getResponse()->json(); |
||
| 140 | // throw new \Exception($responseBody['message']); |
||
| 141 | // }catch (\Exception $ex){ |
||
| 142 | // throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
||
| 143 | // } |
||
| 144 | // } |
||
| 145 | |||
| 146 | } |
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.
We recommend to add an additional type check (or disallow null for the parameter):