1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MidasSoft\DominicanBankParser\Validators; |
4
|
|
|
|
5
|
|
|
use MidasSoft\DominicanBankParser\Interfaces\ValidatorInterface; |
6
|
|
|
|
7
|
|
|
class PopularValidator implements ValidatorInterface |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* {@inheritdoc} |
11
|
|
|
*/ |
12
|
2 |
|
public static function validate(array $deposit) |
13
|
|
|
{ |
14
|
|
|
$deposit = array_map(function ($value) { |
15
|
2 |
|
return utf8_decode($value); |
16
|
2 |
|
}, $deposit); |
17
|
|
|
|
18
|
2 |
|
if (!self::shortDescriptionIsSet($deposit[1]) && !self::amountIsSet($deposit[2]) && !self::longDescriptionIsSet($deposit[5])) { |
19
|
|
|
return false; |
20
|
|
|
} |
21
|
|
|
|
22
|
2 |
|
if (!self::isValidDate($deposit[0])) { |
23
|
|
|
return false; |
24
|
|
|
} |
25
|
|
|
|
26
|
2 |
|
if (self::isHeader($deposit[2])) { |
27
|
|
|
return false; |
28
|
|
|
} |
29
|
|
|
|
30
|
2 |
|
if (self::isCommision($deposit[1])) { |
31
|
2 |
|
return false; |
32
|
|
|
} |
33
|
|
|
|
34
|
2 |
|
if (self::isTax($deposit[5])) { |
35
|
|
|
return false; |
36
|
|
|
} |
37
|
|
|
|
38
|
2 |
|
return true; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Checks if the deposit is a tax payment. |
43
|
|
|
* |
44
|
|
|
* @param string $longDescription |
45
|
|
|
* |
46
|
|
|
* @return bool |
47
|
|
|
*/ |
48
|
2 |
|
private static function isTax($longDescription) |
49
|
|
|
{ |
50
|
2 |
|
return substr(utf8_decode($longDescription), 0, 13) == 'PAGO IMPUESTO'; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Checks if the deposit is a commision payment. |
55
|
|
|
* |
56
|
|
|
* @param string $shortDescription |
57
|
|
|
* |
58
|
|
|
* @return bool |
59
|
|
|
*/ |
60
|
2 |
|
private static function isCommision($shortDescription) |
61
|
|
|
{ |
62
|
2 |
|
return in_array(utf8_decode($shortDescription), ['DB Comisiones', 'D?bito Cuenta']); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Checks if the current line is a header. |
67
|
|
|
* |
68
|
|
|
* @param string $amount |
69
|
|
|
* |
70
|
|
|
* @return bool |
71
|
|
|
*/ |
72
|
2 |
|
private static function isHeader($amount) |
73
|
|
|
{ |
74
|
2 |
|
return substr($amount, 0, 5) == 'Monto Transac'; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Checks if the date is valid. |
79
|
|
|
* |
80
|
|
|
* @param string $date |
81
|
|
|
* |
82
|
|
|
* @return bool |
83
|
|
|
*/ |
84
|
2 |
|
private static function isValidDate($date) |
85
|
|
|
{ |
86
|
2 |
|
return boolval(preg_match('/^([0-9]{1,2})\\/([0-9]{1,2})\\/([0-9]{4})$/', $date)); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Checks if the short description is set. |
91
|
|
|
* |
92
|
|
|
* @param string $description |
93
|
|
|
* |
94
|
|
|
* @return bool |
95
|
|
|
*/ |
96
|
2 |
|
private static function shortDescriptionIsSet($description) |
97
|
|
|
{ |
98
|
2 |
|
return isset($description); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Checks if the amount is set. |
103
|
|
|
* |
104
|
|
|
* @param string $amount |
105
|
|
|
* |
106
|
|
|
* @return bool |
107
|
|
|
*/ |
108
|
|
|
private static function amountIsSet($amount) |
109
|
|
|
{ |
110
|
|
|
return isset($amount); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Checks if the amount is set. |
115
|
|
|
* |
116
|
|
|
* @param string $description |
117
|
|
|
* |
118
|
|
|
* @return bool |
119
|
|
|
*/ |
120
|
|
|
private static function longDescriptionIsSet($description) |
121
|
|
|
{ |
122
|
|
|
return isset($description); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|