Bank   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 216
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 0
dl 0
loc 216
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A billing() 0 4 1
A channels() 0 4 1
defaults() 0 1 ?
A documentsPrefixes() 0 4 1
A emission() 0 4 1
A especies() 0 4 1
A instructions() 0 4 1
A motives() 0 8 2
A postage() 0 4 1
A rejectionCodes() 0 4 1
A remittanceOccurrences() 0 4 1
A returnOccurrences() 0 4 1
A findMotives() 0 10 1
1
<?php
2
3
namespace SmartCNAB\Support\Bank;
4
5
use SmartCNAB\Contracts\Support\BankSupportInterface;
6
7
/**
8
 * Bank base support class.
9
 */
10
abstract class Bank implements BankSupportInterface
11
{
12
    /**
13
     * Channels codes.
14
     *
15
     * @var array
16
     */
17
    protected static $billing = [];
18
19
    /**
20
     * Channels codes.
21
     *
22
     * @var array
23
     */
24
    protected static $channels = [];
25
26
    /**
27
     * Prefixes of documents.
28
     *
29
     * @var array
30
     */
31
    protected static $documentsPrefixes = [];
32
33
    /**
34
     * Emission types.
35
     *
36
     * @var array
37
     */
38
    protected static $emission = [];
39
40
    /**
41
     * Especies codes.
42
     *
43
     * @var array
44
     */
45
    protected static $especies = [];
46
47
    /**
48
     * Billing instruction.
49
     *
50
     * @var array
51
     */
52
    protected static $instructions = [];
53
54
    /**
55
     * Motives codes.
56
     *
57
     * @var array
58
     */
59
    protected static $motives = [];
60
61
    /**
62
     * Postage types.
63
     *
64
     * @var array
65
     */
66
    protected static $postage = [];
67
68
    /**
69
     * Return all available rejection codes.
70
     *
71
     * @var array
72
     */
73
    protected static $rejectionCodes = [];
74
75
    /**
76
     * Remittance occurrences codes.
77
     *
78
     * @var array
79
     */
80
    protected static $remittanceOccurrences = [];
81
82
    /**
83
     * Return occurrences codes.
84
     *
85
     * @var array
86
     */
87
    protected static $returnOccurrences = [];
88
89
    /**
90
     * @return array
91
     */
92
    public function billing()
93
    {
94
        return static::$billing;
95
    }
96
97
    /**
98
     * Return the payment channels.
99
     *
100
     * @return array
101
     */
102
    public function channels()
103
    {
104
        return static::$channels;
105
    }
106
107
    /**
108
     * Return the default state of itau infos.
109
     *
110
     * @return \StdClass
111
     */
112
    abstract public function defaults();
113
114
    /**
115
     * Return all available documents prefixes.
116
     *
117
     * @return array
118
     */
119
    public function documentsPrefixes()
120
    {
121
        return static::$documentsPrefixes;
122
    }
123
124
    /**
125
     * Return all available emission.
126
     *
127
     * @return array
128
     */
129
    public function emission()
130
    {
131
        return static::$emission;
132
    }
133
134
    /**
135
     * Return all available especies.
136
     *
137
     * @return array
138
     */
139
    public function especies()
140
    {
141
        return static::$especies;
142
    }
143
144
    /**
145
     * Return all available instructions.
146
     *
147
     * @return array
148
     */
149
    public function instructions()
150
    {
151
        return static::$instructions;
152
    }
153
154
    /**
155
     * Return all motives codes.
156
     *
157
     * @param  int  $occurrenceCode
158
     * @return array
159
     */
160
    public function motives($occurrenceCode = null)
161
    {
162
        if ( ! $occurrenceCode) return static::$motives;
0 ignored issues
show
Bug Best Practice introduced by
The expression $occurrenceCode of type integer|null is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
163
164
        $occurrenceCode = str_pad($occurrenceCode, 2, 0, STR_PAD_LEFT);
165
166
        return $this->findMotives($occurrenceCode);
167
    }
168
169
    /**
170
     * Return all available postage.
171
     *
172
     * @return array
173
     */
174
    public function postage()
175
    {
176
        return static::$postage;
177
    }
178
179
    /**
180
     * Return all available rejection codes.
181
     *
182
     * @return array
183
     */
184
    public function rejectionCodes()
185
    {
186
        return static::$rejectionCodes;
187
    }
188
189
    /**
190
     * Return all occurrences available for remittances.
191
     *
192
     * @return array
193
     */
194
    public function remittanceOccurrences()
195
    {
196
        return static::$remittanceOccurrences;
197
    }
198
199
    /**
200
     * Return all occurrences available for returning.
201
     *
202
     * @return array
203
     */
204
    public function returnOccurrences()
205
    {
206
        return static::$returnOccurrences;
207
    }
208
209
    /**
210
     * Find for a motive group by occurrenceCode.
211
     *
212
     * @param  int  $occurrenceCode
213
     * @return array
214
     */
215
    protected function findMotives($occurrenceCode)
216
    {
217
        $filter = function ($key) use ($occurrenceCode) {
218
            return in_array($occurrenceCode, explode(',', $key));
219
        };
220
221
        $motives = array_filter(static::$motives, $filter, ARRAY_FILTER_USE_KEY);
222
223
        return reset($motives);
224
    }
225
}
226