| Total Complexity | 51 |
| Total Lines | 214 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| 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 |
||
| 28 | class At247 extends National |
||
| 29 | { |
||
| 30 | private ?string $parcelsDepotId = null; |
||
| 31 | private ?string $parcelsDepotName = null; |
||
| 32 | private ?ParcelsDepotAddress $parcelsDepotAddress = null; |
||
| 33 | |||
| 34 | protected ?string $product = Product::PRODUCT_NAME_BPACK_24H_PRO; |
||
| 35 | |||
| 36 | private ?string $memberId = null; |
||
| 37 | private ?Unregistered $unregistered = null; |
||
| 38 | private ?string $receiverName = null; |
||
| 39 | private ?string $receiverCompany = null; |
||
| 40 | protected ?string $requestedDeliveryDate = null; |
||
| 41 | |||
| 42 | public function setMemberId(?string $memberId): void |
||
| 43 | { |
||
| 44 | $this->memberId = $memberId; |
||
| 45 | } |
||
| 46 | |||
| 47 | public function getMemberId(): ?string |
||
| 50 | } |
||
| 51 | |||
| 52 | public function setParcelsDepotAddress(?ParcelsDepotAddress $parcelsDepotAddress): void |
||
| 53 | { |
||
| 54 | $this->parcelsDepotAddress = $parcelsDepotAddress; |
||
| 55 | } |
||
| 56 | |||
| 57 | public function getParcelsDepotAddress(): ?ParcelsDepotAddress |
||
| 58 | { |
||
| 59 | return $this->parcelsDepotAddress; |
||
| 60 | } |
||
| 61 | |||
| 62 | public function setParcelsDepotId(?string $parcelsDepotId): void |
||
| 65 | } |
||
| 66 | |||
| 67 | public function getParcelsDepotId(): ?string |
||
| 68 | { |
||
| 69 | return $this->parcelsDepotId; |
||
| 70 | } |
||
| 71 | |||
| 72 | public function setParcelsDepotName(?string $parcelsDepotName): void |
||
| 73 | { |
||
| 74 | $this->parcelsDepotName = $parcelsDepotName; |
||
| 75 | } |
||
| 76 | |||
| 77 | public function getParcelsDepotName(): ?string |
||
| 78 | { |
||
| 79 | return $this->parcelsDepotName; |
||
| 80 | } |
||
| 81 | |||
| 82 | public function getUnregistered(): ?Unregistered |
||
| 83 | { |
||
| 84 | return $this->unregistered; |
||
| 85 | } |
||
| 86 | |||
| 87 | public function setUnregistered(?Unregistered $unregistered): void |
||
| 88 | { |
||
| 89 | $this->unregistered = $unregistered; |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @throws BpostInvalidValueException |
||
| 94 | */ |
||
| 95 | public function setProduct(string $product): void |
||
| 96 | { |
||
| 97 | if (!in_array($product, self::getPossibleProductValues(), true)) { |
||
| 98 | throw new BpostInvalidValueException('product', $product, self::getPossibleProductValues()); |
||
| 99 | } |
||
| 100 | parent::setProduct($product); |
||
| 101 | } |
||
| 102 | |||
| 103 | public static function getPossibleProductValues(): array |
||
| 104 | { |
||
| 105 | return [ |
||
| 106 | Product::PRODUCT_NAME_BPACK_24H_PRO, |
||
| 107 | Product::PRODUCT_NAME_BPACK_24_7, |
||
| 108 | ]; |
||
| 109 | } |
||
| 110 | |||
| 111 | public function setReceiverCompany(?string $receiverCompany): void |
||
| 112 | { |
||
| 113 | $this->receiverCompany = $receiverCompany; |
||
| 114 | } |
||
| 115 | |||
| 116 | public function getReceiverCompany(): ?string |
||
| 117 | { |
||
| 118 | return $this->receiverCompany; |
||
| 119 | } |
||
| 120 | |||
| 121 | public function setReceiverName(?string $receiverName): void |
||
| 122 | { |
||
| 123 | $this->receiverName = $receiverName; |
||
| 124 | } |
||
| 125 | |||
| 126 | public function getReceiverName(): ?string |
||
| 127 | { |
||
| 128 | return $this->receiverName; |
||
| 129 | } |
||
| 130 | |||
| 131 | public function getRequestedDeliveryDate(): ?string |
||
| 132 | { |
||
| 133 | return $this->requestedDeliveryDate; |
||
| 134 | } |
||
| 135 | |||
| 136 | public function setRequestedDeliveryDate(?string $requestedDeliveryDate): void |
||
| 137 | { |
||
| 138 | $this->requestedDeliveryDate = $requestedDeliveryDate; |
||
| 139 | } |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @throws \DOMException |
||
| 143 | */ |
||
| 144 | public function toXML(DOMDocument $document, ?string $prefix = null, ?string $type = null): DOMElement |
||
| 145 | { |
||
| 146 | $nationalElement = $document->createElement(XmlHelper::getPrefixedTagName('nationalBox', $prefix)); |
||
| 147 | $boxElement = parent::toXML($document, null, 'at24-7'); |
||
| 148 | $nationalElement->appendChild($boxElement); |
||
| 149 | |||
| 150 | if ($this->parcelsDepotId !== null) { |
||
| 151 | $boxElement->appendChild($document->createElement('parcelsDepotId', $this->parcelsDepotId)); |
||
| 152 | } |
||
| 153 | if ($this->parcelsDepotName !== null) { |
||
| 154 | $boxElement->appendChild($document->createElement('parcelsDepotName', $this->parcelsDepotName)); |
||
| 155 | } |
||
| 156 | if ($this->parcelsDepotAddress !== null) { |
||
| 157 | $boxElement->appendChild($this->parcelsDepotAddress->toXML($document)); |
||
| 158 | } |
||
| 159 | if ($this->memberId !== null) { |
||
| 160 | $boxElement->appendChild($document->createElement('memberId', $this->memberId)); |
||
| 161 | }else if ($this->unregistered !== null) { |
||
| 162 | $boxElement->appendChild($this->unregistered->toXML($document)); |
||
| 163 | } |
||
| 164 | |||
| 165 | if ($this->receiverName !== null) { |
||
| 166 | $boxElement->appendChild($document->createElement('receiverName', $this->receiverName)); |
||
| 167 | } |
||
| 168 | if ($this->receiverCompany !== null) { |
||
| 169 | $boxElement->appendChild($document->createElement('receiverCompany', $this->receiverCompany)); |
||
| 170 | } |
||
| 171 | |||
| 172 | $this->addToXmlRequestedDeliveryDate($document, $boxElement, $prefix); |
||
| 173 | |||
| 174 | return $nationalElement; |
||
| 175 | } |
||
| 176 | |||
| 177 | protected function addToXmlRequestedDeliveryDate(DOMDocument $document, DOMElement $typeElement, ?string $prefix): void |
||
| 183 | ); |
||
| 184 | } |
||
| 185 | } |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @throws BpostInvalidValueException |
||
| 189 | * @throws BpostNotImplementedException |
||
| 190 | * @throws BpostInvalidLengthException |
||
| 191 | */ |
||
| 192 | public static function createFromXML(SimpleXMLElement $xml, ?National $self = null): At247 |
||
| 242 | } |
||
| 243 | } |
||
| 244 |