File400   A
last analyzed

Complexity

Total Complexity 21

Size/Duplication

Total Lines 180
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 21
lcom 1
cbo 1
dl 0
loc 180
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A mutateDetailAccount() 0 7 1
A mutateDetailAccountDv() 0 7 1
A mutateDetailCompanyDocumentType() 0 6 2
A mutateDetailDiscountTo() 0 6 2
A mutateDetailDocumentType() 0 6 2
A mutateDetailLateInterestDate() 0 6 2
A mutateDetailOurNumber() 0 9 3
A mutateDetailPortfolioCode() 0 7 2
A mutateHeaderAccount() 0 8 3
A mutateHeaderAccountDv() 0 8 3
1
<?php
2
3
namespace SmartCNAB\Services\Remittances\Banks\Itau;
4
5
use SmartCNAB\Support\File\Remittance;
6
7
/**
8
 * Class for Itau remittance CNAB 400 layout.
9
 */
10
class File400 extends Remittance
11
{
12
    /**
13
     * Map of portfolios codes.
14
     *
15
     * @var array
16
     */
17
    protected $portfolioCodes = [
18
        '108' => ['I', 'D'],
19
        '180' => ['I', 'D'],
20
        '121' => ['I', 'D'],
21
        '150' => ['U', 'D'],
22
        '109' => ['I', 'D'],
23
        '191' => ['1', ''],
24
        '104' => ['I', 'E'],
25
        '188' => ['I', 'E'],
26
        '147' => ['E', 'E'],
27
        '112' => ['I', 'E'],
28
        '115' => ['I', 'E'],
29
    ];
30
31
    /**
32
     * File schema file.
33
     *
34
     * @var string
35
     */
36
    protected $schemaFile = '/schemas/400.json';
37
38
    /**
39
     * Mutates an account on detail.
40
     *
41
     * @param  mixed  $value
42
     * @param  array  $data
43
     * @param  array  $meta
44
     * @return mixed
45
     */
46
    protected function mutateDetailAccount(
47
        $value,
48
        array $data = [],
49
        array $meta = []
50
    ) {
51
        return $this->mutateHeaderAccount($value, $data, $meta);
0 ignored issues
show
Unused Code introduced by
The call to File400::mutateHeaderAccount() has too many arguments starting with $meta.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
52
    }
53
54
    /**
55
     * Mutates an account DV on detail.
56
     *
57
     * @param  mixed  $value
58
     * @param  array  $data
59
     * @param  array  $meta
60
     * @return mixed
61
     */
62
    protected function mutateDetailAccountDv(
63
        $value,
64
        array $data = [],
65
        array $meta = []
66
    ) {
67
        return $this->mutateHeaderAccountDv($value, $data, $meta);
0 ignored issues
show
Unused Code introduced by
The call to File400::mutateHeaderAccountDv() has too many arguments starting with $meta.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
68
    }
69
70
    /**
71
     * Mutates a company document type.
72
     *
73
     * @param  mixed  $value
74
     * @param  array  $data
75
     * @return mixed
76
     */
77
    protected function mutateDetailCompanyDocumentType(
78
        $value,
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed.

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

Loading history...
79
        array $data = []
80
    ) {
81
        return strlen($data['companyDocument']) === 14 ? 2 : 1;
82
    }
83
84
    /**
85
     * Mutates a discount to date.
86
     *
87
     * @param  mixed  $value
88
     * @param  array  $data
89
     * @return mixed
90
     */
91
    protected function mutateDetailDiscountTo(
92
        $value,
93
        array $data = []
94
    ) {
95
        return $value ?: $data['expiration'];
96
    }
97
98
    /**
99
     * Mutates a document type.
100
     *
101
     * @param  mixed  $value
102
     * @param  array  $data
103
     * @return mixed
104
     */
105
    protected function mutateDetailDocumentType(
106
        $value,
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed.

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

Loading history...
107
        array $data = []
108
    ) {
109
        return strlen($data['document']) === 14 ? 2 : 1;
110
    }
111
112
    /**
113
     * Mutates a late interest date.
114
     *
115
     * @param  mixed  $value
116
     * @param  array  $data
117
     * @return mixed
118
     */
119
    protected function mutateDetailLateInterestDate(
120
        $value,
121
        array $data = []
122
    ) {
123
        return $value ?: $data['expiration']->add(new \DateInterval('P1D'));
124
    }
125
126
    /**
127
     * Mutates the our number.
128
     *
129
     * @param  mixed  $value
130
     * @param  array  $data
131
     * @return mixed
132
     */
133
    protected function mutateDetailOurNumber(
134
        $value,
135
        array $data = []
136
    ) {
137
        $bypass = $this->portfolioCodes[$data['portfolio']][1] === 'D' ||
138
                    $data['portfolio'] == 115;
139
140
        return $bypass ? $value : '';
141
    }
142
143
    /**
144
     * Mutates a portfolio code.
145
     *
146
     * @param  mixed  $value
147
     * @param  array  $data
148
     * @return mixed
149
     */
150
    protected function mutateDetailPortfolioCode(
151
        $value,
152
        array $data = []
153
    ) {
154
        return ( ! empty($this->portfolioCodes[$data['portfolio']])) ?
155
                    $this->portfolioCodes[$data['portfolio']][0] : $value;
156
    }
157
158
    /**
159
     * Mutates an account on header.
160
     *
161
     * @param  mixed  $value
162
     * @param  array  $data
163
     * @return mixed
164
     */
165
    protected function mutateHeaderAccount(
166
        $value,
167
        array $data = []
168
    ) {
169
        if (empty($data['account'])) return $value;
170
171
        return $value ?: $data['account'];
172
    }
173
174
    /**
175
     * Mutates an account DV on header.
176
     *
177
     * @param  mixed  $value
178
     * @param  array  $data
179
     * @return mixed
180
     */
181
    protected function mutateHeaderAccountDv(
182
        $value,
183
        array $data = []
184
    ) {
185
        if (empty($data['accountDv'])) return $value;
186
187
        return $value ?: $data['accountDv'];
188
    }
189
}
190