Passed
Push — master ( fc2fbe...67de1a )
by Markus
02:31
created

GetSEPAAccounts::getSEPAAccountsArray()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 11
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 2
nop 0
crap 12
1
<?php
2
3
namespace Fhp\Response;
4
5
use Fhp\Model\SEPAAccount;
6
7
/**
8
 * Class GetSEPAAccounts
9
 * @package Fhp\Response
10
 */
11
class GetSEPAAccounts extends Response
12
{
13
    const SEG_ACCOUNT_INFORMATION = 'HISPA';
14
15
    /** @var array */
16
    protected $accounts = array();
17
18
    /**
19
     * Creates SEPA Account array list with SEPAAccount models.
20
     *
21
     * @return SEPAAccount[]
22
     */
23
    public function getSEPAAccountsArray()
24
    {
25
        $accounts = $this->findSegment(static::SEG_ACCOUNT_INFORMATION);
26
27
        if (is_string($accounts)) {
28
            $accounts = $this->splitSegment($accounts);
29
            array_shift($accounts);
30
            foreach ($accounts as $account) {
31
                $array = $this->splitDeg($account);
32
                $this->accounts[] = $this->createModelFromArray($array);
33
            }
34
        }
35
36
        return $this->accounts;
37
    }
38
39
    /**
40
     * Creates a SEPAAccount model from array.
41
     *
42
     * @param array $array
43
     * @return SEPAAccount
44
     */
45
    protected function createModelFromArray(array $array)
46
    {
47
        $account = new SEPAAccount();
48
        $account->setIban($array[1]);
49
        $account->setBic($array[2]);
50
        $account->setAccountNumber($array[3]);
51
        $account->setSubAccount($array[4]);
52
        $account->setBlz($array[6]);
53
54
        return $account;
55
    }
56
}
57