1 | <?php |
||
19 | trait CustomerDetailsTrait |
||
20 | { |
||
21 | /** |
||
22 | * Get the card. |
||
23 | * |
||
24 | * @return CreditCard |
||
25 | * |
||
26 | * @codeCoverageIgnore |
||
27 | */ |
||
28 | abstract public function getCard(); |
||
29 | |||
30 | /** |
||
31 | * Get the client IP address. |
||
32 | * |
||
33 | * @return string |
||
34 | * |
||
35 | * @codeCoverageIgnore |
||
36 | */ |
||
37 | abstract public function getClientIp(); |
||
38 | |||
39 | /** |
||
40 | * @param string $country |
||
41 | * |
||
42 | * @return string|null ISO-3166-1 Alpha3 |
||
43 | * |
||
44 | * @codeCoverageIgnore |
||
45 | */ |
||
46 | abstract public function getCountryCode($country); |
||
47 | |||
48 | /** |
||
49 | * @throws InvalidRequestException |
||
50 | * |
||
51 | * @return null|Customer |
||
52 | */ |
||
53 | 13 | public function getCustomerDetails() |
|
54 | { |
||
55 | 13 | return $this->getParameter('customerDetails'); |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * Sets the customer detail information |
||
60 | * |
||
61 | * @param Customer $customer |
||
62 | * |
||
63 | * @return AuthorizeRequest |
||
64 | */ |
||
65 | 18 | public function setCustomerDetails($customer) |
|
66 | { |
||
67 | 18 | return $this->setParameter('customerDetails', $customer); |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * @param SimpleXMLElement $data |
||
72 | * |
||
73 | * @throws InvalidRequestException |
||
74 | */ |
||
75 | 11 | protected function appendCustomerDetails(SimpleXMLElement $data) |
|
76 | { |
||
77 | 11 | $data->addChild('customer_details'); |
|
78 | 11 | $this->appendCustomerDetailsAdditional($data, $this->getCustomerDetails()); |
|
|
|||
79 | 11 | $this->appendCustomerDetailsCard($data, $this->getCard()); |
|
80 | 11 | } |
|
81 | |||
82 | /** |
||
83 | * Get a single parameter. |
||
84 | * |
||
85 | * @param string $key The parameter key |
||
86 | * |
||
87 | * @return mixed |
||
88 | * |
||
89 | * @codeCoverageIgnore |
||
90 | */ |
||
91 | abstract protected function getParameter($key); |
||
92 | |||
93 | /** |
||
94 | * Set a single parameter |
||
95 | * |
||
96 | * @param string $key The parameter key |
||
97 | * @param mixed $value The value to set |
||
98 | * |
||
99 | * @return AbstractRequest Provides a fluent interface |
||
100 | * |
||
101 | * @codeCoverageIgnore |
||
102 | */ |
||
103 | abstract protected function setParameter($key, $value); |
||
104 | |||
105 | /** |
||
106 | * Fills additional data |
||
107 | * |
||
108 | * @param SimpleXMLElement $data |
||
109 | * @param Customer $customer |
||
110 | */ |
||
111 | 11 | private function appendCustomerDetailsAdditional(SimpleXMLElement $data, Customer $customer) |
|
119 | |||
120 | /** |
||
121 | * Fills the card information |
||
122 | * |
||
123 | * @param SimpleXMLElement $data |
||
124 | * @param CreditCard $card |
||
125 | */ |
||
126 | 11 | private function appendCustomerDetailsCard(SimpleXMLElement $data, CreditCard $card) |
|
143 | } |
||
144 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: