Passed
Push — master ( 2c0c97...e77480 )
by Robin
01:12
created

Sns::filterMetaDataFromDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Kingsquare\Parser\Banking\Mt940\Engine;
4
5
use Kingsquare\Parser\Banking\Mt940\Engine;
6
7
/**
8
 * **CAUTION** This is an untested / experimental engine for SNS
9
 *
10
 *
11
 * @package Kingsquare\Parser\Banking\Mt940\Engine
12
 * @author Paul Olthof ([email protected])
13
 * @license http://opensource.org/licenses/MIT MIT
14
 */
15
class Sns extends Engine
16
{
17
    /**
18
     * returns the name of the bank
19
     * @return string
20
     */
21
    protected function parseStatementBank()
22
    {
23
        return 'SNS';
24
    }
25
26
    /**
27
     * @override just return the unsanitized IBAN string
28
     * @inheritdoc
29
     */
30
    protected function sanitizeAccount($string)
31
    {
32
        return $string;
33
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38
    protected function parseTransactionAccount()
39
    {
40
        $results = [];
41
        if (preg_match('/^:86:\s?([A-z\d]+)\s/im', $this->getCurrentTransactionData(), $results)
42
            && !empty($results[1])
43
        ) {
44
            return $this->sanitizeAccount($results[1]);
45
        }
46
47
        return '';
48
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53
    protected function parseTransactionAccountName()
54
    {
55
        $results = [];
56
        if (preg_match('/^:86:\s?[A-z\d]+\s(.*?)$/im', $this->getCurrentTransactionData(), $results)
57
            && !empty($results[1])
58
        ) {
59
            return strtoupper($this->sanitizeAccountName($results[1]));
60
        }
61
62
        return '';
63
    }
64
65
    /**
66
     * @override filter out the first two meta-data lines
67
     * @inheritdoc
68
     */
69
    protected function parseTransactionDescription()
70
    {
71
        $results = [];
72
        if (preg_match_all('/[\n]:86:(.*?)(?=\n(:6(1|2))|$)/s', $this->getCurrentTransactionData(), $results)
73
            && !empty($results[1])
74
        ) {
75
            // filter out meta data
76
            $lines = explode("\r\n", $results[1][0]);
77
            unset($lines[0], $lines[1]);
78
            $results[1][0] = implode("\r\n", $lines);
79
80
            return $this->sanitizeDescription(implode(PHP_EOL, $results[1]));
81
        }
82
83
        return '';
84
    }
85
86
}
87