| Conditions | 10 |
| Paths | 460 |
| Total Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 43 | public function vender(Contracts\Venda\VenderRequest $venderRequest) |
||
| 44 | { |
||
| 45 | try{ |
||
| 46 | |||
| 47 | if(empty($venderRequest->getTerminalId())) |
||
| 48 | $venderRequest->setTerminalId( |
||
| 49 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_TERMINAL_ID) |
||
| 50 | ); |
||
| 51 | |||
| 52 | if(empty($venderRequest->getFormaPagamentoId())) |
||
| 53 | $venderRequest->setFormaPagamentoId( |
||
| 54 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_FORMA_PAGAMENTO_ID) |
||
| 55 | ); |
||
| 56 | |||
| 57 | if(empty($venderRequest->isAguardarTefIniciarTransacao())) |
||
| 58 | $venderRequest->setAguardarTefIniciarTransacao( |
||
| 59 | boolval( |
||
| 60 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_FORMA_AGUARDA_TEF) |
||
| 61 | ) |
||
| 62 | ); |
||
| 63 | |||
| 64 | if(!empty($venderRequest->getProdutosVendidos())) |
||
| 65 | foreach ($venderRequest->getProdutosVendidos() as $key => $produto) |
||
| 66 | { |
||
| 67 | if(empty($produto->getId())) |
||
| 68 | $venderRequest->getProdutosVendidos()[$key]->setId( |
||
| 69 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_PRODUTO_ID) |
||
| 70 | ); |
||
| 71 | |||
| 72 | if(empty($produto->getQuantidade())) |
||
| 73 | $venderRequest->getProdutosVendidos()[$key]->setQuantidade( |
||
| 74 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_PRODUTO_QTDE) |
||
| 75 | ); |
||
| 76 | } |
||
| 77 | |||
| 78 | $this->response = $this->_httpClient->post(__FUNCTION__,[ |
||
| 79 | 'body' => json_encode($venderRequest), |
||
| 80 | ]); |
||
| 81 | |||
| 82 | return SerializerHelper::denormalize( |
||
| 83 | $this->response->json(), |
||
| 84 | Contracts\Venda\VenderResponse::class |
||
| 85 | ); |
||
| 86 | }catch (RequestException $ex) { |
||
| 87 | $this->requestException($ex); |
||
| 88 | }catch (\Exception $ex){ |
||
| 89 | throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 191 | } |
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):