summaryrefslogtreecommitdiff
path: root/src/Validators/EmailValidator.php
diff options
context:
space:
mode:
authorAsko Nomm <asko@bien.ee>2022-02-22 21:32:37 +0100
committerAsko Nomm <asko@bien.ee>2022-02-22 21:32:37 +0100
commitb0fd14cd71d60c1b9926aff10fe9e8eeebe1285c (patch)
treeff5f1689ffa87a84d8c7487d8a64c885ce7b592e /src/Validators/EmailValidator.php
parent4256c45b6b9c96400b8f372b289be1127495ac56 (diff)
Lots of documentation and basic tests
Diffstat (limited to 'src/Validators/EmailValidator.php')
-rw-r--r--src/Validators/EmailValidator.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/Validators/EmailValidator.php b/src/Validators/EmailValidator.php
new file mode 100644
index 0000000..5d69b5b
--- /dev/null
+++ b/src/Validators/EmailValidator.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace Askonomm\Bouncer\Validators;
+
+/**
+ * Implements an e-mail validator that has a job
+ * of validating e-mail addresses.
+ *
+ * @author Asko Nomm <asko@bien.ee>
+ */
+class EmailValidator implements Validator
+{
+ /**
+ * Returns a boolean `true` when given `$value` is a valid e-mail
+ * address. Returns `false` otherwise.
+ *
+ * @param string $value
+ * @param mixed $modifier
+ * @return boolean
+ */
+ public static function validate(string $value, mixed $modifier = null): bool
+ {
+ return filter_var($value, FILTER_VALIDATE_EMAIL);
+ }
+
+ /**
+ * Composes the error message in case the validation fails.
+ *
+ * @param string $field
+ * @param mixed $modifier
+ * @return string
+ */
+ public static function composeError(string $field, mixed $modifier = null): string
+ {
+ return "${field} is not a valid e-mail address.";
+ }
+}