TerminalApi   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 85
Duplicated Lines 64.71 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getByPessoaId() 19 19 3
A getById() 19 19 3
A insert() 17 17 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
namespace Integracao\ControlPay\API;
4
5
use GuzzleHttp\Exception\RequestException;
6
use Integracao\ControlPay\AbstractAPI;
7
use Integracao\ControlPay\Client;
8
use Integracao\ControlPay\Helpers\SerializerHelper;
9
use Integracao\ControlPay\Contracts;
10
11
/**
12
 * Class TerminalApi
13
 * @package Integracao\ControlPay\API
14
 */
15
class TerminalApi extends AbstractAPI
16
{
17
18
    /**
19
     * TerminalApi constructor.
20
     */
21
    public function __construct(Client $client = null)
22
    {
23
        parent::__construct('terminal', $client);
24
    }
25
26
    /**
27
     * @param integer $pessoaId
28
     * @return Contracts\Terminal\GetByPessoaIdResponse
29
     * @throws \Exception
30
     */
31 View Code Duplication
    public function getByPessoaId($pessoaId)
0 ignored issues
show
Duplication introduced by
This method 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...
32
    {
33
        try{
34
            $this->response = $this->_httpClient->post(__FUNCTION__,[
35
                'query' => $this->addQueryAdditionalParameters([
36
                    'pessoaId' => $pessoaId
37
                ])
38
            ]);
39
40
            return SerializerHelper::denormalize(
41
                $this->response->json(),
42
                Contracts\Terminal\GetByPessoaIdResponse::class
43
            );
44
        }catch (RequestException $ex) {
45
            $this->requestException($ex);
46
        }catch (\Exception $ex){
47
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
48
        }
49
    }
50
51
    /**
52
     * @param integer $terminalId
53
     * @return Contracts\Terminal\GetByIdResponse
54
     * @throws \Exception
55
     */
56 View Code Duplication
    public function getById($terminalId)
0 ignored issues
show
Duplication introduced by
This method 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...
57
    {
58
        try{
59
            $this->response = $this->_httpClient->post(__FUNCTION__,[
60
                'query' => $this->addQueryAdditionalParameters([
61
                    'terminalId' => $terminalId
62
                ])
63
            ]);
64
65
            return SerializerHelper::denormalize(
66
                $this->response->json(),
67
                Contracts\Terminal\GetByIdResponse::class
68
            );
69
        }catch (RequestException $ex) {
70
            $this->requestException($ex);
71
        }catch (\Exception $ex){
72
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
73
        }
74
    }
75
76
    /**
77
     * @param Contracts\Terminal\InsertRequest $insertRequest
78
     * @return Contracts\Terminal\GetByIdResponse
79
     * @throws \Exception
80
     */
81 View Code Duplication
    public function insert(Contracts\Terminal\InsertRequest $insertRequest)
0 ignored issues
show
Duplication introduced by
This method 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...
82
    {
83
        try{
84
            $this->response = $this->_httpClient->post(__FUNCTION__,[
85
                'body' => json_encode($insertRequest)
86
            ]);
87
88
            return SerializerHelper::denormalize(
89
                $this->response->json(),
90
                Contracts\Terminal\InsertResponse::class
91
            );
92
        }catch (RequestException $ex) {
93
            $this->requestException($ex);
94
        }catch (\Exception $ex){
95
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
96
        }
97
    }
98
99
}