recreate project
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class PhoneFormatterService
|
||||
{
|
||||
/**
|
||||
* Format a raw phone number to (xxx)-xxx-xxxx format
|
||||
*
|
||||
* @param string $number
|
||||
* @return string|null
|
||||
*/
|
||||
public function formatPhoneNumber(string $number): ?string
|
||||
{
|
||||
// Remove non-digit characters
|
||||
$digits = preg_replace('/\D/', '', $number);
|
||||
|
||||
// Ensure it's exactly 10 digits
|
||||
if (strlen($digits) === 10) {
|
||||
return sprintf(
|
||||
'%s-%s-%s',
|
||||
substr($digits, 0, 3),
|
||||
substr($digits, 3, 3),
|
||||
substr($digits, 6)
|
||||
);
|
||||
}
|
||||
|
||||
// Invalid number
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user