| Total Complexity | 42 |
| Total Lines | 324 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Standard 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 Standard, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class Standard |
||
| 25 | extends \Aimeos\MShop\Order\Item\Base |
||
| 26 | implements \Aimeos\MShop\Order\Item\Iface |
||
| 27 | { |
||
| 28 | private $baseItem; |
||
| 29 | |||
| 30 | |||
| 31 | /** |
||
| 32 | * Initializes the object with the given values. |
||
| 33 | * |
||
| 34 | * @param array $values Associative list of values from database |
||
| 35 | * @param \Aimeos\MShop\Order\Item\Base\Iface|null $baseItem Order basket if available |
||
| 36 | */ |
||
| 37 | public function __construct( array $values = [], ?\Aimeos\MShop\Order\Item\Base\Iface $baseItem = null ) |
||
| 41 | } |
||
| 42 | |||
| 43 | |||
| 44 | /** |
||
| 45 | * Returns the order number |
||
| 46 | * |
||
| 47 | * @return string Order number |
||
| 48 | */ |
||
| 49 | public function getOrderNumber() : string |
||
| 50 | { |
||
| 51 | if( $fcn = self::method( 'ordernumber' ) ) { |
||
| 52 | return (string) $fcn( $this ); |
||
| 53 | } |
||
| 54 | |||
| 55 | return (string) $this->getId(); |
||
| 56 | } |
||
| 57 | |||
| 58 | |||
| 59 | /** |
||
| 60 | * Returns the associated order base item |
||
| 61 | * |
||
| 62 | * @return \Aimeos\MShop\Order\Item\Base\Iface|null Order base item |
||
| 63 | */ |
||
| 64 | public function getBaseItem() : ?\Aimeos\MShop\Order\Item\Base\Iface |
||
| 65 | { |
||
| 66 | return $this->baseItem; |
||
| 67 | } |
||
| 68 | |||
| 69 | |||
| 70 | /** |
||
| 71 | * Sets the associated order base item |
||
| 72 | * |
||
| 73 | * @return \Aimeos\MShop\Order\Item\Base\Iface Order base item |
||
| 74 | */ |
||
| 75 | public function setBaseItem( \Aimeos\MShop\Order\Item\Base\Iface $baseItem ) : \Aimeos\MShop\Order\Item\Iface |
||
| 76 | { |
||
| 77 | $this->baseItem = $baseItem; |
||
| 78 | return $this; |
||
| 79 | } |
||
| 80 | |||
| 81 | |||
| 82 | /** |
||
| 83 | * Returns the basic order ID. |
||
| 84 | * |
||
| 85 | * @return string|null Basic order ID |
||
| 86 | */ |
||
| 87 | public function getBaseId() : ?string |
||
| 88 | { |
||
| 89 | return $this->get( 'order.baseid' ); |
||
| 90 | } |
||
| 91 | |||
| 92 | |||
| 93 | /** |
||
| 94 | * Sets the ID of the basic order item which contains the order details. |
||
| 95 | * |
||
| 96 | * @param string $id ID of the basic order item |
||
| 97 | * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls |
||
| 98 | */ |
||
| 99 | public function setBaseId( string $id ) : \Aimeos\MShop\Order\Item\Iface |
||
| 100 | { |
||
| 101 | return $this->set( 'order.baseid', $id ); |
||
| 102 | } |
||
| 103 | |||
| 104 | |||
| 105 | /** |
||
| 106 | * Returns the type of the invoice (repeating, web, phone, etc). |
||
| 107 | * |
||
| 108 | * @return string Invoice type |
||
| 109 | */ |
||
| 110 | public function getType() : string |
||
| 113 | } |
||
| 114 | |||
| 115 | |||
| 116 | /** |
||
| 117 | * Sets the type of the invoice. |
||
| 118 | * |
||
| 119 | * @param string $type Invoice type |
||
| 120 | * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls |
||
| 121 | */ |
||
| 122 | public function setType( string $type ) : \Aimeos\MShop\Common\Item\Iface |
||
| 123 | { |
||
| 124 | return $this->set( 'order.type', $this->checkCode( $type ) ); |
||
| 125 | } |
||
| 126 | |||
| 127 | |||
| 128 | /** |
||
| 129 | * Returns the delivery date of the invoice. |
||
| 130 | * |
||
| 131 | * @return string|null ISO date in yyyy-mm-dd HH:ii:ss format |
||
| 132 | */ |
||
| 133 | public function getDateDelivery() : ?string |
||
| 134 | { |
||
| 135 | $value = $this->get( 'order.datedelivery' ); |
||
| 136 | return $value ? substr( $value, 0, 19 ) : null; |
||
| 137 | } |
||
| 138 | |||
| 139 | |||
| 140 | /** |
||
| 141 | * Sets the delivery date of the invoice. |
||
| 142 | * |
||
| 143 | * @param string|null $date ISO date in yyyy-mm-dd HH:ii:ss format |
||
| 144 | * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls |
||
| 145 | */ |
||
| 146 | public function setDateDelivery( ?string $date ) : \Aimeos\MShop\Order\Item\Iface |
||
| 147 | { |
||
| 148 | return $this->set( 'order.datedelivery', $this->checkDateFormat( $date ) ); |
||
| 149 | } |
||
| 150 | |||
| 151 | |||
| 152 | /** |
||
| 153 | * Returns the purchase date of the invoice. |
||
| 154 | * |
||
| 155 | * @return string|null ISO date in yyyy-mm-dd HH:ii:ss format |
||
| 156 | */ |
||
| 157 | public function getDatePayment() : ?string |
||
| 158 | { |
||
| 159 | $value = $this->get( 'order.datepayment' ); |
||
| 160 | return $value ? substr( $value, 0, 19 ) : null; |
||
| 161 | } |
||
| 162 | |||
| 163 | |||
| 164 | /** |
||
| 165 | * Sets the purchase date of the invoice. |
||
| 166 | * |
||
| 167 | * @param string|null $date ISO date in yyyy-mm-dd HH:ii:ss format |
||
| 168 | * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls |
||
| 169 | */ |
||
| 170 | public function setDatePayment( ?string $date ) : \Aimeos\MShop\Order\Item\Iface |
||
| 173 | } |
||
| 174 | |||
| 175 | |||
| 176 | /** |
||
| 177 | * Returns the delivery status of the invoice. |
||
| 178 | * |
||
| 179 | * @return int Status code constant from \Aimeos\MShop\Order\Item\Base |
||
| 180 | */ |
||
| 181 | public function getStatusDelivery() : ?int |
||
| 184 | } |
||
| 185 | |||
| 186 | |||
| 187 | /** |
||
| 188 | * @deprecated 2022.01 |
||
| 189 | */ |
||
| 190 | public function getDeliveryStatus() : ?int |
||
| 193 | } |
||
| 194 | |||
| 195 | |||
| 196 | /** |
||
| 197 | * Sets the delivery status of the invoice. |
||
| 198 | * |
||
| 199 | * @param int|null $status Status code constant from \Aimeos\MShop\Order\Item\Base |
||
| 200 | * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls |
||
| 201 | */ |
||
| 202 | public function setStatusDelivery( ?int $status ) : \Aimeos\MShop\Order\Item\Iface |
||
| 203 | { |
||
| 204 | if( $status !== null ) { |
||
| 205 | $this->set( '.statusdelivery', $this->get( 'order.statusdelivery' ) ); |
||
| 206 | } |
||
| 207 | |||
| 208 | return $this->set( 'order.statusdelivery', $status ); |
||
| 209 | } |
||
| 210 | |||
| 211 | |||
| 212 | /** |
||
| 213 | * @deprecated 2022.01 |
||
| 214 | */ |
||
| 215 | public function setDeliveryStatus( ?int $status ) : \Aimeos\MShop\Order\Item\Iface |
||
| 216 | { |
||
| 217 | return $this->setStatusDelivery( $status ); |
||
| 218 | } |
||
| 219 | |||
| 220 | |||
| 221 | /** |
||
| 222 | * Returns the payment status of the invoice. |
||
| 223 | * |
||
| 224 | * @return int Payment constant from \Aimeos\MShop\Order\Item\Base |
||
| 225 | */ |
||
| 226 | public function getStatusPayment() : ?int |
||
| 227 | { |
||
| 228 | return $this->get( 'order.statuspayment' ); |
||
| 229 | } |
||
| 230 | |||
| 231 | |||
| 232 | /** |
||
| 233 | * @deprecated 2022.01 |
||
| 234 | */ |
||
| 235 | public function getPaymentStatus() : ?int |
||
| 236 | { |
||
| 237 | return $this->getStatusPayment(); |
||
| 238 | } |
||
| 239 | |||
| 240 | |||
| 241 | /** |
||
| 242 | * Sets the payment status of the invoice. |
||
| 243 | * |
||
| 244 | * @param int|null $status Payment constant from \Aimeos\MShop\Order\Item\Base |
||
| 245 | * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls |
||
| 246 | */ |
||
| 247 | public function setStatusPayment( ?int $status ) : \Aimeos\MShop\Order\Item\Iface |
||
| 248 | { |
||
| 249 | if( $status !== $this->getStatusPayment() ) { |
||
| 250 | $this->set( 'order.datepayment', date( 'Y-m-d H:i:s' ) ); |
||
| 251 | } |
||
| 252 | |||
| 253 | if( $status !== null ) { |
||
| 254 | $this->set( '.statuspayment', $this->get( 'order.statuspayment' ) ); |
||
| 255 | } |
||
| 256 | |||
| 257 | return $this->set( 'order.statuspayment', $status ); |
||
| 258 | } |
||
| 259 | |||
| 260 | |||
| 261 | /** |
||
| 262 | * @deprecated 2022.01 |
||
| 263 | */ |
||
| 264 | public function setPaymentStatus( ?int $status ) : \Aimeos\MShop\Order\Item\Iface |
||
| 265 | { |
||
| 266 | return $this->setStatusPayment( $status ); |
||
| 267 | } |
||
| 268 | |||
| 269 | |||
| 270 | /** |
||
| 271 | * Returns the related invoice ID. |
||
| 272 | * |
||
| 273 | * @return string|null Related invoice ID |
||
| 274 | */ |
||
| 275 | public function getRelatedId() : ?string |
||
| 276 | { |
||
| 277 | return $this->get( 'order.relatedid' ); |
||
| 278 | } |
||
| 279 | |||
| 280 | |||
| 281 | /** |
||
| 282 | * Sets the related invoice ID. |
||
| 283 | * |
||
| 284 | * @param string|null $id Related invoice ID |
||
| 285 | * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls |
||
| 286 | * @throws \Aimeos\MShop\Order\Exception If ID is invalid |
||
| 287 | */ |
||
| 288 | public function setRelatedId( ?string $id ) : \Aimeos\MShop\Order\Item\Iface |
||
| 289 | { |
||
| 290 | return $this->set( 'order.relatedid', $id ); |
||
| 291 | } |
||
| 292 | |||
| 293 | |||
| 294 | /* |
||
| 295 | * Sets the item values from the given array and removes that entries from the list |
||
| 296 | * |
||
| 297 | * @param array &$list Associative list of item keys and their values |
||
| 298 | * @param bool True to set private properties too, false for public only |
||
| 299 | * @return \Aimeos\MShop\Order\Item\Iface Order item for chaining method calls |
||
| 300 | */ |
||
| 301 | public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface |
||
| 302 | { |
||
| 303 | $item = parent::fromArray( $list, $private ); |
||
| 304 | |||
| 305 | foreach( $list as $key => $value ) |
||
| 306 | { |
||
| 307 | switch( $key ) |
||
| 308 | { |
||
| 309 | case 'order.baseid': !$private ?: $item = $item->setBaseId( $value ); break; |
||
|
|
|||
| 310 | case 'order.type': $item = $item->setType( $value ); break; |
||
| 311 | case 'order.statusdelivery': $item = $item->setStatusDelivery( $value !== null ? (int) $value : null ); break; |
||
| 312 | case 'order.statuspayment': $item = $item->setStatusPayment( $value !== null ? (int) $value : null ); break; |
||
| 313 | case 'order.datedelivery': $item = $item->setDateDelivery( $value ); break; |
||
| 314 | case 'order.datepayment': $item = $item->setDatePayment( $value ); break; |
||
| 315 | case 'order.relatedid': $item = $item->setRelatedId( $value ); break; |
||
| 316 | default: continue 2; |
||
| 317 | } |
||
| 318 | |||
| 319 | unset( $list[$key] ); |
||
| 320 | } |
||
| 321 | |||
| 322 | return $item; |
||
| 323 | } |
||
| 324 | |||
| 325 | |||
| 326 | /** |
||
| 327 | * Returns the item values as array. |
||
| 328 | * |
||
| 329 | * @param bool True to return private properties, false for public only |
||
| 330 | * @return array Associative list of item properties and their values |
||
| 331 | */ |
||
| 332 | public function toArray( bool $private = false ) : array |
||
| 348 | } |
||
| 349 | } |
||
| 350 |