Passed
Push — master ( 640d80...f107f9 )
by Max Alex
01:45
created

Cobranca::split()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace CodePhix\Asaas;
4
5
use CodePhix\Asaas\Connection;
6
7
class Cobranca {
8
    public $http;
9
    protected $cobranca;
10
    
11
    public function __construct(Connection $connection)
12
    {
13
        $this->http = $connection;
14
    }
15
16
    // Retorna a listagem de cobranças
17
    public function getAll(array $filtros){
18
        $filtro = '';
19
        if(is_array($filtros)){
0 ignored issues
show
introduced by
The condition is_array($filtros) is always true.
Loading history...
20
            if($filtros){
0 ignored issues
show
Bug Best Practice introduced by
The expression $filtros of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
21
                foreach($filtros as $key => $f){
22
                    if(!empty($f)){
23
                        if($filtro){
24
                            $filtro .= '&';
25
                        }
26
                        $filtro .= $key.'='.$f;
27
                    }
28
                }
29
                $filtro = '?'.$filtro;
30
            }
31
        }
32
        return $this->http->get('/payments'.$filtro);
33
    }
34
35
    // Retorna os dados da cobrança de acordo com o Id
36
    public function getById($id){
37
        return $this->http->get('/payments/'.$id);
38
    }
39
40
    // Retorna a listagem de cobranças de acordo com o Id do Cliente
41
    public function getByCustomer($customer_id){
42
        return $this->http->get('/payments?customer='.$customer_id);
43
    }
44
45
    // Retorna a listagem de cobranças de acordo com o Id da Assinaturas
46
    public function getBySubscription($subscription_id){
47
        return $this->http->get('/payments?subscription='.$subscription_id);
48
    }
49
50
    // Insere uma nova cobrança
51
    public function create(array $dadosCobranca){
52
        $dadosCobranca = $this->setCobranca($dadosCobranca);
53
        if(!empty($dadosCobranca['error'])){
54
            return $dadosCobranca;
55
        }else {
56
            return $this->http->post('/payments', $dadosCobranca);
57
        }
58
    }
59
60
    // Insere uma nova cobrança parcelada
61
    public function parcelada(array $dadosCobranca){
0 ignored issues
show
Unused Code introduced by
The parameter $dadosCobranca is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

61
    public function parcelada(/** @scrutinizer ignore-unused */ array $dadosCobranca){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
62
63
    }
64
65
    // Insere uma nova cobrança com split
66
        /* Saldo dividido em multiplas contas do Asaas*/
67
    public function split(array $dadosCobranca){
0 ignored issues
show
Unused Code introduced by
The parameter $dadosCobranca is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

67
    public function split(/** @scrutinizer ignore-unused */ array $dadosCobranca){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
68
69
    }
70
71
    // Atualiza os dados da cobrança
72
    public function update($id, array $dadosCobranca){
0 ignored issues
show
Unused Code introduced by
The parameter $dadosCobranca is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

72
    public function update($id, /** @scrutinizer ignore-unused */ array $dadosCobranca){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

72
    public function update(/** @scrutinizer ignore-unused */ $id, array $dadosCobranca){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
73
74
    }
75
76
    // Restaura cobrança removida
77
    public function restore($id){
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

77
    public function restore(/** @scrutinizer ignore-unused */ $id){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
78
79
    }
80
81
    // Estorna cobrança
82
    public function estorno($id){
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

82
    public function estorno(/** @scrutinizer ignore-unused */ $id){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
83
84
    }
85
86
    // Confirmação em dinheiro
87
    public function confirmacao($id, $dados){
0 ignored issues
show
Unused Code introduced by
The parameter $dados is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

87
    public function confirmacao($id, /** @scrutinizer ignore-unused */ $dados){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

87
    public function confirmacao(/** @scrutinizer ignore-unused */ $id, $dados){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
88
        $data = array(
89
            "paymentDate" => "2019-09-03",
90
            "value" => 100.00,
91
        );
92
        return $this->http->post('/customers', $data);
93
    }
94
95
    // Deleta uma cobrança
96
    public function delete($id){
97
        return $this->http->get('/payments/'.$id,'','DELETE');
98
    }
99
100
    /**
101
     * Cria um novo boleto no Asaas.
102
     * @param Array $cliente
103
     * @return Boolean
104
     */
105
    public function create2($dados)
106
    {
107
        // Preenche as informações da cobranca
108
        $cobranca = $this->setCobranca($dados);
109
        
110
        // Faz o post e retorna array de resposta
111
        return $this->http->post('/payments', ['form_params' => $cobranca]);
112
    }
113
114
    /**
115
     * Faz merge nas informações das cobranças.
116
     *
117
     * @see https://asaasv3.docs.apiary.io/#reference/0/cobrancas/criar-nova-cobrancas
118
     * @param Array $cliente
119
     * @return Array
120
     */
121
    public function setCobranca($dados)
122
    {
123
        try {
124
            $this->cobranca = array(
125
                'customer'             => '',
126
                'billingType'          => '',
127
                'value'                => '',
128
                'dueDate'              => '',
129
                'description'          => '',
130
                'externalReference'    => '',
131
                'installmentCount'     => '',
132
                'installmentValue'     => '',
133
                'discount'             => '',
134
                'interest'             => '',
135
                'fine'                 => '',
136
            );
137
138
            $this->cobranca = array_merge($this->cobranca, $dados);
139
            return $this->cobranca;
140
141
        } catch (Exception $e) {
142
            return 'Erro ao definir o cliente. - ' . $e->getMessage();
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'Erro ao definir ... - ' . $e->getMessage() returns the type string which is incompatible with the documented return type array.
Loading history...
143
        }
144
    }
145
146
    /**
147
     * Faz merge nas informações das cobranças.
148
     *
149
     * @see https://asaasv3.docs.apiary.io/#reference/0/cobrancas/criar-nova-cobrancas
150
     * @param Array $cliente
151
     * @return Array
152
     */
153
    public function setCobrancaCartao($dados)
154
    {
155
        try {
156
            $this->cobranca = array(
157
                'customer'             => '',
158
                'billingType'          => '',
159
                'value'                => '',
160
                'dueDate'              => '',
161
                'description'          => '',
162
                'externalReference'    => '',
163
                'installmentCount'     => '',
164
                'installmentValue'     => '',
165
                'discount'             => '',
166
                'interest'             => '',
167
                'fine'                 => '',
168
            );
169
170
            $this->cobranca = array_merge($this->cobranca, $dados);
171
            return $this->cobranca;
172
173
        } catch (Exception $e) {
174
            return 'Erro ao definir o cliente. - ' . $e->getMessage();
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'Erro ao definir ... - ' . $e->getMessage() returns the type string which is incompatible with the documented return type array.
Loading history...
175
        }
176
    }
177
}
178