Passed
Push — dev ( 5c4da4...f4770d )
by Mattia
05:20
created

UserDataValidator::isValidEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Helpers;
6
7
/**
8
 * Class Date.
9
 */
10
class UserDataValidator
11
{
12
    /**
13
     * Checks if the given string is a valid username
14
     *
15
     * @param $username
16
     * @return bool
17
     */
18
    public static function isValidUsername(string $username): bool
19
    {
20
        return !(\preg_match('#[\W]+#', $username) === 1);
21
    }
22
23
    /**
24
     * Checks if the given string is a valid UUID
25
     *
26
     * @param string $uuid
27
     * @return bool
28
     */
29
    public static function isValidUuid(string $uuid): bool
30
    {
31
        return \preg_match('#[a-f0-9]{32}#i', $uuid) === 1 && \mb_strlen($uuid) === 32;
32
    }
33
34
    /**
35
     * Check if is an email address has invalid characters.
36
     *
37
     * @param string
38
     * @return bool
39
     */
40
    public static function isValidEmail(string $email): bool
41
    {
42
        return \preg_match('#^[a-zA-Z0-9\.\_\%\+\-]+@[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,8}$#', $email) === 1;
43
    }
44
}
45