Completed
Push — master ( f4f5ad...3e60e2 )
by Naylon Kessler de
02:45
created

Bank::findMotives()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 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
     * Especies codes.
28
     *
29
     * @var array
30
     */
31
    protected static $especies = [];
32
33
    /**
34
     * Billing instruction.
35
     *
36
     * @var array
37
     */
38
    protected static $instructions = [];
39
40
    /**
41
     * Motives codes.
42
     *
43
     * @var array
44
     */
45
    protected static $motives = [];
46
47
    /**
48
     * Remittance occurrences codes.
49
     *
50
     * @var array
51
     */
52
    protected static $remittanceOccurrences = [];
53
54
    /**
55
     * Return occurrences codes.
56
     *
57
     * @var array
58
     */
59
    protected static $returnOccurrences = [];
60
61
    /**
62
     * @return array
63
     */
64
    public function billing()
65
    {
66
        return static::$billing;
67
    }
68
69
    /**
70
     * Return the payment channels.
71
     *
72
     * @return array
73
     */
74
    public function channels()
75
    {
76
        return static::$channels;
77
    }
78
79
    /**
80
     * Return the default state of itau infos.
81
     *
82
     * @return array
83
     */
84
    abstract public function defaults();
85
86
    /**
87
     * @return array
88
     */
89
    public function documentsPrefixes()
90
    {
91
        return [];
92
    }
93
94
    /**
95
     * Return all available especies.
96
     *
97
     * @return array
98
     */
99
    public function especies()
100
    {
101
        return static::$especies;
102
    }
103
104
    /**
105
     * Return all available emission.
106
     *
107
     * @return array
108
     */
109
    public function emission()
110
    {
111
        return [];
112
    }
113
114
    /**
115
     * Return all available instructions.
116
     *
117
     * @return array
118
     */
119
    public function instructions()
120
    {
121
        return static::$instructions;
122
    }
123
124
    /**
125
     * Return all motives codes.
126
     *
127
     * @param  int  $occurrenceCode
128
     * @return array
129
     */
130
    public function motives($occurrenceCode = null)
131
    {
132
        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...
133
134
        $occurrenceCode = str_pad($occurrenceCode, 2, 0, STR_PAD_LEFT);
135
136
        return $this->findMotives($occurrenceCode);
137
    }
138
139
    /**
140
     * Return all available postage.
141
     *
142
     * @return array
143
     */
144
    public function postage()
145
    {
146
        return [];
147
    }
148
149
    /**
150
     * @return array
151
     */
152
    public function rejectionCodes()
153
    {
154
        return [];
155
    }
156
157
    /**
158
     * Return all occurrences available for remittances.
159
     *
160
     * @return array
161
     */
162
    public function remittanceOccurrences()
163
    {
164
        return static::$remittanceOccurrences;
165
    }
166
167
    /**
168
     * Return all occurrences available for returning.
169
     *
170
     * @return array
171
     */
172
    public function returnOccurrences()
173
    {
174
        return static::$returnOccurrences;
175
    }
176
177
    /**
178
     * Find for a motive group by occurrenceCode.
179
     *
180
     * @param  int  $occurrenceCode
181
     * @return array
182
     */
183
    protected function findMotives($occurrenceCode)
184
    {
185
        $motives = array_filter($motives, function ($key) use ($occurrenceCode) {
0 ignored issues
show
Bug introduced by
The variable $motives seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
186
            return in_array($occurrenceCode, explode(',', $key));
187
        }, ARRAY_FILTER_USE_KEY);
188
189
        return reset($motives);
190
    }
191
}
192