Skip to content

Commit

Permalink
add phone default country code (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
alekitto authored Oct 5, 2020
2 parents 2352fad + ba90521 commit 2420437
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/Model/Document/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ abstract class Document implements \JsonSerializable
public $vatIncluded;

/**
* INPS compensation (not available in TransportDocument and SupplierOrder)
* INPS compensation (not available in TransportDocument and SupplierOrder).
*
* @var float
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Model/Document/Good.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function jsonSerialize(): array
'sconto_rosso' => $this->highlightDiscount,
'in_ddt' => $this->inTransportDocument,
'magazzino' => $this->fromWarehouse,
'giacenza_iniziale' => $this->initialStock
'giacenza_iniziale' => $this->initialStock,
], static function ($value): bool {
return null !== $value && '' !== $value;
});
Expand Down
25 changes: 17 additions & 8 deletions lib/Model/Subject/Subject.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ abstract class Subject implements \JsonSerializable
*/
private $originalData;

/**
* The default phone country code.
*
* @var string|null
*/
private static $defaultPhoneCountryCode = null;

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -148,15 +155,9 @@ public function &__set($name, $value)
{
switch ($name) {
case 'phone':
$value = $value ?
PhoneNumberUtil::getInstance()->parse($value, 'IT') :
null;
break;

case 'fax':
$value = $value ?
PhoneNumberUtil::getInstance()->parse($value, 'IT') :
null;
$defaultPhoneCountryCode = static::$defaultPhoneCountryCode ?? 'IT';
$value = $value ? PhoneNumberUtil::getInstance()->parse($value, $defaultPhoneCountryCode) : null;
break;

default:
Expand Down Expand Up @@ -324,4 +325,12 @@ public function fromArray(array $data): self

return $this;
}

/**
* Set default phone country code.
*/
public static function setDefaultPhoneCountryCode(string $defaultPhoneCountryCode): void
{
static::$defaultPhoneCountryCode = $defaultPhoneCountryCode;
}
}

0 comments on commit 2420437

Please sign in to comment.