Completed
Push — master ( 26e69a...ab0b77 )
by Robin
03:27
created

Rabo::sanitizeDescription()   B

Complexity

Conditions 7
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 16
Ratio 100 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 16
loc 16
rs 8.2222
cc 7
eloc 9
nc 3
nop 1
1
<?php
2
3
namespace Kingsquare\Parser\Banking\Mt940\Engine;
4
5
use Kingsquare\Parser\Banking\Mt940\Engine;
6
7
/**
8
 * @author Kingsquare ([email protected])
9
 * @license http://opensource.org/licenses/MIT MIT
10
 */
11
class Rabo extends Engine
12
{
13
    /**
14
     * returns the name of the bank.
15
     *
16
     * @return string
17
     */
18
    protected function parseStatementBank()
19
    {
20
        return 'Rabo';
21
    }
22
23
    /**
24
     * Overloaded: Rabo has different way of storing account info.
25
     *
26
     * {@inheritdoc}
27
     */
28 View Code Duplication
    protected function parseTransactionAccount()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        $results = [];
31
        // SEPA MT940 Structured
32
        if (preg_match('/^:61:.*\n(.*?)(\n|\:8)/im', $this->getCurrentTransactionData(), $results)
33
                && !empty($results[1])
34
        ) {
35
            return $this->sanitizeAccount($results[1]);
36
        }
37
38
        if (preg_match('/^:61:.{26}(.{16})/im', $this->getCurrentTransactionData(), $results)
39
                && !empty($results[1])
40
        ) {
41
            return $this->sanitizeAccount($results[1]);
42
        }
43
44
        return '';
45
    }
46
47
    /**
48
     * Overloaded: Rabo has different way of storing account name.
49
     *
50
     * {@inheritdoc}
51
     */
52
    protected function parseTransactionAccountName()
53
    {
54
        $results = [];
55
        // SEPA MT940 Structured
56 View Code Duplication
        if (preg_match('#/NAME/(.*?)/(REMI|ADDR)/#ms', $this->getCurrentTransactionData(), $results)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
                && !empty($results[1])
58
        ) {
59
            $accountName = trim($results[1]);
60
            if (!empty($accountName)) {
61
                return $this->sanitizeAccountName($accountName);
62
            }
63
        }
64
65 View Code Duplication
        if (preg_match('/^:61:.*? (.*)/m', $this->getCurrentTransactionData(), $results) && !empty($results[1])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
            $accountName = trim($results[1]);
67
            if (!empty($accountName)) {
68
                return $this->sanitizeAccountName($accountName);
69
            }
70
        }
71
72
        return '';
73
    }
74
75
    /**
76
     * Overloaded: Rabo has different way of storing transaction value timestamps (ymd).
77
     *
78
     * {@inheritdoc}
79
     */
80
    protected function parseTransactionEntryTimestamp()
81
    {
82
        $results = [];
83
        if (preg_match('/^:60F:[C|D]([\d]{6})/m', $this->getCurrentStatementData(), $results) && !empty($results[1])) {
84
            return $this->sanitizeTimestamp($results[1], 'ymd');
85
        }
86
87
        return 0;
88
    }
89
90
    /**
91
     * Overloaded: Rabo has different way of storing transaction value timestamps (ymd).
92
     *
93
     * {@inheritdoc}
94
     */
95 View Code Duplication
    protected function parseTransactionValueTimestamp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
    {
97
        $results = [];
98
        if (preg_match('/^:61:([\d]{6})[C|D]/', $this->getCurrentTransactionData(), $results) && !empty($results[1])) {
99
            return $this->sanitizeTimestamp($results[1], 'ymd');
100
        }
101
102
        return 0;
103
    }
104
105
    /**
106
     * Overloaded: Rabo uses longer strings for accountnumbers.
107
     *
108
     * {@inheritdoc}
109
     */
110
    protected function sanitizeAccount($string)
111
    {
112
        $account = parent::sanitizeAccount($string);
113
        if (strlen($account) > 20 && strpos($account, '80000') == 0) {
114
            $account = substr($account, 5);
115
        }
116
117
        return $account;
118
    }
119
120
    /**
121
     * Overloaded: Rabo encapsulates the description with /REMI/ for SEPA.
122
     *
123
     * {@inheritdoc}
124
     */
125 View Code Duplication
    protected function sanitizeDescription($string)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
126
    {
127
        $description = parent::sanitizeDescription($string);
128
        if (strpos($description, '/REMI/') !== false
129
                && preg_match('#/REMI/(.*?)/(ISDT|CSID|RTRN)/#s', $description, $results) && !empty($results[1])
130
        ) {
131
            return $results[1];
132
        }
133
        if (strpos($description, '/EREF/') !== false
134
                && preg_match('#/EREF/(.*?)/(ORDP)/#s', $description, $results) && !empty($results[1])
135
        ) {
136
            return $results[1];
137
        }
138
139
        return $description;
140
    }
141
142
    /**
143
     * Overloaded: Is applicable if first line has :940:.
144
     *
145
     * {@inheritdoc}
146
     */
147
    public static function isApplicable($string)
148
    {
149
        $firstline = strtok($string, "\r\n\t");
150
151
        return strpos($firstline, ':940:') !== false;
152
    }
153
}
154