Skip to content

Commit 4eae775

Browse files
thisismeonmounteverestthisismeonmounteverest
authored andcommitted
Add check for phone number and email address in relation comment.
1 parent ab77245 commit 4eae775

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/Controller/RelationController.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function add(Request $request, Member $member, Mailer $mailer): Response
5656
if ($form->isSubmitted() && $form->isValid()) {
5757
/** @var Relation $relation */
5858
$relation = $form->getData();
59-
if (!checkForEmailAddress($relation) && !checkForPhoneNumber($relation)) {
59+
if (!$this->checkForEmailAddress($relation) && !$this->checkForPhoneNumber($relation)) {
6060
$relation->setOwner($loggedInMember);
6161
$relation->setReceiver($member);
6262

@@ -211,4 +211,20 @@ private function findRelationBetween(Member $loggedInMember, Member $member): ?R
211211

212212
return $relationRepository->findRelationBetween($loggedInMember, $member);
213213
}
214+
215+
private function checkForEmailAddress(Relation $relation): bool
216+
{
217+
$relationText = $relation->getCommentText();
218+
$found = preg_match("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $relationText);
219+
220+
return $found > 0;
221+
}
222+
223+
private function checkForPhoneNumber(Relation $relation): bool
224+
{
225+
$relationText = $relation->getCommentText();
226+
$found = preg_match("/([0-9][\. \)-]*){9,}/", $relationText);
227+
228+
return $found > 0;
229+
}
214230
}

0 commit comments

Comments
 (0)