Completed
Pull Request — master (#27)
by Yann
02:57
created

OrganisationIdentification::createFromXml()   C

Complexity

Conditions 8
Paths 68

Size

Total Lines 52
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 36
CRAP Score 8.3844

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 52
ccs 36
cts 44
cp 0.8182
rs 6.8493
cc 8
eloc 33
nc 68
nop 1
crap 8.3844

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Genkgo\Camt\Decoder\Factory\DTO;
4
5
use SimpleXMLElement;
6
use Genkgo\Camt\DTO;
7
8
class OrganisationIdentification
9
{
10
    use Behavior\Mapping;
11
12 17
    public static function createFromXml(SimpleXMLElement $xmlOrganisationIdentification)
13
    {
14
        $mapping = [
15 17
            ['setBic', 'BIC'],
16 17
            ['setBic', 'BICOrBEI'],
17 17
            ['setBic', 'AnyBIC'],
18 17
            ['setBei', 'BICOrBEI'],
19 17
            ['setIbei', 'IBEI'],
20 17
            ['setBei', 'BEI'],
21 17
            ['setEangln', 'EANGLN'],
22 17
            ['setChipsUniversalId', 'USCHU'],
23 17
            ['setDuns', 'DUNS'],
24 17
            ['setBankPartyId', 'BkPtyId'],
25 17
            ['setTaxId', 'TaxIdNb'],
26 17
        ];
27
28 17
        $organisationIdentification = new DTO\OrganisationIdentification();
29
30 17
        self::map($organisationIdentification, $xmlOrganisationIdentification, $mapping);
31
32 17
        if (isset($xmlOrganisationIdentification->PrtryId)) {
33 4
            $other = $xmlOrganisationIdentification->PrtryId;
0 ignored issues
show
Bug introduced by
The property PrtryId 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...
34 4
        }
35 17
        if (isset($xmlOrganisationIdentification->Othr)) {
36 16
            $other = $xmlOrganisationIdentification->Othr;
0 ignored issues
show
Bug introduced by
The property Othr 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...
37 16
        }
38
39 17
        if (isset($other)) {
40 17
            if (isset($other->Id)) {
41 17
                $organisationIdentification->setOtherId(
42 17
                    (string) $other->Id
43 17
                );
44 17
            }
45 17
            if (isset($other->Issr)) {
46 17
                $organisationIdentification->setOtherIssuer(
47 17
                    (string) $other->Issr
48 17
                );
49 17
            }
50 17
            if (isset($other->Tp)) {
51
                $organisationIdentification->setOtherType(
52
                    (string) $other->Tp
53
                );
54
            }
55 17
            if (isset($other->SchmeNm)) {
56
                $organisationIdentification->setOtherSchemeName(
57
                    (string) $other->SchmeNm
58
                );
59
            }
60 17
        }
61
62 17
        return $organisationIdentification;
63
    }
64
}
65