BHDValidator   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Test Coverage

Coverage 90.48%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 92
ccs 19
cts 21
cp 0.9048
rs 10
c 0
b 0
f 0
wmc 13

7 Methods

Rating   Name   Duplication   Size   Complexity  
A isWithdraw() 0 3 1
A referenceIsSet() 0 3 1
A amountIsZero() 0 3 1
A amountIsSet() 0 3 1
A dateIsSet() 0 3 1
A isAnnulment() 0 3 1
B validate() 0 15 7
1
<?php
2
3
namespace MidasSoft\DominicanBankParser\Validators;
4
5
use MidasSoft\DominicanBankParser\Interfaces\ValidatorInterface;
6
7
class BHDValidator implements ValidatorInterface
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12 2
    public static function validate(array $deposit)
13
    {
14 2
        if (!self::dateIsSet($deposit[0]) || !self::referenceIsSet($deposit[4]) || !self::amountIsSet($deposit[6])) {
15
            return false;
16
        }
17
18 2
        if (self::amountIsZero($deposit[6])) {
19 2
            return false;
20
        }
21
22 2
        if (self::isWithdraw($deposit[4]) || self::isAnnulment($deposit[4])) {
23
            return false;
24
        }
25
26 2
        return true;
27
    }
28
29
    /**
30
     * Checks if the amount is equal to zero.
31
     *
32
     * @param int $amount
33
     *
34
     * @return bool
35
     */
36 2
    private static function amountIsZero($amount)
37
    {
38 2
        return $amount == 0;
39
    }
40
41
    /**
42
     * Checks if date is set.
43
     *
44
     * @param string $date
45
     *
46
     * @return bool
47
     */
48 2
    private static function dateIsSet($date)
49
    {
50 2
        return isset($date);
51
    }
52
53
    /**
54
     * Checks if reference is set.
55
     *
56
     * @param string $reference
57
     *
58
     * @return bool
59
     */
60 2
    private static function referenceIsSet($reference)
61
    {
62 2
        return isset($reference);
63
    }
64
65
    /**
66
     * Checks if amount is set.
67
     *
68
     * @param string $amount
69
     *
70
     * @return bool
71
     */
72 2
    private static function amountIsSet($amount)
73
    {
74 2
        return isset($amount);
75
    }
76
77
    /**
78
     * Checks if the deposit is a withdraw.
79
     *
80
     * @param string $description
81
     *
82
     * @return bool
83
     */
84 2
    private static function isWithdraw($description)
85
    {
86 2
        strpos(utf8_decode($description), 'Retiro Ahorros CA') != 0;
87 2
    }
88
89
    /**
90
     * Checks if amount is set.
91
     *
92
     * @param string $description
93
     *
94
     * @return bool
95
     */
96 2
    private static function isAnnulment($description)
97
    {
98 2
        strpos(utf8_decode($description), 'Anul.Deposito') != 0;
99 2
    }
100
}
101