Passed
Pull Request — master (#87)
by
unknown
08:41
created

Btrl::parseTransactionPrice()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 10
rs 10
1
<?php
2
3
namespace Kingsquare\Parser\Banking\Mt940\Engine;
4
5
use Kingsquare\Parser\Banking\Mt940\Engine;
6
7
class Btrl extends Engine
8
{
9
    /**
10
     *
11
     * {@inheritdoc}
12
     * @see \Kingsquare\Parser\Banking\Mt940\Engine::parseStatementBank()
13
     */
14
    protected function parseStatementBank()
15
    {
16
        return 'BTRL';
17
    }
18
	
19
   /**
20
     * uses the 61 field to determine amount/value of the transaction.
21
     *
22
     * @return float
23
     */
24
    protected function parseTransactionPrice()
25
    {
26
        $results = [];
27
        if (preg_match('/^:61:.*?[CD]([\d,\.]+)[NSF]/i', $this->getCurrentTransactionData(), $results)
28
            && !empty($results[1])
29
        ) {
30
            return $this->sanitizePrice($results[1]);
31
        }
32
33
        return 0;
34
    }    
35
	
36
37
    /**
38
     *
39
     * {@inheritdoc}
40
     * @see \Kingsquare\Parser\Banking\Mt940\Engine::isApplicable()
41
     */
42
    public static function isApplicable($string)
43
    {
44
        $firstline = strtok($string, "\r\n\t");
45
46
        return strpos($firstline, 'BTRL') !== false;
47
    }
48
}
49