1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Octante\UpsAPIBundle\Library; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the UpsAPIBundle package. |
7
|
|
|
* |
8
|
|
|
* (c) Issel Guberna <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
use Ups\AddressValidation; |
15
|
|
|
use Ups\RequestInterface; |
16
|
|
|
use Ups\ResponseInterface; |
17
|
|
|
use Ups\Entity\Exception; |
18
|
|
|
|
19
|
|
View Code Duplication |
class AddressValidationWrapper |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var \Ups\AddressValidation |
23
|
|
|
*/ |
24
|
|
|
private $upsAddressValidation; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Shipping constructor. |
28
|
|
|
* |
29
|
|
|
* @param AddressValidation $upsAddressValidation |
30
|
|
|
*/ |
31
|
|
|
public function __construct(AddressValidation $upsAddressValidation) |
32
|
|
|
{ |
33
|
|
|
$this->upsAddressValidation = $upsAddressValidation; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get address suggestions from UPS. |
38
|
|
|
* |
39
|
|
|
* @param $address |
40
|
|
|
* @param int $requestOption |
41
|
|
|
* @param int $maxSuggestion |
42
|
|
|
* |
43
|
|
|
* @throws Exception |
44
|
|
|
* |
45
|
|
|
* @return \StdClass |
46
|
|
|
*/ |
47
|
|
|
public function validate( |
48
|
|
|
$address, |
49
|
|
|
$requestOption = AddressValidation::REQUEST_OPTION_ADDRESS_VALIDATION, |
50
|
|
|
$maxSuggestion = 15 |
51
|
|
|
) { |
52
|
|
|
$this->upsAddressValidation->validate($address, $requestOption, $maxSuggestion); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return RequestInterface |
57
|
|
|
*/ |
58
|
|
|
public function getRequest() |
59
|
|
|
{ |
60
|
|
|
return $this |
61
|
|
|
->upsAddressValidation |
62
|
|
|
->getRequest(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param RequestInterface $request |
67
|
|
|
* |
68
|
|
|
* @return $this |
69
|
|
|
*/ |
70
|
|
|
public function setRequest(RequestInterface $request) |
71
|
|
|
{ |
72
|
|
|
$this->upsAddressValidation->setRequest($request); |
73
|
|
|
|
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return ResponseInterface |
79
|
|
|
*/ |
80
|
|
|
public function getResponse() |
81
|
|
|
{ |
82
|
|
|
return $this->upsAddressValidation->getResponse(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param ResponseInterface $response |
87
|
|
|
* |
88
|
|
|
* @return $this |
89
|
|
|
*/ |
90
|
|
|
public function setResponse(ResponseInterface $response) |
91
|
|
|
{ |
92
|
|
|
$this->upsAddressValidation->setResponse($response); |
93
|
|
|
|
94
|
|
|
return $this; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
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.