FIX: Telefono sobre rango maximo de integer en MySQL

This commit is contained in:
Juan Pablo Vial
2025-08-05 15:41:23 -04:00
parent 307f2ac7d7
commit c38e89d3f1
5 changed files with 78 additions and 6 deletions

View File

@ -0,0 +1,28 @@
<?php
namespace Incoviba\Service\Valor;
class Phone
{
public function toDatabase(?string $phone): ?int
{
if ($phone === null) {
return null;
}
return (int) str_replace([' ', '+'], '', $phone) ?? null;
}
public function toDisplay(?int $phone): ?string
{
if ($phone === null) {
return null;
}
$parts = preg_split('/(?=<country>\d{2})?(?=<area>\d)(?=<first>\d{4})(?=<last>\d{4})/', $phone);
$output = [];
if (array_key_exists('country', $parts)) {
$output [] = "+{$parts[0]}";
}
$output [] = $parts[1] ?? '';
$output [] = $parts[2] ?? '';
$output [] = $parts[3] ?? '';
return implode(' ', $output);
}
}