Completed
Push — rabo-pref ( e7e1b8 )
by Robin
01:58
created

Rabo   A

Complexity

Total Complexity 33

Size/Duplication

Total Lines 153
Duplicated Lines 45.1 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 7
Bugs 0 Features 1
Metric Value
wmc 33
c 7
b 0
f 1
lcom 1
cbo 1
dl 69
loc 153
rs 9.3999

8 Methods

Rating   Name   Duplication   Size   Complexity  
A parseStatementBank() 0 4 1
B parseTransactionAccount() 18 18 5
A parseTransactionValueTimestamp() 9 9 3
A sanitizeAccount() 0 9 3
C parseTransactionAccountName() 18 26 7
A parseTransactionEntryTimestamp() 9 9 3
C sanitizeDescription() 15 22 10
A isApplicable() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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})/m', $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/(.+?)\n?/(REMI|ADDR|ISDT|CSID)/#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
            $accountName = trim($results[1]);
58
            if (!empty($accountName)) {
59
                return $this->sanitizeAccountName($accountName);
60
            }
61
        }
62
63 View Code Duplication
        if (preg_match('/^:61:.*? (.+)/m', $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...
64
            $accountName = trim($results[1]);
65
            if (!empty($accountName)) {
66
                return $this->sanitizeAccountName($accountName);
67
            }
68
        }
69
70 View Code Duplication
        if (preg_match('/(.*) Betaalautomaat/', $this->parseTransactionDescription(), $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...
71
            $accountName = trim($results[1]);
72
            if (!empty($accountName)) {
73
                return $this->sanitizeAccountName($accountName);
74
            }
75
        }
76
        return '';
77
    }
78
79
    /**
80
     * Overloaded: Rabo has different way of storing transaction value timestamps (ymd).
81
     *
82
     * {@inheritdoc}
83
     */
84 View Code Duplication
    protected function parseTransactionEntryTimestamp()
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...
85
    {
86
        $results = [];
87
        if (preg_match('/^:60F:[C|D]([\d]{6})/m', $this->getCurrentStatementData(), $results) && !empty($results[1])) {
88
            return $this->sanitizeTimestamp($results[1], 'ymd');
89
        }
90
91
        return 0;
92
    }
93
94
    /**
95
     * Overloaded: Rabo has different way of storing transaction value timestamps (ymd).
96
     *
97
     * {@inheritdoc}
98
     */
99 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...
100
    {
101
        $results = [];
102
        if (preg_match('/^:61:([\d]{6})[C|D]/', $this->getCurrentTransactionData(), $results) && !empty($results[1])) {
103
            return $this->sanitizeTimestamp($results[1], 'ymd');
104
        }
105
106
        return 0;
107
    }
108
109
    /**
110
     * Overloaded: Rabo uses longer strings for accountnumbers.
111
     *
112
     * {@inheritdoc}
113
     */
114
    protected function sanitizeAccount($string)
115
    {
116
        $account = parent::sanitizeAccount($string);
117
        if (strlen($account) > 20 && strpos($account, '80000') === 0) {
118
            $account = substr($account, 5);
119
        }
120
121
        return $account;
122
    }
123
124
    /**
125
     * Overloaded: Rabo encapsulates the description with /REMI/ for SEPA.
126
     *
127
     * {@inheritdoc}
128
     */
129
    protected function sanitizeDescription($string)
130
    {
131
        $description = parent::sanitizeDescription($string);
132 View Code Duplication
        if (strpos($description, '/REMI/') !== false
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...
133
                && preg_match('#/REMI/(.*?)(/((PURP|ISDT|CSID|RTRN)/)|$)#s', $description, $results) && !empty($results[1])
134
        ) {
135
            return $results[1];
136
        }
137 View Code Duplication
        if (strpos($description, '/EREF/') !== false
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...
138
                && preg_match('#/EREF/(.*?)/(ORDP)/#s', $description, $results) && !empty($results[1])
139
        ) {
140
            return $results[1];
141
        }
142
143 View Code Duplication
        if (strpos($description, '/PREF/') !== false
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...
144
                    && preg_match('#/PREF/(.*)/?#s', $description, $results) && !empty($results[1])
145
        ) {
146
            return $results[1];
147
        }
148
149
        return $description;
150
    }
151
152
    /**
153
     * Overloaded: Is applicable if first line has :940:.
154
     *
155
     * {@inheritdoc}
156
     */
157
    public static function isApplicable($string)
158
    {
159
        $firstline = strtok($string, "\r\n\t");
160
161
        return strpos($firstline, ':940:') !== false;
162
    }
163
}
164