Passed
Pull Request — master (#157)
by Rudger
03:17
created

IncludeCriteria   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 53.19%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 15
lcom 1
cbo 3
dl 0
loc 122
ccs 25
cts 47
cp 0.5319
rs 10
c 1
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 4 1
C toNode() 0 38 8
A getServiceOfferingList() 0 4 1
A setServiceOfferingList() 0 4 1
A getMerchantAccountNumberList() 0 4 1
A setMerchantAccountNumberList() 0 4 1
A getSearchFilter() 0 4 1
A setSearchFilter() 0 4 1
1
<?php
2
3
namespace Ups\Entity;
4
5
use DOMDocument;
6
use DOMElement;
7
use DOMNode;
8
use Ups\NodeInterface;
9
10
class IncludeCriteria implements NodeInterface
11
{
12
13
    /**
14
     * @var ServiceOffering[]
15
     */
16
    private $serviceOfferingList;
17
18
    /**
19
     * not implemented yet
20
     *
21
     * @var MerchantAccountNumber[]|null
22
     */
23
    private $merchantAccountNumberList;
24
25
    /**
26
     * not implemented yet
27
     *
28
     * @var SearchFilter[]|null
29
     */
30
    private $searchFilter;
31
32
33
    public function __toString()
34
    {
35
        return $this->toNode()->ownerDocument->saveXML();
36
    }
37
38
    /**
39
     * @param null|DOMDocument $document
40
     *
41
     * @return DOMNode|DOMElement
42
     */
43 1
    public function toNode(DOMDocument $document = null)
44
    {
45 1
        if (null === $document) {
46
            $document = new DOMDocument();
47
        }
48
49
        /** @var DOMElement $node */
50 1
        $node = $document->createElement('IncludeCriteria');
51
52 1
        $serviceOfferingList = $this->getServiceOfferingList();
53 1
        if ($serviceOfferingList) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $serviceOfferingList of type Ups\Entity\ServiceOffering[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
54 1
            $serviceOfferingListNode = $node->appendChild($document->createElement('ServiceOfferingList'));
55 1
            foreach ($serviceOfferingList as $serviceOffering) {
56 1
                $serviceOfferingListNode->appendChild($serviceOffering->toNode($document));
57 1
            }
58 1
            $node->appendChild($serviceOfferingListNode);
59 1
        }
60
61 1
        $merchantAccountNumberList = $this->getMerchantAccountNumberList();
62 1
        if ($merchantAccountNumberList) {
63
            $merchantAccountNumberNode = $node->appendChild($document->createElement('MerchantAccountNumber'));
64
            foreach ($merchantAccountNumberList as $merchantAccountNumber) {
65
                $merchantAccountNumberNode->appendChild($merchantAccountNumber->toNode($document));
66
            }
67
            $node->appendChild($merchantAccountNumberNode);
68
        }
69
70 1
        $searchFilters = $this->getSearchFilter();
71 1
        if ($searchFilters) {
72
            $searchFilterNode = $node->appendChild($document->createElement('SearchFilter'));
73
            foreach ($searchFilters as $searchFilter) {
74
                $searchFilterNode->appendChild($searchFilter->toNode($document));
75
            }
76
            $node->appendChild($searchFilterNode);
77
        }
78
79 1
        return $node;
80
    }
81
82
    /**
83
     * @return ServiceOffering[]
84
     */
85 1
    public function getServiceOfferingList()
86
    {
87 1
        return $this->serviceOfferingList;
88
    }
89
90
    /**
91
     * @param ServiceOffering[] $serviceOfferingList
92
     */
93 1
    public function setServiceOfferingList($serviceOfferingList)
94
    {
95 1
        $this->serviceOfferingList = $serviceOfferingList;
96 1
    }
97
98
    /**
99
     * @return null|MerchantAccountNumber[]
100
     */
101 1
    public function getMerchantAccountNumberList()
102
    {
103 1
        return $this->merchantAccountNumberList;
104
    }
105
106
    /**
107
     * @param null|MerchantAccountNumber[] $merchantAccountNumberList
108
     */
109
    public function setMerchantAccountNumberList($merchantAccountNumberList)
110
    {
111
        $this->merchantAccountNumberList = $merchantAccountNumberList;
112
    }
113
114
    /**
115
     * @return null|SearchFilter[]
116
     */
117 1
    public function getSearchFilter()
118
    {
119 1
        return $this->searchFilter;
120
    }
121
122
    /**
123
     * @param null|SearchFilter[] $searchFilter
124
     */
125
    public function setSearchFilter($searchFilter)
126
    {
127
        $this->searchFilter = $searchFilter;
128
    }
129
130
131
}
132