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

VendaApi   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 65
loc 65
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A vender() 18 18 3

How to fix   Duplicated Code   

Duplicated Code

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
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
}