Completed
Push — master ( 924818...a51019 )
by Adriano
02:59
created

VendaApi::consultarVendas()   A

Complexity

Conditions 3
Paths 5

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
cc 3
eloc 15
nc 5
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: a.moreira
5
 * Date: 20/10/2016
6
 * Time: 09:51
7
 */
8
9
namespace Integracao\ControlPay\API;
10
11
use GuzzleHttp\Exception\RequestException;
12
use Integracao\ControlPay\AbstractAPI;
13
use Integracao\ControlPay\Client;
14
use Integracao\ControlPay\Helpers\SerializerHelper;
15
use Integracao\ControlPay\Contracts;
16
17
/**
18
 * Class VenderApi
19
 * @package Integracao\ControlPay\API
20
 */
21 View Code Duplication
class VendaApi extends AbstractAPI
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
22
{
23
24
    /**
25
     * VenderApi constructor.
26
     */
27
    public function __construct(Client $client = null)
28
    {
29
        parent::__construct('venda', $client);
30
    }
31
32
    /**
33
     * @param Contracts\Venda\VenderRequest $venderRequest
34
     * @return Contracts\Venda\VenderResponse
35
     * @throws \Exception
36
     */
37
    public function vender(Contracts\Venda\VenderRequest $venderRequest)
38
    {
39
        try{
40
            $response = $this->_httpClient->post(__FUNCTION__,[
41
                'body' => json_encode($venderRequest),
42
            ]);
43
44
            return SerializerHelper::denormalize(
45
                $response->json(),
46
                Contracts\Venda\VenderResponse::class
47
            );
48
        }catch (RequestException $ex) {
49
            $responseBody = $ex->getResponse()->json();
50
            throw new \Exception($responseBody['message']);
51
        }catch (\Exception $ex){
52
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
53
        }
54
    }
55
56
//    /**
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
57
//     * API Provavelmente descontinuada
58
//     *
59
//     * @return Contracts\Venda\ConsultarVendasResponse
60
//     * @throws \Exception
61
//     */
62
//    public function consultarVendas(array $ids = [])
63
//    {
64
//        try{
65
//            $response = $this->_httpClient->post(__FUNCTION__, [
66
//                'body' => json_encode(array_map(function($id){
67
//                    return [
68
//                        'Id' => (string)$id
69
//                    ];
70
//                },$ids))
71
//            ]);
72
//
73
//            return SerializerHelper::denormalize(
74
//                $response->json(),
75
//                Contracts\Venda\ConsultarVendasResponse::class
76
//            );
77
//        }catch (RequestException $ex) {
78
//            $responseBody = $ex->getResponse()->json();
79
//            throw new \Exception($responseBody['message']);
80
//        }catch (\Exception $ex){
81
//            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
82
//        }
83
//    }
84
85
}