| Total Complexity | 96 |
| Total Lines | 777 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Base 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 Base, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | abstract class Base |
||
| 22 | extends \Aimeos\MShop\Common\Item\Base |
||
| 23 | implements \Aimeos\MShop\Common\Item\Address\Iface |
||
| 24 | { |
||
| 25 | private string $prefix; |
||
| 26 | |||
| 27 | |||
| 28 | /** |
||
| 29 | * Initializes the address item. |
||
| 30 | * |
||
| 31 | * @param string $prefix Key prefix that should be used for toArray()/fromArray() like "customer.address." |
||
| 32 | * @param array $values Associative list of key/value pairs containing address data |
||
| 33 | */ |
||
| 34 | public function __construct( string $prefix, array $values = [] ) |
||
| 35 | { |
||
| 36 | parent::__construct( $prefix, $values, str_replace( '.', '/', rtrim( $prefix, '.' ) ) ); |
||
| 37 | |||
| 38 | $this->prefix = $prefix; |
||
| 39 | } |
||
| 40 | |||
| 41 | |||
| 42 | /** |
||
| 43 | * Returns the company name. |
||
| 44 | * |
||
| 45 | * @return string Company name |
||
| 46 | */ |
||
| 47 | public function getCompany() : string |
||
| 48 | { |
||
| 49 | return (string) $this->get( $this->prefix . 'company', '' ); |
||
| 50 | } |
||
| 51 | |||
| 52 | |||
| 53 | /** |
||
| 54 | * Sets a new company name. |
||
| 55 | * |
||
| 56 | * @param string|null $company New company name |
||
| 57 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 58 | */ |
||
| 59 | public function setCompany( ?string $company ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 60 | { |
||
| 61 | return $this->set( $this->prefix . 'company', (string) $company ); |
||
| 62 | } |
||
| 63 | |||
| 64 | |||
| 65 | /** |
||
| 66 | * Returns the vatid. |
||
| 67 | * |
||
| 68 | * @return string vatid |
||
| 69 | */ |
||
| 70 | public function getVatID() : string |
||
| 71 | { |
||
| 72 | return (string) $this->get( $this->prefix . 'vatid', '' ); |
||
| 73 | } |
||
| 74 | |||
| 75 | |||
| 76 | /** |
||
| 77 | * Sets a new vatid. |
||
| 78 | * |
||
| 79 | * @param string|null $vatid New vatid |
||
| 80 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 81 | */ |
||
| 82 | public function setVatID( ?string $vatid ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 83 | { |
||
| 84 | return $this->set( $this->prefix . 'vatid', str_replace( ' ', '', (string) $vatid ) ); |
||
| 85 | } |
||
| 86 | |||
| 87 | |||
| 88 | /** |
||
| 89 | * Returns the salutation constant for the person described by the address. |
||
| 90 | * |
||
| 91 | * @return string Saluatation code |
||
| 92 | */ |
||
| 93 | public function getSalutation() : string |
||
| 94 | { |
||
| 95 | return $this->get( $this->prefix . 'salutation', '' ); |
||
| 96 | } |
||
| 97 | |||
| 98 | |||
| 99 | /** |
||
| 100 | * Sets the new salutation for the person described by the address. |
||
| 101 | * |
||
| 102 | * @param string|null $salutation Salutation constant defined in \Aimeos\MShop\Common\Item\Address\Base |
||
| 103 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 104 | */ |
||
| 105 | public function setSalutation( ?string $salutation ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 106 | { |
||
| 107 | return $this->set( $this->prefix . 'salutation', $this->checkSalutation( (string) $salutation ) ); |
||
| 108 | } |
||
| 109 | |||
| 110 | |||
| 111 | /** |
||
| 112 | * Returns the title of the person. |
||
| 113 | * |
||
| 114 | * @return string Title of the person |
||
| 115 | */ |
||
| 116 | public function getTitle() : string |
||
| 117 | { |
||
| 118 | return $this->get( $this->prefix . 'title', '' ); |
||
| 119 | } |
||
| 120 | |||
| 121 | |||
| 122 | /** |
||
| 123 | * Sets a new title of the person. |
||
| 124 | * |
||
| 125 | * @param string|null $title New title of the person |
||
| 126 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 127 | */ |
||
| 128 | public function setTitle( ?string $title ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 129 | { |
||
| 130 | return $this->set( $this->prefix . 'title', (string) $title ); |
||
| 131 | } |
||
| 132 | |||
| 133 | |||
| 134 | /** |
||
| 135 | * Returns the first name of the person. |
||
| 136 | * |
||
| 137 | * @return string First name of the person |
||
| 138 | */ |
||
| 139 | public function getFirstname() : string |
||
| 140 | { |
||
| 141 | return $this->get( $this->prefix . 'firstname', '' ); |
||
| 142 | } |
||
| 143 | |||
| 144 | |||
| 145 | /** |
||
| 146 | * Sets a new first name of the person. |
||
| 147 | * |
||
| 148 | * @param string|null $firstname New first name of the person |
||
| 149 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 150 | */ |
||
| 151 | public function setFirstname( ?string $firstname ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 152 | { |
||
| 153 | return $this->set( $this->prefix . 'firstname', (string) $firstname ); |
||
| 154 | } |
||
| 155 | |||
| 156 | |||
| 157 | /** |
||
| 158 | * Returns the last name of the person. |
||
| 159 | * |
||
| 160 | * @return string Last name of the person |
||
| 161 | */ |
||
| 162 | public function getLastname() : string |
||
| 163 | { |
||
| 164 | return $this->get( $this->prefix . 'lastname', '' ); |
||
| 165 | } |
||
| 166 | |||
| 167 | |||
| 168 | /** |
||
| 169 | * Sets a new last name of the person. |
||
| 170 | * |
||
| 171 | * @param string|null $lastname New last name of the person |
||
| 172 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 173 | */ |
||
| 174 | public function setLastname( ?string $lastname ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 175 | { |
||
| 176 | return $this->set( $this->prefix . 'lastname', (string) $lastname ); |
||
| 177 | } |
||
| 178 | |||
| 179 | |||
| 180 | /** |
||
| 181 | * Returns the first address part, e.g. the street name. |
||
| 182 | * |
||
| 183 | * @return string First address part |
||
| 184 | */ |
||
| 185 | public function getAddress1() : string |
||
| 186 | { |
||
| 187 | return $this->get( $this->prefix . 'address1', '' ); |
||
| 188 | } |
||
| 189 | |||
| 190 | |||
| 191 | /** |
||
| 192 | * Sets a new first address part, e.g. the street name. |
||
| 193 | * |
||
| 194 | * @param string|null $address1 New first address part |
||
| 195 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 196 | */ |
||
| 197 | public function setAddress1( ?string $address1 ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 198 | { |
||
| 199 | return $this->set( $this->prefix . 'address1', (string) $address1 ); |
||
| 200 | } |
||
| 201 | |||
| 202 | |||
| 203 | /** |
||
| 204 | * Returns the second address part, e.g. the house number. |
||
| 205 | * |
||
| 206 | * @return string Second address part |
||
| 207 | */ |
||
| 208 | public function getAddress2() : string |
||
| 209 | { |
||
| 210 | return $this->get( $this->prefix . 'address2', '' ); |
||
| 211 | } |
||
| 212 | |||
| 213 | |||
| 214 | /** |
||
| 215 | * Sets a new second address part, e.g. the house number. |
||
| 216 | * |
||
| 217 | * @param string|null $address2 New second address part |
||
| 218 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 219 | */ |
||
| 220 | public function setAddress2( ?string $address2 ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 221 | { |
||
| 222 | return $this->set( $this->prefix . 'address2', (string) $address2 ); |
||
| 223 | } |
||
| 224 | |||
| 225 | |||
| 226 | /** |
||
| 227 | * Returns the third address part, e.g. the house name or floor number. |
||
| 228 | * |
||
| 229 | * @return string third address part |
||
| 230 | */ |
||
| 231 | public function getAddress3() : string |
||
| 232 | { |
||
| 233 | return $this->get( $this->prefix . 'address3', '' ); |
||
| 234 | } |
||
| 235 | |||
| 236 | |||
| 237 | /** |
||
| 238 | * Sets a new third address part, e.g. the house name or floor number. |
||
| 239 | * |
||
| 240 | * @param string|null $address3 New third address part |
||
| 241 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 242 | */ |
||
| 243 | public function setAddress3( ?string $address3 ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 244 | { |
||
| 245 | return $this->set( $this->prefix . 'address3', (string) $address3 ); |
||
| 246 | } |
||
| 247 | |||
| 248 | |||
| 249 | /** |
||
| 250 | * Returns the postal code. |
||
| 251 | * |
||
| 252 | * @return string Postal code |
||
| 253 | */ |
||
| 254 | public function getPostal() : string |
||
| 255 | { |
||
| 256 | return $this->get( $this->prefix . 'postal', '' ); |
||
| 257 | } |
||
| 258 | |||
| 259 | |||
| 260 | /** |
||
| 261 | * Sets a new postal code. |
||
| 262 | * |
||
| 263 | * @param string|null $postal New postal code |
||
| 264 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 265 | */ |
||
| 266 | public function setPostal( ?string $postal ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 267 | { |
||
| 268 | return $this->set( $this->prefix . 'postal', (string) $postal ); |
||
| 269 | } |
||
| 270 | |||
| 271 | |||
| 272 | /** |
||
| 273 | * Returns the city name. |
||
| 274 | * |
||
| 275 | * @return string City name |
||
| 276 | */ |
||
| 277 | public function getCity() : string |
||
| 278 | { |
||
| 279 | return $this->get( $this->prefix . 'city', '' ); |
||
| 280 | } |
||
| 281 | |||
| 282 | |||
| 283 | /** |
||
| 284 | * Sets a new city name. |
||
| 285 | * |
||
| 286 | * @param string|null $city New city name |
||
| 287 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 288 | */ |
||
| 289 | public function setCity( ?string $city ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 290 | { |
||
| 291 | return $this->set( $this->prefix . 'city', (string) $city ); |
||
| 292 | } |
||
| 293 | |||
| 294 | |||
| 295 | /** |
||
| 296 | * Returns the state name. |
||
| 297 | * |
||
| 298 | * @return string State name |
||
| 299 | */ |
||
| 300 | public function getState() : string |
||
| 301 | { |
||
| 302 | return $this->get( $this->prefix . 'state', '' ); |
||
| 303 | } |
||
| 304 | |||
| 305 | |||
| 306 | /** |
||
| 307 | * Sets a new state name. |
||
| 308 | * |
||
| 309 | * @param string|null $state New state name |
||
| 310 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 311 | */ |
||
| 312 | public function setState( ?string $state ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 313 | { |
||
| 314 | return $this->set( $this->prefix . 'state', (string) $state ); |
||
| 315 | } |
||
| 316 | |||
| 317 | |||
| 318 | /** |
||
| 319 | * Returns the unique ID of the country the address belongs to. |
||
| 320 | * |
||
| 321 | * @return string|null Unique ID of the country |
||
| 322 | */ |
||
| 323 | public function getCountryId() : ?string |
||
| 324 | { |
||
| 325 | return $this->get( $this->prefix . 'countryid' ); |
||
| 326 | } |
||
| 327 | |||
| 328 | |||
| 329 | /** |
||
| 330 | * Sets the ID of the country the address is in. |
||
| 331 | * |
||
| 332 | * @param string|null $countryid Unique ID of the country |
||
| 333 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 334 | */ |
||
| 335 | public function setCountryId( ?string $countryid ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 336 | { |
||
| 337 | return $this->set( $this->prefix . 'countryid', $this->checkCountryId( $countryid ) ); |
||
| 338 | } |
||
| 339 | |||
| 340 | |||
| 341 | /** |
||
| 342 | * Returns the unique ID of the language. |
||
| 343 | * |
||
| 344 | * @return string|null Unique ID of the language |
||
| 345 | */ |
||
| 346 | public function getLanguageId() : ?string |
||
| 347 | { |
||
| 348 | return $this->get( $this->prefix . 'languageid' ); |
||
| 349 | } |
||
| 350 | |||
| 351 | |||
| 352 | /** |
||
| 353 | * Sets the ID of the language. |
||
| 354 | * |
||
| 355 | * @param string|null $langid Unique ID of the language |
||
| 356 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 357 | */ |
||
| 358 | public function setLanguageId( ?string $langid ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 359 | { |
||
| 360 | return $this->set( $this->prefix . 'languageid', $this->checkLanguageId( $langid ) ); |
||
| 361 | } |
||
| 362 | |||
| 363 | |||
| 364 | /** |
||
| 365 | * Returns the telephone number. |
||
| 366 | * |
||
| 367 | * @return string Telephone number |
||
| 368 | */ |
||
| 369 | public function getTelephone() : string |
||
| 370 | { |
||
| 371 | return $this->get( $this->prefix . 'telephone', '' ); |
||
| 372 | } |
||
| 373 | |||
| 374 | |||
| 375 | /** |
||
| 376 | * Sets a new telephone number. |
||
| 377 | * |
||
| 378 | * @param string|null $telephone New telephone number |
||
| 379 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 380 | */ |
||
| 381 | public function setTelephone( ?string $telephone ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 382 | { |
||
| 383 | return $this->set( $this->prefix . 'telephone', (string) $telephone ); |
||
| 384 | } |
||
| 385 | |||
| 386 | |||
| 387 | /** |
||
| 388 | * Returns the telefax number. |
||
| 389 | * |
||
| 390 | * @return string Telefax number |
||
| 391 | */ |
||
| 392 | public function getTelefax() : string |
||
| 393 | { |
||
| 394 | return $this->get( $this->prefix . 'telefax', '' ); |
||
| 395 | } |
||
| 396 | |||
| 397 | |||
| 398 | /** |
||
| 399 | * Sets a new telefax number. |
||
| 400 | * |
||
| 401 | * @param string|null $telefax New telefax number |
||
| 402 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 403 | */ |
||
| 404 | public function setTelefax( ?string $telefax ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 405 | { |
||
| 406 | return $this->set( $this->prefix . 'telefax', (string) $telefax ); |
||
| 407 | } |
||
| 408 | |||
| 409 | |||
| 410 | /** |
||
| 411 | * Returns the mobile number. |
||
| 412 | * |
||
| 413 | * @return string Mobile number |
||
| 414 | */ |
||
| 415 | public function getMobile() : string |
||
| 416 | { |
||
| 417 | return $this->get( $this->prefix . 'mobile', '' ); |
||
| 418 | } |
||
| 419 | |||
| 420 | |||
| 421 | /** |
||
| 422 | * Sets a new mobile number. |
||
| 423 | * |
||
| 424 | * @param string|null $value New mobile number |
||
| 425 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 426 | */ |
||
| 427 | public function setMobile( ?string $value ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 428 | { |
||
| 429 | return $this->set( $this->prefix . 'mobile', (string) $value ); |
||
| 430 | } |
||
| 431 | |||
| 432 | |||
| 433 | /** |
||
| 434 | * Returns the email address. |
||
| 435 | * |
||
| 436 | * @return string Email address |
||
| 437 | */ |
||
| 438 | public function getEmail() : string |
||
| 439 | { |
||
| 440 | return $this->get( $this->prefix . 'email', '' ); |
||
| 441 | } |
||
| 442 | |||
| 443 | |||
| 444 | /** |
||
| 445 | * Sets a new email address. |
||
| 446 | * |
||
| 447 | * @param string|null $email New email address |
||
| 448 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 449 | */ |
||
| 450 | public function setEmail( ?string $email ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 451 | { |
||
| 452 | $email = (string) $email; |
||
| 453 | $regex = '/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD'; |
||
| 454 | |||
| 455 | if( $email != '' && preg_match( $regex, $email ) !== 1 ) { |
||
| 456 | throw new \Aimeos\MShop\Exception( sprintf( 'Invalid characters in email address: "%1$s"', $email ) ); |
||
| 457 | } |
||
| 458 | |||
| 459 | return $this->set( $this->prefix . 'email', $email ); |
||
| 460 | } |
||
| 461 | |||
| 462 | |||
| 463 | /** |
||
| 464 | * Returns the website URL. |
||
| 465 | * |
||
| 466 | * @return string Website URL |
||
| 467 | */ |
||
| 468 | public function getWebsite() : string |
||
| 471 | } |
||
| 472 | |||
| 473 | |||
| 474 | /** |
||
| 475 | * Sets a new website URL. |
||
| 476 | * |
||
| 477 | * @param string|null $website New website URL |
||
| 478 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 479 | */ |
||
| 480 | public function setWebsite( ?string $website ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 481 | { |
||
| 482 | $website = (string) $website; |
||
| 483 | $pattern = '#^([a-z]+://)?[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)+(:[0-9]+)?(/.*)?$#'; |
||
| 484 | |||
| 485 | if( $website != '' && preg_match( $pattern, $website ) !== 1 ) { |
||
| 486 | throw new \Aimeos\MShop\Exception( sprintf( 'Invalid web site URL "%1$s"', $website ) ); |
||
| 487 | } |
||
| 488 | |||
| 489 | return $this->set( $this->prefix . 'website', $website ); |
||
| 490 | } |
||
| 491 | |||
| 492 | |||
| 493 | /** |
||
| 494 | * Returns the longitude coordinate of the customer address |
||
| 495 | * |
||
| 496 | * @return float|null Longitude coordinate as decimal value or null |
||
| 497 | */ |
||
| 498 | public function getLongitude() : ?float |
||
| 499 | { |
||
| 500 | if( ( $result = $this->get( $this->prefix . 'longitude' ) ) !== null ) { |
||
| 501 | return (float) $result; |
||
| 502 | } |
||
| 503 | |||
| 504 | return null; |
||
| 505 | } |
||
| 506 | |||
| 507 | |||
| 508 | /** |
||
| 509 | * Sets the longitude coordinate of the customer address |
||
| 510 | * |
||
| 511 | * @param string|null $value Longitude coordinate as decimal value or null |
||
| 512 | * @return \Aimeos\MShop\Customer\Item\Iface Customer address item for chaining method calls |
||
| 513 | */ |
||
| 514 | public function setLongitude( ?string $value ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 515 | { |
||
| 516 | return $this->set( $this->prefix . 'longitude', $value !== '' && $value !== null ? $value : null ); |
||
| 517 | } |
||
| 518 | |||
| 519 | |||
| 520 | /** |
||
| 521 | * Returns the latitude coordinate of the customer address |
||
| 522 | * |
||
| 523 | * @return float|null Latitude coordinate as decimal value or null |
||
| 524 | */ |
||
| 525 | public function getLatitude() : ?float |
||
| 526 | { |
||
| 527 | if( ( $result = $this->get( $this->prefix . 'latitude' ) ) !== null ) { |
||
| 528 | return (float) $result; |
||
| 529 | } |
||
| 530 | |||
| 531 | return null; |
||
| 532 | } |
||
| 533 | |||
| 534 | |||
| 535 | /** |
||
| 536 | * Sets the latitude coordinate of the customer address |
||
| 537 | * |
||
| 538 | * @param string|null $value Latitude coordinate as decimal value or null |
||
| 539 | * @return \Aimeos\MShop\Customer\Item\Iface Customer address item for chaining method calls |
||
| 540 | */ |
||
| 541 | public function setLatitude( ?string $value ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 542 | { |
||
| 543 | return $this->set( $this->prefix . 'latitude', $value !== '' && $value !== null ? $value : null ); |
||
| 544 | } |
||
| 545 | |||
| 546 | |||
| 547 | /** |
||
| 548 | * Returns the birthday of the customer item. |
||
| 549 | * |
||
| 550 | * @return string|null Birthday in YYYY-MM-DD format |
||
| 551 | */ |
||
| 552 | public function getBirthday() : ?string |
||
| 553 | { |
||
| 554 | return $this->get( $this->prefix . 'birthday' ); |
||
| 555 | } |
||
| 556 | |||
| 557 | |||
| 558 | /** |
||
| 559 | * Sets the birthday of the customer item. |
||
| 560 | * |
||
| 561 | * @param string|null $value Birthday of the customer item |
||
| 562 | * @return \Aimeos\MShop\Common\Item\Address\Iface Customer address item for chaining method calls |
||
| 563 | */ |
||
| 564 | public function setBirthday( ?string $value ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 565 | { |
||
| 566 | return $this->set( $this->prefix . 'birthday', $this->checkDateOnlyFormat( $value ) ); |
||
| 567 | } |
||
| 568 | |||
| 569 | |||
| 570 | /** |
||
| 571 | * Returns the customer ID this address belongs to |
||
| 572 | * |
||
| 573 | * @return string|null Customer ID of the address |
||
| 574 | */ |
||
| 575 | public function getParentId() : ?string |
||
| 576 | { |
||
| 577 | return $this->get( $this->prefix . 'parentid' ); |
||
| 578 | } |
||
| 579 | |||
| 580 | |||
| 581 | /** |
||
| 582 | * Sets the new customer ID this address belongs to |
||
| 583 | * |
||
| 584 | * @param string|null $parentid New customer ID of the address |
||
| 585 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 586 | */ |
||
| 587 | public function setParentId( ?string $parentid ) : \Aimeos\MShop\Common\Item\Iface |
||
| 588 | { |
||
| 589 | return $this->set( $this->prefix . 'parentid', $parentid ); |
||
| 590 | } |
||
| 591 | |||
| 592 | |||
| 593 | /** |
||
| 594 | * Returns the position of the address item. |
||
| 595 | * |
||
| 596 | * @return int Position of the address item |
||
| 597 | */ |
||
| 598 | public function getPosition() : int |
||
| 599 | { |
||
| 600 | return $this->get( $this->prefix . 'position', 0 ); |
||
| 601 | } |
||
| 602 | |||
| 603 | |||
| 604 | /** |
||
| 605 | * Sets the Position of the address item. |
||
| 606 | * |
||
| 607 | * @param int $position Position of the address item |
||
| 608 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 609 | */ |
||
| 610 | public function setPosition( int $position ) : \Aimeos\MShop\Common\Item\Iface |
||
| 613 | } |
||
| 614 | |||
| 615 | |||
| 616 | /** |
||
| 617 | * Returns the type of the address item. |
||
| 618 | * |
||
| 619 | * @return string Address type |
||
| 620 | */ |
||
| 621 | public function getType() : string |
||
| 622 | { |
||
| 623 | return $this->get( $this->prefix . 'type', 'delivery' ); |
||
| 624 | } |
||
| 625 | |||
| 626 | |||
| 627 | /** |
||
| 628 | * Sets the type of the address item. |
||
| 629 | * |
||
| 630 | * @param string $type Address type |
||
| 631 | * @return \Aimeos\MShop\Common\Item\Address\Iface Address item for chaining method calls |
||
| 632 | */ |
||
| 633 | public function setType( string $type ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 636 | } |
||
| 637 | |||
| 638 | |||
| 639 | /** |
||
| 640 | * Copies the values of the address item into another one. |
||
| 641 | * |
||
| 642 | * @param \Aimeos\MShop\Common\Item\Address\Iface $item Address item |
||
| 643 | * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls |
||
| 644 | */ |
||
| 645 | public function copyFrom( \Aimeos\MShop\Common\Item\Address\Iface $item ) : \Aimeos\MShop\Common\Item\Address\Iface |
||
| 646 | { |
||
| 647 | $values = $item->toArray(); |
||
| 648 | $this->fromArray( $values ); |
||
| 649 | |||
| 650 | $this->setType( $item->getType() ); |
||
| 651 | $this->setCompany( $item->getCompany() ); |
||
| 652 | $this->setVatID( $item->getVatID() ); |
||
| 653 | $this->setSalutation( $item->getSalutation() ); |
||
| 654 | $this->setTitle( $item->getTitle() ); |
||
| 655 | $this->setFirstname( $item->getFirstname() ); |
||
| 656 | $this->setLastname( $item->getLastname() ); |
||
| 657 | $this->setAddress1( $item->getAddress1() ); |
||
| 658 | $this->setAddress2( $item->getAddress2() ); |
||
| 659 | $this->setAddress3( $item->getAddress3() ); |
||
| 660 | $this->setPostal( $item->getPostal() ); |
||
| 661 | $this->setCity( $item->getCity() ); |
||
| 662 | $this->setState( $item->getState() ); |
||
| 663 | $this->setCountryId( $item->getCountryId() ); |
||
| 664 | $this->setLanguageId( $item->getLanguageId() ); |
||
| 665 | $this->setTelephone( $item->getTelephone() ); |
||
| 666 | $this->setTelefax( $item->getTelefax() ); |
||
| 667 | $this->setMobile( $item->getMobile() ); |
||
| 668 | $this->setEmail( $item->getEmail() ); |
||
| 669 | $this->setWebsite( $item->getWebsite() ); |
||
| 670 | $this->setLongitude( $item->getLongitude() ); |
||
| 671 | $this->setLatitude( $item->getLatitude() ); |
||
| 672 | $this->setBirthday( $item->getBirthday() ); |
||
| 673 | |||
| 674 | return $this; |
||
| 675 | } |
||
| 676 | |||
| 677 | |||
| 678 | /* |
||
| 679 | * Sets the item values from the given array and removes that entries from the list |
||
| 680 | * |
||
| 681 | * @param array &$list Associative list of item keys and their values |
||
| 682 | * @param bool True to set private properties too, false for public only |
||
| 683 | * @return \Aimeos\MShop\Common\Item\Address\Iface Address item for chaining method calls |
||
| 684 | */ |
||
| 685 | public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface |
||
| 728 | } |
||
| 729 | |||
| 730 | |||
| 731 | /** |
||
| 732 | * Returns the item values as array. |
||
| 733 | * |
||
| 734 | * @param bool True to return private properties, false for public only |
||
| 735 | * @return array Associative list of item properties and their values |
||
| 736 | */ |
||
| 737 | public function toArray( bool $private = false ) : array |
||
| 738 | { |
||
| 739 | $list = parent::toArray( $private ); |
||
| 740 | |||
| 741 | $list[$this->prefix . 'type'] = $this->getType(); |
||
| 742 | $list[$this->prefix . 'salutation'] = $this->getSalutation(); |
||
| 743 | $list[$this->prefix . 'company'] = $this->getCompany(); |
||
| 744 | $list[$this->prefix . 'vatid'] = $this->getVatID(); |
||
| 745 | $list[$this->prefix . 'title'] = $this->getTitle(); |
||
| 746 | $list[$this->prefix . 'firstname'] = $this->getFirstname(); |
||
| 747 | $list[$this->prefix . 'lastname'] = $this->getLastname(); |
||
| 748 | $list[$this->prefix . 'address1'] = $this->getAddress1(); |
||
| 749 | $list[$this->prefix . 'address2'] = $this->getAddress2(); |
||
| 750 | $list[$this->prefix . 'address3'] = $this->getAddress3(); |
||
| 751 | $list[$this->prefix . 'postal'] = $this->getPostal(); |
||
| 752 | $list[$this->prefix . 'city'] = $this->getCity(); |
||
| 753 | $list[$this->prefix . 'state'] = $this->getState(); |
||
| 754 | $list[$this->prefix . 'countryid'] = $this->getCountryId(); |
||
| 755 | $list[$this->prefix . 'languageid'] = $this->getLanguageId(); |
||
| 756 | $list[$this->prefix . 'telephone'] = $this->getTelephone(); |
||
| 757 | $list[$this->prefix . 'telefax'] = $this->getTelefax(); |
||
| 758 | $list[$this->prefix . 'mobile'] = $this->getMobile(); |
||
| 759 | $list[$this->prefix . 'email'] = $this->getEmail(); |
||
| 760 | $list[$this->prefix . 'website'] = $this->getWebsite(); |
||
| 761 | $list[$this->prefix . 'longitude'] = $this->getLongitude(); |
||
| 762 | $list[$this->prefix . 'latitude'] = $this->getLatitude(); |
||
| 763 | $list[$this->prefix . 'birthday'] = $this->getBirthday(); |
||
| 764 | $list[$this->prefix . 'position'] = $this->getPosition(); |
||
| 765 | |||
| 766 | if( $private === true ) { |
||
| 767 | $list[$this->prefix . 'parentid'] = $this->getParentId(); |
||
| 768 | } |
||
| 769 | |||
| 770 | return $list; |
||
| 771 | } |
||
| 772 | |||
| 773 | |||
| 774 | /** |
||
| 775 | * Checks the given address salutation is valid |
||
| 776 | * |
||
| 777 | * @param string $value Address salutation defined in \Aimeos\MShop\Common\Item\Address\Base |
||
| 778 | * @throws \Aimeos\MShop\Exception If salutation is invalid |
||
| 779 | */ |
||
| 780 | protected function checkSalutation( string $value ) |
||
| 787 | } |
||
| 788 | |||
| 789 | |||
| 790 | /** |
||
| 791 | * Returns the prefix for toArray() and fromArray() methods. |
||
| 792 | * |
||
| 793 | * @return string Prefix for toArray() and fromArray() methods |
||
| 794 | */ |
||
| 795 | protected function prefix() : string |
||
| 796 | { |
||
| 800 |