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

Spk   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 131
Duplicated Lines 16.79 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 12
Bugs 3 Features 4
Metric Value
wmc 18
c 12
b 3
f 4
lcom 1
cbo 1
dl 22
loc 131
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A parseStatementBank() 0 4 1
A parseStatementStartPrice() 0 4 1
A parseStatementStartTimestamp() 0 4 1
A parseStatementEndTimestamp() 0 4 1
A parseStatementEndPrice() 0 4 1
A parseTransactionPrice() 11 11 3
A parseTransactionDebitCredit() 11 11 3
A parseTransactionCancellation() 0 10 3
A parseStatementData() 0 9 1
A isApplicable() 0 7 3

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 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 parent::parseStatementPrice('60[FM]');
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (parseStatementPrice() instead of parseStatementStartPrice()). Are you sure this is correct? If so, you might want to change this to $this->parseStatementPrice().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
33
    }
34
35
    /**
36
     * Overloaded: Sparkasse uses 60M and 60F.
37
     *
38
     * {@inheritdoc}
39
     */
40
    protected function parseStatementStartTimestamp()
41
    {
42
        return parent::parseTimestampFromStatement('60[FM]');
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (parseTimestampFromStatement() instead of parseStatementStartTimestamp()). Are you sure this is correct? If so, you might want to change this to $this->parseTimestampFromStatement().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
43
    }
44
45
    /**
46
     * Overloaded: Sparkasse uses 60M and 60F.
47
     *
48
     * {@inheritdoc}
49
     */
50
    protected function parseStatementEndTimestamp()
51
    {
52
        return parent::parseTimestampFromStatement('60[FM]');
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (parseTimestampFromStatement() instead of parseStatementEndTimestamp()). Are you sure this is correct? If so, you might want to change this to $this->parseTimestampFromStatement().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
53
    }
54
55
    /**
56
     * Overloaded: Sparkasse uses 62M and 62F.
57
     *
58
     * {@inheritdoc}
59
     */
60
    protected function parseStatementEndPrice()
61
    {
62
        return parent::parseStatementPrice('62[FM]');
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (parseStatementPrice() instead of parseStatementEndPrice()). Are you sure this is correct? If so, you might want to change this to $this->parseStatementPrice().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
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 View Code Duplication
    protected function parseTransactionPrice()
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...
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 View Code Duplication
    protected function parseTransactionDebitCredit()
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...
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
        if (preg_match('/^:61:\d+(R)?[CD].?\d+/', $this->getCurrentTransactionData(), $results)
109
            && !empty($results[1])
110
        ) {
111
            return true;
112
        }
113
        return false;
114
    }
115
116
    /**
117
     * Overloaded: Sparkasse does not have a header line.
118
     *
119
     * {@inheritdoc}
120
     */
121
    protected function parseStatementData()
122
    {
123
        return preg_split(
124
                '/(^:20:|^-X{,3}$|\Z)/sm',
125
                $this->getRawData(),
126
                -1,
127
                PREG_SPLIT_NO_EMPTY
128
        );
129
    }
130
131
    /**
132
     * Overloaded: Is applicable if first or second line has :20:STARTUMS or first line has -.
133
     *
134
     * {@inheritdoc}
135
     */
136
    public static function isApplicable($string)
137
    {
138
        $firstline = strtok($string, "\r\n\t");
139
        $secondline = strtok("\r\n\t");
140
141
        return strpos($firstline, ':20:STARTUMS') !== false || $firstline === '-' && $secondline === ':20:STARTUMS';
142
    }
143
}
144