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

BankCreditTransfer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 90.91%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A asDom() 0 22 2
1
<?php
2
3
namespace Z38\SwissPayment\TransactionInformation;
4
5
use Z38\SwissPayment\BC;
6
use Z38\SwissPayment\BIC;
7
use Z38\SwissPayment\FinancialInstitutionInterface;
8
use Z38\SwissPayment\IBAN;
9
use Z38\SwissPayment\Money;
10
use Z38\SwissPayment\PostalAddressInterface;
11
12
/**
13
 * BankCreditTransfer contains all the information about a type 3 transaction.
14
 */
15
class BankCreditTransfer extends CreditTransfer
16
{
17
    /**
18
     * @var IBAN
19
     */
20
    protected $creditorIBAN;
21
22
    /**
23
     * @var FinancialInstitutionInterface
24
     */
25
    protected $creditorAgent;
26
27
    /**
28
     * {@inheritdoc}
29
     *
30
     * @param IBAN   $creditorIBAN  IBAN of the creditor
31
     * @param BC|BIC $creditorAgent BC or BIC of the creditor's financial institution
32
     */
33 3
    public function __construct($instructionId, $endToEndId, Money\CHF $amount, $creditorName, PostalAddressInterface $creditorAddress, IBAN $creditorIBAN, FinancialInstitutionInterface $creditorAgent)
34
    {
35 3
        parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress);
36
37 3
        if (!$creditorAgent instanceof BC && !$creditorAgent instanceof BIC) {
38 1
            throw new \InvalidArgumentException('The creditor agent must be an instance of BC or BIC.');
39
        }
40
41 2
        $this->creditorIBAN = $creditorIBAN;
42 2
        $this->creditorAgent = $creditorAgent;
43 2
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 2
    public function asDom(\DOMDocument $doc)
49
    {
50 2
        $root = $this->buildHeader($doc, null);
51
52 2
        $creditorAgent = $doc->createElement('CdtrAgt');
53 2
        $creditorAgent->appendChild($this->creditorAgent->asDom($doc));
54 2
        $root->appendChild($creditorAgent);
55
56 2
        $root->appendChild($this->buildCreditor($doc));
57
58 2
        $creditorAccount = $doc->createElement('CdtrAcct');
59 2
        $creditorAccountId = $doc->createElement('Id');
60 2
        $creditorAccountId->appendChild($doc->createElement('IBAN', $this->creditorIBAN->normalize()));
61 2
        $creditorAccount->appendChild($creditorAccountId);
62 2
        $root->appendChild($creditorAccount);
63
64 2
        if ($this->hasRemittanceInformation()) {
65
            $root->appendChild($this->buildRemittanceInformation($doc));
66
        }
67
68 2
        return $root;
69
    }
70
}
71