Completed
Push — scrutinizer ( 42ac6a...7bc18e )
by z38
02:40
created

ForeignCreditTransfer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 90.91%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 1
cbo 3
dl 0
loc 57
ccs 20
cts 22
cp 0.9091
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A asDom() 0 23 2
1
<?php
2
3
namespace Z38\SwissPayment\TransactionInformation;
4
5
use Z38\SwissPayment\BIC;
6
use Z38\SwissPayment\FinancialInstitutionAddress;
7
use Z38\SwissPayment\FinancialInstitutionInterface;
8
use Z38\SwissPayment\IBAN;
9
use Z38\SwissPayment\Money\Money;
10
use Z38\SwissPayment\PostalAddressInterface;
11
12
/**
13
 * ForeignCreditTransfer contains all the information about a foreign (type 6) transaction.
14
 */
15
class ForeignCreditTransfer extends CreditTransfer
16
{
17
    /**
18
     * @var IBAN
19
     */
20
    protected $creditorIBAN;
21
22
    /**
23
     * @var BIC|FinancialInstitutionAddress
24
     */
25
    protected $creditorAgent;
26
27
    /**
28
     * {@inheritdoc}
29
     *
30
     * @param IBAN                            $creditorIBAN  IBAN of the creditor
31
     * @param BIC|FinancialInstitutionAddress $creditorAgent BIC or address of the creditor's financial institution
32
     */
33 3
    public function __construct($instructionId, $endToEndId, Money $amount, $creditorName, PostalAddressInterface $creditorAddress, IBAN $creditorIBAN, FinancialInstitutionInterface $creditorAgent)
34
    {
35 3
        parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress);
36
37 3
        if (!$creditorAgent instanceof BIC && !$creditorAgent instanceof FinancialInstitutionAddress) {
38 1
            throw new \InvalidArgumentException('The creditor agent must be an instance of BIC or FinancialInstitutionAddress.');
39
        }
40
41 2
        $this->creditorIBAN = $creditorIBAN;
42 2
        $this->creditorAgent = $creditorAgent;
0 ignored issues
show
Documentation Bug introduced by
It seems like $creditorAgent can also be of type object<Z38\SwissPayment\...cialInstitutionAddress>. However, the property $creditorAgent is declared as type object<Z38\SwissPayment\BIC>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
43 2
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 2
    public function asDom(\DOMDocument $doc)
49
    {
50 2
        $root = $this->buildHeader($doc);
51
52 2
        $creditorAgent = $doc->createElement('CdtrAgt');
53
54 2
        $creditorAgent->appendChild($this->creditorAgent->asDom($doc));
55 2
        $root->appendChild($creditorAgent);
56
57 2
        $root->appendChild($this->buildCreditor($doc));
58
59 2
        $creditorAccount = $doc->createElement('CdtrAcct');
60 2
        $creditorAccountId = $doc->createElement('Id');
61 2
        $creditorAccountId->appendChild($doc->createElement('IBAN', $this->creditorIBAN->normalize()));
62 2
        $creditorAccount->appendChild($creditorAccountId);
63 2
        $root->appendChild($creditorAccount);
64
65 2
        if ($this->hasRemittanceInformation()) {
66
            $root->appendChild($this->buildRemittanceInformation($doc));
67
        }
68
69 2
        return $root;
70
    }
71
}
72