55/**
66 * Formats phone numbers.
77 */
8+
89class PhoneNumber implements IFormatter
910{
10- public function format ( $ Data ): string
11- {
12- $ Phone = preg_replace ("/[^0-9]/ " , "" , $ Data );
11+ /**
12+ * @param string $Data
13+ * @return string|null
14+ */
15+
16+ public function format ( string $ Data ): ?string
17+ {
18+ $ Phone = preg_replace ("/[^0-9]/ " , "" , $ Data );
1319
14- if ( strlen ( $ Phone ) == 7 )
15- {
16- $ Phone = $ this ->format7Digit ( $ Phone );
17- }
18- else if ( strlen ( $ Phone ) == 10 )
19- {
20- $ Phone = $ this ->format10Digit ( $ Phone );
21- }
22- else if ( strlen ( $ Phone ) > 10 )
23- {
24- $ Phone = $ this ->formatInternational ( $ Phone );
25- }
20+ if ( strlen ( $ Phone ) == 7 )
21+ {
22+ $ Phone = $ this ->format7Digit ( $ Phone );
23+ }
24+ else if ( strlen ( $ Phone ) == 10 )
25+ {
26+ $ Phone = $ this ->format10Digit ( $ Phone );
27+ }
28+ else if ( strlen ( $ Phone ) > 10 )
29+ {
30+ $ Phone = $ this ->formatInternational ( $ Phone );
31+ }
2632
27- return $ Phone ;
28- }
33+ return $ Phone ;
34+ }
2935
3036 /**
3137 * @param array|string|null $Phone
3238 * @return string
3339 */
40+
3441 protected function format7Digit ( array |string |null $ Phone ): string
3542 {
3643 $ Pre = substr ( $ Phone , 0 , 3 );
@@ -44,6 +51,7 @@ protected function format7Digit( array|string|null $Phone ): string
4451 * @param array|string|null $Phone
4552 * @return string
4653 */
54+
4755 protected function format10Digit ( array |string |null $ Phone ): string
4856 {
4957 $ Area = substr ( $ Phone , 0 , 3 );
@@ -58,6 +66,7 @@ protected function format10Digit( array|string|null $Phone ): string
5866 * @param array|string|null $Phone
5967 * @return string
6068 */
69+
6170 protected function formatInternational ( array |string |null $ Phone ): string
6271 {
6372 $ CountryCode = substr ($ Phone , 0 , strlen ($ Phone ) - 10 );
0 commit comments