Mt940::parse()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 4
eloc 8
c 3
b 1
f 0
nc 5
nop 2
dl 0
loc 19
rs 10
1
<?php
2
3
namespace Kingsquare\Parser\Banking;
4
5
use Kingsquare\Parser\Banking;
6
7
/**
8
 * @author Kingsquare ([email protected])
9
 * @license http://opensource.org/licenses/MIT MIT
10
 */
11
class Mt940 extends Banking
12
{
13
    /** @var Banking\Mt940\Engine */
14
    protected $engine;
15
16
    /** @var bool */
17
    public static $removeIBAN = true; // defaults to true for BC
18
19
    /**
20
     * Parse the given string into an array of Banking\Statement objects.
21
     *
22
     * @param string $string
23
     * @param Banking\Mt940\Engine $engine
24
     *
25
     * @return \Kingsquare\Banking\Statement[]
26
     */
27
    public function parse($string, Banking\Mt940\Engine $engine = null)
28
    {
29
        if (!empty($string)) {
30
            // load engine
31
            if ($engine === null) {
32
                $engine = Banking\Mt940\Engine::__getInstance($string);
33
            }
34
35
            $this->engine = $engine;
36
37
            if ($this->engine instanceof Banking\Mt940\Engine) {
0 ignored issues
show
introduced by
$this->engine is always a sub-type of Kingsquare\Parser\Banking\Mt940\Engine.
Loading history...
38
                // parse using the engine
39
                $this->engine->loadString($string);
40
41
                return $this->engine->parse();
42
            }
43
        }
44
45
        return [];
46
    }
47
}
48