Total Complexity | 52 |
Total Lines | 356 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Complex classes like At247 often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use At247, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
26 | class At247 extends National |
||
27 | { |
||
28 | /** @var string */ |
||
29 | private $parcelsDepotId; |
||
30 | |||
31 | /** @var string */ |
||
32 | private $parcelsDepotName; |
||
33 | |||
34 | /** @var \Bpost\BpostApiClient\Bpost\Order\ParcelsDepotAddress */ |
||
35 | private $parcelsDepotAddress; |
||
36 | |||
37 | /** @var string */ |
||
38 | protected $product = Product::PRODUCT_NAME_BPACK_24H_PRO; |
||
39 | |||
40 | /** @var string */ |
||
41 | private $memberId; |
||
42 | |||
43 | /** @var Unregistered */ |
||
44 | private $unregistered; |
||
45 | |||
46 | /** @var string */ |
||
47 | private $receiverName; |
||
48 | |||
49 | /** @var string */ |
||
50 | private $receiverCompany; |
||
51 | |||
52 | /** @var string */ |
||
53 | protected $requestedDeliveryDate; |
||
54 | |||
55 | /** |
||
56 | * @param string $memberId |
||
57 | */ |
||
58 | public function setMemberId($memberId) |
||
59 | { |
||
60 | $this->memberId = $memberId; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @return string |
||
65 | */ |
||
66 | public function getMemberId() |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @param \Bpost\BpostApiClient\Bpost\Order\ParcelsDepotAddress $parcelsDepotAddress |
||
73 | */ |
||
74 | public function setParcelsDepotAddress($parcelsDepotAddress) |
||
75 | { |
||
76 | $this->parcelsDepotAddress = $parcelsDepotAddress; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @return \Bpost\BpostApiClient\Bpost\Order\ParcelsDepotAddress |
||
81 | */ |
||
82 | public function getParcelsDepotAddress() |
||
83 | { |
||
84 | return $this->parcelsDepotAddress; |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @param string $parcelsDepotId |
||
89 | */ |
||
90 | public function setParcelsDepotId($parcelsDepotId) |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @return string |
||
97 | */ |
||
98 | public function getParcelsDepotId() |
||
99 | { |
||
100 | return $this->parcelsDepotId; |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * @param string $parcelsDepotName |
||
105 | */ |
||
106 | public function setParcelsDepotName($parcelsDepotName) |
||
107 | { |
||
108 | $this->parcelsDepotName = $parcelsDepotName; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * @return string |
||
113 | */ |
||
114 | public function getParcelsDepotName() |
||
115 | { |
||
116 | return $this->parcelsDepotName; |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * @return Unregistered |
||
121 | */ |
||
122 | public function getUnregistered() |
||
123 | { |
||
124 | return $this->unregistered; |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * @param Unregistered $unregistered |
||
129 | */ |
||
130 | public function setUnregistered(Unregistered $unregistered) |
||
131 | { |
||
132 | $this->unregistered = $unregistered; |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * @param string $product Possible values are: bpack 24h Pro |
||
137 | * |
||
138 | * @throws BpostInvalidValueException |
||
139 | */ |
||
140 | public function setProduct($product) |
||
141 | { |
||
142 | if (!in_array($product, self::getPossibleProductValues())) { |
||
143 | throw new BpostInvalidValueException('product', $product, self::getPossibleProductValues()); |
||
144 | } |
||
145 | |||
146 | parent::setProduct($product); |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * @return array |
||
151 | */ |
||
152 | public static function getPossibleProductValues() |
||
153 | { |
||
154 | return array( |
||
155 | Product::PRODUCT_NAME_BPACK_24H_PRO, |
||
156 | Product::PRODUCT_NAME_BPACK_24_7, |
||
157 | ); |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * @param string $receiverCompany |
||
162 | */ |
||
163 | public function setReceiverCompany($receiverCompany) |
||
164 | { |
||
165 | $this->receiverCompany = $receiverCompany; |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * @return string |
||
170 | */ |
||
171 | public function getReceiverCompany() |
||
172 | { |
||
173 | return $this->receiverCompany; |
||
174 | } |
||
175 | |||
176 | /** |
||
177 | * @param string $receiverName |
||
178 | */ |
||
179 | public function setReceiverName($receiverName) |
||
180 | { |
||
181 | $this->receiverName = $receiverName; |
||
182 | } |
||
183 | |||
184 | /** |
||
185 | * @return string |
||
186 | */ |
||
187 | public function getReceiverName() |
||
188 | { |
||
189 | return $this->receiverName; |
||
190 | } |
||
191 | |||
192 | /** |
||
193 | * @return string |
||
194 | */ |
||
195 | public function getRequestedDeliveryDate() |
||
196 | { |
||
197 | return $this->requestedDeliveryDate; |
||
198 | } |
||
199 | |||
200 | /** |
||
201 | * @param string $requestedDeliveryDate |
||
202 | */ |
||
203 | public function setRequestedDeliveryDate($requestedDeliveryDate) |
||
204 | { |
||
205 | $this->requestedDeliveryDate = (string) $requestedDeliveryDate; |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * Return the object as an array for usage in the XML |
||
210 | * |
||
211 | * @param DomDocument $document |
||
212 | * @param string $prefix |
||
213 | * @param string $type |
||
214 | * |
||
215 | * @return DomElement |
||
216 | */ |
||
217 | public function toXML(DOMDocument $document, $prefix = null, $type = null) |
||
218 | { |
||
219 | $nationalElement = $document->createElement(XmlHelper::getPrefixedTagName('nationalBox', $prefix)); |
||
220 | $boxElement = parent::toXML($document, null, 'at24-7'); |
||
221 | $nationalElement->appendChild($boxElement); |
||
222 | |||
223 | if ($this->getParcelsDepotId() !== null) { |
||
|
|||
224 | $boxElement->appendChild( |
||
225 | $document->createElement('parcelsDepotId', $this->getParcelsDepotId()) |
||
226 | ); |
||
227 | } |
||
228 | if ($this->getParcelsDepotName() !== null) { |
||
229 | $boxElement->appendChild( |
||
230 | $document->createElement( |
||
231 | 'parcelsDepotName', |
||
232 | $this->getParcelsDepotName() |
||
233 | ) |
||
234 | ); |
||
235 | } |
||
236 | if ($this->getParcelsDepotAddress() !== null) { |
||
237 | $boxElement->appendChild( |
||
238 | $this->getParcelsDepotAddress()->toXML($document) |
||
239 | ); |
||
240 | } |
||
241 | if ($this->getMemberId() !== null) { |
||
242 | $boxElement->appendChild( |
||
243 | $document->createElement( |
||
244 | 'memberId', |
||
245 | $this->getMemberId() |
||
246 | ) |
||
247 | ); |
||
248 | } |
||
249 | $this->addToXmlUnregistered($document, $boxElement, $prefix); |
||
250 | if ($this->getReceiverName() !== null) { |
||
251 | $boxElement->appendChild( |
||
252 | $document->createElement( |
||
253 | 'receiverName', |
||
254 | $this->getReceiverName() |
||
255 | ) |
||
256 | ); |
||
257 | } |
||
258 | if ($this->getReceiverCompany() !== null) { |
||
259 | $boxElement->appendChild( |
||
260 | $document->createElement( |
||
261 | 'receiverCompany', |
||
262 | $this->getReceiverCompany() |
||
263 | ) |
||
264 | ); |
||
265 | } |
||
266 | $this->addToXmlRequestedDeliveryDate($document, $boxElement, $prefix); |
||
267 | |||
268 | return $nationalElement; |
||
269 | } |
||
270 | |||
271 | /** |
||
272 | * @param DOMDocument $document |
||
273 | * @param DOMElement $typeElement |
||
274 | * @param string $prefix |
||
275 | */ |
||
276 | protected function addToXmlRequestedDeliveryDate(DOMDocument $document, DOMElement $typeElement, $prefix) |
||
283 | ) |
||
284 | ); |
||
285 | } |
||
286 | } |
||
287 | |||
288 | /** |
||
289 | * @param DOMDocument $document |
||
290 | * @param DOMElement $typeElement |
||
291 | * @param string $prefix |
||
292 | */ |
||
293 | protected function addToXmlUnregistered(DOMDocument $document, DOMElement $typeElement, $prefix) |
||
294 | { |
||
295 | if ($this->getUnregistered() !== null) { |
||
296 | $typeElement->appendChild( |
||
297 | $this->getUnregistered()->toXml($document) |
||
298 | ); |
||
299 | } |
||
300 | } |
||
301 | |||
302 | /** |
||
303 | * @param SimpleXMLElement $xml |
||
304 | * @param National|null $self |
||
305 | * |
||
306 | * @return At247 |
||
307 | * |
||
308 | * @throws BpostInvalidValueException |
||
309 | * @throws BpostNotImplementedException |
||
310 | * @throws \Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException |
||
311 | * @throws \Bpost\BpostApiClient\Exception\XmlException\BpostXmlInvalidItemException |
||
312 | */ |
||
313 | public static function createFromXML(SimpleXMLElement $xml, National $self = null) |
||
382 | } |
||
383 | } |
||
384 |