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

Knab::isApplicable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
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