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

Btrl   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parseStatementBank() 0 3 1
A isApplicable() 0 5 1
A parseTransactionPrice() 0 10 3
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