1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ups\Entity; |
4
|
|
|
|
5
|
|
|
use DOMDocument; |
6
|
|
|
use DOMElement; |
7
|
|
|
use Exception as BaseException; |
8
|
|
|
use Ups\NodeInterface; |
9
|
|
|
|
10
|
|
|
class LocationSearchCriteria implements NodeInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var AccessPointSearch |
14
|
|
|
*/ |
15
|
|
|
private $accessPointSearch; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var |
19
|
|
|
*/ |
20
|
|
|
private $maximumListSize; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @return AccessPointSearch |
24
|
|
|
*/ |
25
|
3 |
|
public function getAccessPointSearch() |
26
|
|
|
{ |
27
|
3 |
|
return $this->accessPointSearch; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param AccessPointSearch $accessPointSearch |
32
|
|
|
*/ |
33
|
2 |
|
public function setAccessPointSearch(AccessPointSearch $accessPointSearch) |
34
|
|
|
{ |
35
|
2 |
|
$this->accessPointSearch = $accessPointSearch; |
36
|
2 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param null|DOMDocument $document |
40
|
|
|
* |
41
|
|
|
* @return DOMElement |
42
|
|
|
*/ |
43
|
3 |
|
public function toNode(DOMDocument $document = null) |
44
|
|
|
{ |
45
|
3 |
|
if (null === $document) { |
46
|
|
|
$document = new DOMDocument(); |
47
|
|
|
} |
48
|
|
|
|
49
|
3 |
|
$node = $document->createElement('LocationSearchCriteria'); |
50
|
|
|
|
51
|
3 |
|
if ($this->getAccessPointSearch()) { |
52
|
2 |
|
$node->appendChild($this->getAccessPointSearch()->toNode($document)); |
53
|
2 |
|
} |
54
|
|
|
|
55
|
3 |
|
if ($this->getMaximumListSize()) { |
56
|
2 |
|
$node->appendChild($document->createElement('MaximumListSize', $this->getMaximumListSize())); |
57
|
2 |
|
} |
58
|
|
|
|
59
|
3 |
|
return $node; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return mixed |
64
|
|
|
*/ |
65
|
3 |
|
public function getMaximumListSize() |
66
|
|
|
{ |
67
|
3 |
|
return $this->maximumListSize; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param mixed $maximumListSize |
72
|
|
|
* |
73
|
|
|
* @throws BaseException |
74
|
|
|
*/ |
75
|
2 |
View Code Duplication |
public function setMaximumListSize($maximumListSize) |
|
|
|
|
76
|
|
|
{ |
77
|
2 |
|
$maximumListSize = (int)$maximumListSize; |
78
|
|
|
|
79
|
2 |
|
if ($maximumListSize < 1 || $maximumListSize > 50) { |
80
|
|
|
throw new BaseException('Maximum list size: If present, indicates the maximum number of locations the client wishes to receive in response; ranges from 1 to 50 with a default value of 10'); |
81
|
|
|
} |
82
|
|
|
|
83
|
2 |
|
$this->maximumListSize = $maximumListSize; |
84
|
2 |
|
} |
85
|
|
|
} |
86
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.