Passed
Push — master ( cce8a1...2c0c97 )
by Robin
01:29
created

Sns::parseTransactionAccount()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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