Spk::parseStatementStartPrice()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Kingsquare\Parser\Banking\Mt940\Engine;
4
5
use Kingsquare\Parser\Banking\Mt940\Engine;
6
7
/**
8
 * @author Timotheus Pokorra ([email protected])
9
 * @license http://opensource.org/licenses/MIT MIT
10
 *
11
 * This is for german banks, for example Sparkasse
12
 */
13
class Spk extends Engine
14
{
15
    /**
16
     * returns the name of the bank.
17
     *
18
     * @return string
19
     */
20
    protected function parseStatementBank()
21
    {
22
        return 'Spk';
23
    }
24
25
    /**
26
     * Overloaded: Sparkasse uses 60M and 60F.
27
     *
28
     * @inheritdoc
29
     */
30
    protected function parseStatementStartPrice()
31
    {
32
        return $this->parseStatementPrice('60[FM]');
33
    }
34
35
    /**
36
     * Overloaded: Sparkasse uses 60M and 60F.
37
     *
38
     * @inheritdoc
39
     */
40
    protected function parseStatementStartTimestamp()
41
    {
42
        return $this->parseTimestampFromStatement('60[FM]');
43
    }
44
45
    /**
46
     * Overloaded: Sparkasse uses 60M and 60F.
47
     *
48
     * @inheritdoc
49
     */
50
    protected function parseStatementEndTimestamp()
51
    {
52
        return $this->parseTimestampFromStatement('60[FM]');
53
    }
54
55
    /**
56
     * Overloaded: Sparkasse uses 62M and 62F.
57
     *
58
     * @inheritdoc
59
     */
60
    protected function parseStatementEndPrice()
61
    {
62
        return $this->parseStatementPrice('62[FM]');
63
    }
64
65
    /**
66
     * Overloaded: Sparkasse can have the 3rd character of the currencyname after the C/D
67
     * currency codes last letter is always a letter http://www.xe.com/iso4217.php.
68
     *
69
     * @inheritdoc
70
     */
71
    protected function parseTransactionPrice()
72
    {
73
        $results = [];
74
        if (preg_match('/^:61:.*?[CD][a-zA-Z]?([\d,\.]+)N/i', $this->getCurrentTransactionData(), $results)
75
            && !empty($results[1])
76
        ) {
77
            return $this->sanitizePrice($results[1]);
78
        }
79
80
        return 0;
81
    }
82
83
    /**
84
     * Overloaded: Sparkasse can have the 3rd character of the currencyname after the C/D and an "R" for cancellation befor the C/D.
85
     *
86
     * @inheritdoc
87
     */
88
    protected function parseTransactionDebitCredit()
89
    {
90
        $results = [];
91
        if (preg_match('/^:61:\d+R?([CD]).?\d+/', $this->getCurrentTransactionData(), $results)
92
            && !empty($results[1])
93
        ) {
94
            return $this->sanitizeDebitCredit($results[1]);
95
        }
96
97
        return '';
98
    }
99
100
    /**
101
     * Overloaded: Sparkasse use the Field 61 for cancellations
102
     *
103
     * @inheritdoc
104
     */
105
    protected function parseTransactionCancellation()
106
    {
107
        $results = [];
108
        return preg_match('/^:61:\d+(R)?[CD].?\d+/', $this->getCurrentTransactionData(), $results)
109
            && !empty($results[1]);
110
    }
111
112
    /**
113
     * Overloaded: Sparkasse does not have a header line.
114
     *
115
     * @inheritdoc
116
     */
117
    protected function parseStatementData()
118
    {
119
        return preg_split(
120
            '/(^:20:|^-X{,3}$|\Z)/m',
121
            $this->getRawData(),
122
            -1,
123
            PREG_SPLIT_NO_EMPTY
124
        );
125
    }
126
127
    /**
128
     * Overloaded: Is applicable if first or second line has :20:STARTUMS or first line has -.
129
     *
130
     * @inheritdoc
131
     */
132
    public static function isApplicable($string)
133
    {
134
        $firstline = strtok($string, "\r\n\t");
135
        $secondline = strtok("\r\n\t");
136
137
        return strpos($firstline, ':20:STARTUMS') !== false || ($firstline === '-' && $secondline === ':20:STARTUMS');
138
    }
139
}
140