Completed
Pull Request — master (#24)
by Sam
02:37
created

Knab   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 49
Duplicated Lines 18.37 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 10
c 1
b 0
f 1
lcom 1
cbo 1
dl 9
loc 49
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A parseStatementBank() 0 4 1
A parseTransactionAccount() 0 11 3
A parseTransactionAccountName() 9 9 3
A parseTransactionDescription() 0 6 2
A isApplicable() 0 5 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
namespace Kingsquare\Parser\Banking\Mt940\Engine;
3
4
use Kingsquare\Parser\Banking\Mt940\Engine;
5
6
/**
7
 * Knab parser for Kingsquare mt940 package.
8
 *
9
 * @package Kingsquare\Parser\Banking\Mt940\Engine
10
 * @author Kingsquare ([email protected])
11
 * @author Sam Mousa ([email protected])
12
 * @license http://opensource.org/licenses/MIT MIT
13
 */
14
class Knab extends Engine
15
{
16
    const IBAN = '[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}(?:[a-zA-Z0-9]?){0,16}';
17
    /**
18
     * returns the name of the bank
19
     * @return string
20
     */
21
    protected function parseStatementBank()
22
    {
23
        return 'KNAB';
24
    }
25
26
    protected function parseTransactionAccount()
27
    {
28
        $results = [];
29
30
        $pattern = '/^:86:.*?REK:\s*(?<account>' . self::IBAN . '|\d+)/ims';
31
        if (preg_match($pattern, $this->getCurrentTransactionData(), $results)
32
            && !empty($results['account'])
33
        ) {
34
            return $results['account'];
35
        }
36
    }
37
38 View Code Duplication
    protected function parseTransactionAccountName()
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...
39
    {
40
        $results = [];
41
        if (preg_match('/^:86:.*?\/NAAM: (.*?)\s*:\d{2}.?:/ims', $this->getCurrentTransactionData(), $results)
42
            && !empty($results[1])
43
        ) {
44
            return $results[1];
45
        }
46
    }
47
48
    protected function parseTransactionDescription()
49
    {
50
        if (preg_match('/^:86:(.*?)REK:/ims', $this->getCurrentTransactionData(), $results)) {
51
            return $results[1];
52
        }
53
    }
54
55
    public static function isApplicable($string)
56
    {
57
        $firstline = strtok($string, "\r\n\t");
58
        return strpos($firstline, 'F01KNABNL2HAXXX0000000000') !== false;
59
    }
60
61
62
}
63