File400   A
last analyzed

Complexity

Total Complexity 33

Size/Duplication

Total Lines 234
Duplicated Lines 17.95 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 33
c 0
b 0
f 0
lcom 0
cbo 1
dl 42
loc 234
rs 9.3999

15 Methods

Rating   Name   Duplication   Size   Complexity  
A mutateDetailAccount() 0 4 1
A mutateDetailAccountDv() 0 8 3
A mutateDetailBranch() 0 7 1
A mutateDetailBranchDv() 0 7 1
A mutateDetailCompanyDocumentType() 0 6 2
A mutateDetailDiscountTo() 0 8 3
A mutateDetailDocumentType() 0 6 2
A mutateDetailGuaranteeContract() 0 4 1
A mutateDetailGuaranteeContractDv() 0 8 3
A mutateDetailReceiveBranch() 9 9 3
A mutateDetailReceiveBranchDv() 9 9 3
A mutateHeaderBranch() 0 4 1
A mutateHeaderBranchDv() 8 8 3
A mutateHeaderCompanyCode() 8 8 3
A mutateHeaderCompanyCodeDv() 8 8 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 SmartCNAB\Services\Remittances\Banks\SICOOB;
4
5
use SmartCNAB\Support\File\Remittance;
6
7
/**
8
 * Class for SICOOB remittance CNAB 400 layout.
9
 */
10
class File400 extends Remittance
11
{
12
    /**
13
     * File schema file.
14
     *
15
     * @var string
16
     */
17
    protected $schemaFile = '/schemas/400.json';
18
19
    /**
20
     * Mutates an account on detail.
21
     *
22
     * @param  mixed  $value
23
     * @return mixed
24
     */
25
    protected function mutateDetailAccount($value)
26
    {
27
        return $value;
28
    }
29
30
    /**
31
     * Mutates an account DV on detail.
32
     *
33
     * @param  mixed  $value
34
     * @param  array  $data
35
     * @return mixed
36
     */
37
    protected function mutateDetailAccountDv(
38
        $value,
39
        array $data = []
40
    ) {
41
        if (empty($data['accountDv'])) return $value;
42
43
        return $value ?: $data['accountDv'];
44
    }
45
46
    /**
47
     * Mutates a branch on detail.
48
     *
49
     * @param  mixed  $value
50
     * @param  array  $data
51
     * @param  array  $meta
52
     * @return mixed
53
     */
54
    protected function mutateDetailBranch(
55
        $value,
56
        array $data = [],
57
        array $meta = []
58
    ) {
59
        return $this->mutateHeaderBranch($value, $data, $meta);
0 ignored issues
show
Unused Code introduced by
The call to File400::mutateHeaderBranch() has too many arguments starting with $data.

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...
60
    }
61
62
    /**
63
     * Mutates a branch DV on detail.
64
     *
65
     * @param  mixed  $value
66
     * @param  array  $data
67
     * @param  array  $meta
68
     * @return mixed
69
     */
70
    protected function mutateDetailBranchDv(
71
        $value,
72
        array $data = [],
73
        array $meta = []
74
    ) {
75
        return $this->mutateHeaderBranchDv($value, $data, $meta);
0 ignored issues
show
Unused Code introduced by
The call to File400::mutateHeaderBranchDv() 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...
76
    }
77
78
    /**
79
     * Mutates a company document type.
80
     *
81
     * @param  mixed  $value
82
     * @param  array  $data
83
     * @return mixed
84
     */
85
    protected function mutateDetailCompanyDocumentType(
86
        $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...
87
        array $data = []
88
    ) {
89
        return strlen($data['companyDocument']) === 14 ? 2 : 1;
90
    }
91
92
    /**
93
     * Mutates a discount to date.
94
     *
95
     * @param  mixed  $value
96
     * @param  array  $data
97
     * @return mixed
98
     */
99
    protected function mutateDetailDiscountTo(
100
        $value,
101
        array $data = []
102
    ) {
103
        if($data['discount'] == '0') return '';
104
105
        return $value ?: $data['expiration'];
106
    }
107
108
    /**
109
     * Mutates a document type.
110
     *
111
     * @param  mixed  $value
112
     * @param  array  $data
113
     * @return mixed
114
     */
115
    protected function mutateDetailDocumentType(
116
        $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...
117
        array $data = []
118
    ) {
119
        return strlen($data['document']) === 14 ? 2 : 1;
120
    }
121
122
    /**
123
     * Mutates a guarantee contract on detail.
124
     *
125
     * @param  mixed  $value
126
     * @return mixed
127
     */
128
    protected function mutateDetailGuaranteeContract($value)
129
    {
130
        return substr($value, 0, -1);
131
    }
132
133
    /**
134
     * Mutates a guarantee contract DV on detail.
135
     *
136
     * @param  mixed  $value
137
     * @param  array  $data
138
     * @return mixed
139
     */
140
    protected function mutateDetailGuaranteeContractDv(
141
        $value,
142
        array $data = []
143
    ) {
144
        if (empty($data['guaranteeContract'])) return $value;
145
146
        return $value ?: substr($data['guaranteeContract'], -1);
147
    }
148
149
    /**
150
     * Mutates a receive branch on detail.
151
     *
152
     * @param  mixed  $value
153
     * @param  array  $data
154
     * @param  array  $meta
155
     * @return mixed
156
     */
157 View Code Duplication
    protected function mutateDetailReceiveBranch(
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...
158
        $value,
159
        array $data = [],
160
        array $meta = []
0 ignored issues
show
Unused Code introduced by
The parameter $meta 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...
161
    ) {
162
        if (empty($data['branch'])) return $value;
163
164
        return empty($data['branch']) ? $value : $data['branch'];
165
    }
166
167
    /**
168
     * Mutates a receive branch DV on detail.
169
     *
170
     * @param  mixed  $value
171
     * @param  array  $data
172
     * @param  array  $meta
173
     * @return mixed
174
     */
175 View Code Duplication
    protected function mutateDetailReceiveBranchDv(
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...
176
        $value,
177
        array $data = [],
178
        array $meta = []
0 ignored issues
show
Unused Code introduced by
The parameter $meta 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...
179
    ) {
180
        if (empty($data['branch'])) return $value;
181
182
        return empty($data['branchDv']) ? $value : $data['branchDv'];
183
    }
184
185
    /**
186
     * Mutates a branch on header.
187
     *
188
     * @param  mixed  $value
189
     * @return mixed
190
     */
191
    protected function mutateHeaderBranch($value)
192
    {
193
        return $value;
194
    }
195
196
    /**
197
     * Mutates a branch DV on header.
198
     *
199
     * @param  mixed  $value
200
     * @param  array  $data
201
     * @return mixed
202
     */
203 View Code Duplication
    protected function mutateHeaderBranchDv(
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...
204
        $value,
205
        array $data = []
206
    ) {
207
        if (empty($data['branch'])) return $value;
208
209
        return empty($data['branchDv']) ? $value : $data['branchDv'];
210
    }
211
212
    /**
213
     * Mutates a company code on header.
214
     *
215
     * @param  mixed  $value
216
     * @param  array  $data
217
     * @return mixed
218
     */
219 View Code Duplication
    protected function mutateHeaderCompanyCode(
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...
220
        $value,
221
        array $data = []
222
    ) {
223
        if (empty($data['companyCode'])) return $value;
224
225
        return $value ? substr($value, 0, -1) : substr($data['companyCode'], 0, -1);
226
    }
227
228
    /**
229
     * Mutates a company code DV on header.
230
     *
231
     * @param  mixed  $value
232
     * @param  array  $data
233
     * @return mixed
234
     */
235 View Code Duplication
    protected function mutateHeaderCompanyCodeDv(
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...
236
        $value,
237
        array $data = []
238
    ) {
239
        if (empty($data['companyCode'])) return $value;
240
241
        return $value ? substr($data['value'], -1) : substr($data['companyCode'], -1);
242
    }
243
}
244