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

IS2CreditTransfer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 92.31%

Importance

Changes 3
Bugs 1 Features 2
Metric Value
wmc 3
c 3
b 1
f 2
lcom 1
cbo 3
dl 0
loc 64
ccs 24
cts 26
cp 0.9231
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
B asDom() 0 27 2
1
<?php
2
3
namespace Z38\SwissPayment\TransactionInformation;
4
5
use Z38\SwissPayment\IBAN;
6
use Z38\SwissPayment\Money;
7
use Z38\SwissPayment\PostalAccount;
8
use Z38\SwissPayment\PostalAddressInterface;
9
10
/**
11
 * IS2CreditTransfer contains all the information about a IS 2-stage (type 2.2) transaction.
12
 */
13
class IS2CreditTransfer extends CreditTransfer
14
{
15
    /**
16
     * @var IBAN
17
     */
18
    protected $creditorIBAN;
19
20
    /**
21
     * @var string
22
     */
23
    protected $creditorAgentName;
24
25
    /**
26
     * @var PostalAccount
27
     */
28
    protected $creditorAgentPostal;
29
30
    /**
31
     * {@inheritdoc}
32
     *
33
     * @param IBAN          $creditorIBAN        IBAN of the creditor
34
     * @param string        $creditorAgentName   Name of the creditor's financial institution
35
     * @param PostalAccount $creditorAgentPostal Postal account of the creditor's financial institution
36
     */
37 2
    public function __construct($instructionId, $endToEndId, Money\CHF $amount, $creditorName, PostalAddressInterface $creditorAddress, IBAN $creditorIBAN, $creditorAgentName, PostalAccount $creditorAgentPostal)
38
    {
39 2
        parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress);
40
41 2
        $this->creditorIBAN = $creditorIBAN;
42 2
        $this->creditorAgentName = (string) $creditorAgentName;
43 2
        $this->creditorAgentPostal = $creditorAgentPostal;
44 2
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 2
    public function asDom(\DOMDocument $doc)
50
    {
51 2
        $root = $this->buildHeader($doc, 'CH03');
52
53 2
        $creditorAgent = $doc->createElement('CdtrAgt');
54 2
        $creditorAgentId = $doc->createElement('FinInstnId');
55 2
        $creditorAgentId->appendChild($doc->createElement('Nm', $this->creditorAgentName));
56 2
        $creditorAgentIdOther = $doc->createElement('Othr');
57 2
        $creditorAgentIdOther->appendChild($doc->createElement('Id', $this->creditorAgentPostal->format()));
58 2
        $creditorAgentId->appendChild($creditorAgentIdOther);
59 2
        $creditorAgent->appendChild($creditorAgentId);
60 2
        $root->appendChild($creditorAgent);
61
62 2
        $root->appendChild($this->buildCreditor($doc));
63
64 2
        $creditorAccount = $doc->createElement('CdtrAcct');
65 2
        $creditorAccountId = $doc->createElement('Id');
66 2
        $creditorAccountId->appendChild($doc->createElement('IBAN', $this->creditorIBAN->normalize()));
67 2
        $creditorAccount->appendChild($creditorAccountId);
68 2
        $root->appendChild($creditorAccount);
69
70 2
        if ($this->hasRemittanceInformation()) {
71
            $root->appendChild($this->buildRemittanceInformation($doc));
72
        }
73
74 2
        return $root;
75
    }
76
}
77