Completed
Branch master (67de1a)
by Markus
04:26 queued 01:55
created

GetAccounts::getAccountsArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Fhp\Response;
4
5
use Fhp\Model\Account;
6
7
/**
8
 * Class GetAccounts
9
 * @package Fhp\Response
10
 */
11
class GetAccounts extends Response
12
{
13
    const SEG_ACCOUNT_INFORMATION = 'HIUPD';
14
15
    /** @var array */
16
    protected $accounts = array();
17
18
    /**
19
     * @return array
20
     */
21
    public function getAccountsArray()
22
    {
23
        $accounts = $this->findSegments(static::SEG_ACCOUNT_INFORMATION);
24
25
        foreach ($accounts as $account) {
0 ignored issues
show
Bug introduced by
The expression $accounts of type array|null|string is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
26
            $accountParts = $this->splitSegment($account);
27
            $this->accounts[] = $this->createModelFromArray($accountParts);
28
        }
29
30
        return $this->accounts;
31
    }
32
33
    /**
34
     * Creates a Account model from array.
35
     *
36
     * @param array $array
37
     * @return Account
38
     */
39
    protected function createModelFromArray(array $array)
40
    {
41
        $account = new Account();
42
        list($accountNumber, $x, $countryCode, $bankCode) = explode(':', $array[1]);
0 ignored issues
show
Unused Code introduced by
The assignment to $x is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $countryCode is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
43
        $account->setId($array[1]);
44
        $account->setAccountNumber($accountNumber);
45
        $account->setBankCode($bankCode);
46
        $account->setIban($array[2]);
47
        $account->setCustomerId($array[3]);
48
        $account->setCurrency($array[5]);
49
        $account->setAccountOwnerName($array[6]);
50
        $account->setAccountDescription($array[8]);
51
52
        return $account;
53
    }
54
}
55