Completed
Pull Request — master (#29)
by
unknown
02:58
created

EntryTransactionDetail   B

Complexity

Total Complexity 36

Size/Duplication

Total Lines 158
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 11

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 3
Metric Value
wmc 36
c 5
b 0
f 3
lcom 0
cbo 11
dl 0
loc 158
ccs 89
cts 89
cp 1
rs 8.8

7 Methods

Rating   Name   Duplication   Size   Complexity  
D addReferences() 0 32 18
B addRelatedParties() 0 25 5
A addRelatedParty() 0 12 2
B addRemittanceInformation() 0 27 6
A addReturnInformation() 0 10 3
A addAdditionalTransactionInformation() 0 9 2
getRelatedPartyAccount() 0 1 ?
1
<?php
2
3
namespace Genkgo\Camt\Decoder;
4
5
use Genkgo\Camt\DTO;
6
use \SimpleXMLElement;
7
use Genkgo\Camt\Decoder\Factory\DTO as DTOFactory;
8
use Genkgo\Camt\Iban;
9
10
abstract class EntryTransactionDetail
11
{
12
    /**
13
     * @param DTO\EntryTransactionDetail $detail
14
     * @param SimpleXMLElement           $xmlDetail
15
     */
16 19
    public function addReferences(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
17
    {
18 19
        if (false === isset($xmlDetail->Refs)) {
19 5
            return;
20 18
        }
21
22 18
        $refs = $xmlDetail->Refs;
0 ignored issues
show
Bug introduced by
The property Refs does not seem to exist in SimpleXMLElement.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
23 17
        $reference = new DTO\Reference();
24
25 17
        $reference->setMessageId(isset($refs->MsgId) ? (string) $refs->MsgId : null);
26 17
        $reference->setAccountServiceReference(isset($refs->AcctSvcrRef) ? (string) $refs->AcctSvcrRef : null);
27 17
        $reference->setPaymentInformationId(isset($refs->PmtInfId) ? (string) $refs->PmtInfId : null);
28 17
        $reference->setInstructionId(isset($refs->InstrId) ? (string) $refs->InstrId : null);
29 17
        $reference->setEndToEndId(isset($refs->EndToEndId) ? (string) $refs->EndToEndId : null);
30 17
        $reference->setTransactionId(isset($refs->TxId) ? (string) $refs->TxId : null);
31 17
        $reference->setMandateId(isset($refs->MndtId) ? (string) $refs->MndtId : null);
32 17
        $reference->setChequeNumber(isset($refs->ChqNb) ? (string) $refs->ChqNb : null);
33 17
        $reference->setClearingSystemReference(isset($refs->ClrSysRef) ? (string) $refs->ClrSysRef : null);
34 17
        $reference->setAccountOwnerTransactionId(isset($refs->AcctOwnrTxId) ? (string) $refs->AcctOwnrTxId : null);
35 17
        $reference->setAccountServicerTransactionId(isset($refs->AcctSvcrTxId) ? (string) $refs->AcctSvcrTxId : null);
36 17
        $reference->setMarketInfrastructureTransactionId(isset($refs->MktInfrstrctrTxId) ? (string) $refs->MktInfrstrctrTxId : null);
37 17
        $reference->setProcessingId(isset($refs->PrcgId) ? (string) $refs->PrcgId : null);
38
39 17
        foreach ($refs->Prtry as $xmlProprietary) {
40 8
            $type = isset($xmlProprietary->Tp) ? (string) $xmlProprietary->Tp : null;
41 14
            $subReference = isset($xmlProprietary->Ref) ? (string) $xmlProprietary->Ref : null;
42
43 8
            $reference->addProprietary(new DTO\ProprietaryReference($type, $subReference));
44 17
        }
45
46 17
        $detail->addReference($reference);
47 17
    }
48
49
    /**
50
     * @param DTO\EntryTransactionDetail $detail
51
     * @param SimpleXMLElement           $xmlDetail
52
     */
53 19
    public function addRelatedParties(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
54
    {
55 19
        if (false === isset($xmlDetail->RltdPties)) {
56 1
            return;
57
        }
58
59 18
        foreach ($xmlDetail->RltdPties as $xmlRelatedParty) {
60
61 18
            if (isset($xmlRelatedParty->Cdtr)) {
62 18
                $xmlRelatedPartyType = $xmlRelatedParty->Cdtr;
63 18
                $xmlRelatedPartyTypeAccount = $xmlRelatedParty->CdtrAcct;
64 18
                $relatedPartyType = $creditor = new DTO\Creditor((string) $xmlRelatedPartyType->Nm);
0 ignored issues
show
Unused Code introduced by
$creditor is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
65
66 18
                $this->addRelatedParty($detail, $xmlRelatedPartyType, $relatedPartyType, $xmlRelatedPartyTypeAccount);
67 18
            }
68
69 18
            if (isset($xmlRelatedParty->Dbtr)) {
70 15
                $xmlRelatedPartyType = $xmlRelatedParty->Dbtr;
71 15
                $xmlRelatedPartyTypeAccount = $xmlRelatedParty->DbtrAcct;
72 15
                $relatedPartyType = $debtor = new DTO\Debtor((string) $xmlRelatedPartyType->Nm);
0 ignored issues
show
Unused Code introduced by
$debtor is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
73
74 15
                $this->addRelatedParty($detail, $xmlRelatedPartyType, $relatedPartyType, $xmlRelatedPartyTypeAccount);
75 15
            }
76 18
        }
77 18
    }
78
79
    /**
80
     * @param DTO\EntryTransactionDetail $detail
81
     * @param $xmlRelatedPartyType
82
     * @param $relatedPartyType
83
     * @param $xmlRelatedPartyTypeAccount
84
     * @return DTO\RelatedParty
85
     */
86 18
    protected function addRelatedParty(DTO\EntryTransactionDetail $detail, $xmlRelatedPartyType, $relatedPartyType, $xmlRelatedPartyTypeAccount)
87
    {
88 18
        if (isset($xmlRelatedPartyType->PstlAdr)) {
89 18
            $relatedPartyType->setAddress(DTOFactory\Address::createFromXml($xmlRelatedPartyType->PstlAdr));
90 18
        }
91
92 18
        $relatedParty = new DTO\RelatedParty($relatedPartyType, $this->getRelatedPartyAccount($xmlRelatedPartyTypeAccount));
93
94 18
        $detail->addRelatedParty($relatedParty);
95
96 18
        return $relatedParty;
97
    }
98
99
    /**
100
     * @param DTO\EntryTransactionDetail $detail
101
     * @param SimpleXMLElement           $xmlDetail
102
     */
103 20
    public function addRemittanceInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
104
    {
105 20
        if (false === isset($xmlDetail->RmtInf)) {
106 8
            return;
107
        }
108
109 18
        if (isset($xmlDetail->RmtInf->Ustrd)) {
110 9
            $remittanceInformation = DTO\RemittanceInformation::fromUnstructured(
111 9
                (string)$xmlDetail->RmtInf->Ustrd
112 9
            );
113 9
            $detail->setRemittanceInformation($remittanceInformation);
114
115 9
            return;
116
        }
117
        
118 9
        if (isset($xmlDetail->RmtInf->Strd)
119 9
            && isset($xmlDetail->RmtInf->Strd->CdtrRefInf)
120 9
            && isset($xmlDetail->RmtInf->Strd->CdtrRefInf->Ref)
121 9
        ) {
122 9
            $creditorReferenceInformation = DTO\CreditorReferenceInformation::fromUnstructured(
123 9
                (string)$xmlDetail->RmtInf->Strd->CdtrRefInf->Ref
124 9
            );
125 9
            $remittanceInformation = new DTO\RemittanceInformation();
126 9
            $remittanceInformation->setCreditorReferenceInformation($creditorReferenceInformation);
127 9
            $detail->setRemittanceInformation($remittanceInformation);
128 9
        }
129 9
    }
130
131
    /**
132
     * @param DTO\EntryTransactionDetail $detail
133
     * @param SimpleXMLElement           $xmlDetail
134
     */
135 19
    public function addReturnInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
136
    {
137 19
        if (isset($xmlDetail->RtrInf) && isset($xmlDetail->RtrInf->Rsn->Cd)) {
138 1
            $remittanceInformation = DTO\ReturnInformation::fromUnstructured(
139 1
                (string)$xmlDetail->RtrInf->Rsn->Cd,
140 1
                (string)$xmlDetail->RtrInf->AddtlInf
141 1
            );
142 1
            $detail->setReturnInformation($remittanceInformation);
143 1
        }
144 19
    }
145
146
    /**
147
     * @param DTO\EntryTransactionDetail $detail
148
     * @param SimpleXMLElement           $xmlDetail
149
     */
150 19
    public function addAdditionalTransactionInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
151
    {
152 19
        if (isset($xmlDetail->AddtlTxInf)) {
153 1
            $additionalInformation = new DTO\AdditionalTransactionInformation(
154 1
                (string) $xmlDetail->AddtlTxInf
155 1
            );
156 1
            $detail->setAdditionalTransactionInformation($additionalInformation);
157 1
        }
158 19
    }
159
160
    /**
161
     * @param SimpleXMLElement $xmlDetail
0 ignored issues
show
Bug introduced by
There is no parameter named $xmlDetail. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
162
     *
163
     * @return DTO\Account|null
164
     */
165
    abstract public function getRelatedPartyAccount(SimpleXMLElement $xmlRelatedPartyTypeAccount);
166
167
}
168