Test Failed
Pull Request — 1.x (#84)
by
unknown
03:53
created

ValidIban::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 3
dl 0
loc 5
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Milwad\LaravelValidate\Rules;
4
5
use Closure;
6
use Illuminate\Contracts\Validation\ValidationRule;
0 ignored issues
show
Bug introduced by
The type Illuminate\Contracts\Validation\ValidationRule was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Milwad\LaravelValidate\Traits\IbanTrait;
8
use Milwad\LaravelValidate\Utils\Country;
9
10
class ValidIban implements ValidationRule
11
{
12
    use IbanTrait;
13
14
    /**
15
     * Character map
16
     *
17
     * @var array|int[]
18
     */
19
    private array $characterMap = [
0 ignored issues
show
introduced by
The private property $characterMap is not used, and could be removed.
Loading history...
20
        'A' => 10,
21
        'B' => 11,
22
        'C' => 12,
23
        'D' => 13,
24
        'E' => 14,
25
        'F' => 15,
26
        'G' => 16,
27
        'H' => 17,
28
        'I' => 18,
29
        'J' => 19,
30
        'K' => 20,
31
        'L' => 21,
32
        'M' => 22,
33
        'N' => 23,
34
        'O' => 24,
35
        'P' => 25,
36
        'Q' => 26,
37
        'R' => 27,
38
        'S' => 28,
39
        'T' => 29,
40
        'U' => 30,
41
        'V' => 31,
42
        'W' => 32,
43
        'X' => 33,
44
        'Y' => 34,
45
        'Z' => 35,
46
    ];
47
48
    /**
49
     * Get country code with length.
50
     *
51
     * @var array|int[]
52
     */
53
    private array $ibanLengthByCountry = [
0 ignored issues
show
introduced by
The private property $ibanLengthByCountry is not used, and could be removed.
Loading history...
54
        Country::ALBANIA => 28,
55
        Country::ALGERIA => 26,
56
        Country::ANDORRA => 24,
57
        Country::ANGOLA => 25,
58
        Country::AUSTRIA => 20,
59
        Country::AZERBAIJAN => 28,
60
        Country::BAHRAIN => 22,
61
        Country::BELARUS => 28,
62
        Country::BELGIUM => 16,
63
        Country::BENIN => 28,
64
        Country::BOSNIA_HERZEGOVINA => 20,
65
        Country::BRAZIL => 29,
66
        Country::BULGARIA => 22,
67
        Country::BURKINA_FASO => 28,
68
        Country::BURUNDI => 28,
69
        Country::CAMEROON => 27,
70
        Country::CAPE_VERDE => 25,
71
        Country::CENTRAL_AFRICAN_REPUBLIC => 27,
72
        Country::CHAD => 27,
73
        Country::COMOROS => 27,
74
        Country::CONGO => 27,
75
        Country::COSTA_RICA => 22,
76
        Country::CROATIA => 21,
77
        Country::CYPRUS => 28,
78
        Country::CZECH_REPUBLIC => 24,
79
        Country::DENMARK => 18,
80
        Country::DJIBOUTI => 27,
81
        Country::DOMINICAN_REPUBLIC => 28,
82
        Country::EGYPT => 29,
83
        Country::EL_SALVADOR => 28,
84
        Country::EQUATORIAL_GUINEA => 27,
85
        Country::ESTONIA => 20,
86
        Country::FAROE_ISLANDS => 18,
87
        Country::FINLAND => 18,
88
        Country::FRANCE => 27,
89
        Country::GABON => 27,
90
        Country::GEORGIA => 22,
91
        Country::GERMANY => 22,
92
        Country::GIBRALTAR => 23,
93
        Country::GREECE => 27,
94
        Country::GREENLAND => 18,
95
        Country::GUATEMALA => 28,
96
        Country::GUINEA_BISSAU => 25,
97
        Country::HOLY_SEE => 22,
98
        Country::HONDURAS => 28,
99
        Country::HUNGARY => 28,
100
        Country::ICELAND => 26,
101
        Country::IRAN => 26,
102
        Country::IRAQ => 23,
103
        Country::IRELAND => 22,
104
        Country::ISRAEL => 23,
105
        Country::ITALY => 27,
106
        Country::IVORY_COAST => 28,
107
        Country::JORDAN => 30,
108
        Country::KAZAKHSTAN => 20,
109
        Country::KOSOVO => 20,
110
        Country::KUWAIT => 30,
111
        Country::LATVIA => 21,
112
        Country::LEBANON => 28,
113
        Country::LIBYA => 25,
114
        Country::LIECHTENSTEIN => 21,
115
        Country::LITHUANIA => 20,
116
        Country::LUXEMBOURG => 20,
117
        Country::MADAGASCAR => 27,
118
        Country::MALI => 28,
119
        Country::MALTA => 31,
120
        Country::MAURITANIA => 27,
121
        Country::MAURITIUS => 30,
122
        Country::MOLDOVA => 24,
123
        Country::MONACO => 27,
124
        Country::MONGOLIA => 20,
125
        Country::MONTENEGRO => 22,
126
        Country::MOROCCO => 28,
127
        Country::MOZAMBIQUE => 25,
128
        Country::NETHERLANDS => 18,
129
        Country::NICARAGUA => 32,
130
        Country::NIGER => 28,
131
        Country::NORTH_MACEDONIA => 19,
132
        Country::NORWAY => 15,
133
        Country::PAKISTAN => 24,
134
        Country::PALESTINE => 29,
135
        Country::POLAND => 28,
136
        Country::PORTUGAL => 25,
137
        Country::QATAR => 29,
138
        Country::ROMANIA => 24,
139
        Country::RUSSIA => 33,
140
        Country::SAINT_LUCIA => 32,
141
        Country::SAN_MARINO => 27,
142
        Country::SAO_TOME_PRINCIPE => 25,
143
        Country::SAUDI_ARABIA => 24,
144
        Country::SENEGAL => 28,
145
        Country::SERBIA => 22,
146
        Country::SEYCHELLES => 31,
147
        Country::SLOVAKIA => 24,
148
        Country::SLOVENIA => 19,
149
        Country::SOMALIA => 23,
150
        Country::SPAIN => 24,
151
        Country::SUDAN => 18,
152
        Country::SWEDEN => 24,
153
        Country::SWITZERLAND => 21,
154
        Country::TIMOR_LESTE => 23,
155
        Country::TOGO => 28,
156
        Country::TUNISIA => 24,
157
        Country::TURKEY => 26,
158
        Country::UKRAINE => 29,
159
        Country::UNITED_ARAB_EMIRATES => 23,
160
        Country::UNITED_KINGDOM => 22,
161
        Country::VIRGIN_ISLANDS_BRITISH => 24,
162
    ];
163
164
    /**
165
     * Set multiple country codes to validate IBAN (Optional).
166
     */
167
    private array $countries;
0 ignored issues
show
introduced by
The private property $countries is not used, and could be removed.
Loading history...
168
169
    public function __construct(array|string $countries = [])
170
    {
171
        $this->setCountries(func_get_args());
172
    }
173
174
    /**
175
     * Check IBAN.
176
     *
177
     * @param string $attribute
178
     * @param mixed $value
179
     * @param Closure $fail
180
     * @return void
181
     */
182
    public function validate(string $attribute, mixed $value, Closure $fail): void
183
    {
184
        if (! $this->isIbanValid($value)) {
185
186
            $fail('validate.iban')->translate();
187
        }
188
    }
189
}
190