Skip to content

Commit 9ba663f

Browse files
committed
wip: Add sha256_phone_number
1 parent 094c498 commit 9ba663f

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/Helper/UserDataHelper.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
class UserDataHelper
66
{
77
private array $sha256_email_address = [];
8+
private array $sha256_phone_number = [];
89

910
/**
1011
* @param string $email Valid email format
@@ -25,7 +26,7 @@ public function addEmail(string $email): int
2526
$x = explode("@", $email, 2);
2627
if (substr($x[1], -mb_strlen("googlemail.com")) == "googlemail.com") {
2728
// https://support.google.com/mail/thread/125577450/gmail-and-googlemail?hl=en
28-
$x[1] = "gmail.com"; //
29+
$x[1] = "gmail.com";
2930
}
3031
$x[0] = explode("+", $x[0], 2)[0]; // https://gmail.googleblog.com/2008/03/2-hidden-ways-to-get-more-from-your.html
3132
$x[0] = str_replace(".", "", $x[0]);
@@ -39,4 +40,26 @@ public function addEmail(string $email): int
3940
$this->sha256_email_address = array_filter($this->sha256_email_address, fn ($v) => $v != $email);
4041
return array_push($this->sha256_email_address, $email) - 1;
4142
}
43+
44+
/**
45+
* This converst prefix and number into international approved numbers
46+
* @param int $number fully international number (without dashes or plus) eg. \
47+
* "+1-123-4567890" for USA or\
48+
* "+44-1234-5678900" for UK or\
49+
* "+45-12345678" for DK
50+
* @return int Cursor of array or -1 for error
51+
*/
52+
public function addPhone(int $number): int
53+
{
54+
$sNumber = (string)$number;
55+
if (strlen($sNumber) < 1 || strlen($sNumber) > 15) {
56+
return -1;
57+
}
58+
59+
$sNumber = hash("sha256", "+{$sNumber}");
60+
61+
// Skip duplicated and append phone number
62+
$this->sha256_phone_number = array_filter($this->sha256_phone_number, fn ($v) => $v != $sNumber);
63+
return array_push($this->sha256_phone_number, $sNumber) - 1;
64+
}
4265
}

0 commit comments

Comments
 (0)