UserDataValidator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 4
dl 0
loc 24
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isValidUuid() 0 3 2
A isValidUsername() 0 3 1
A isValidEmail() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Minepic\Helpers;
6
7
class UserDataValidator
8
{
9
    /**
10
     * Checks if the given string is a valid username.
11
     */
12
    public static function isValidUsername(string $username): bool
13
    {
14
        return preg_match('#[\W]+#', $username) !== 1;
15
    }
16
17
    /**
18
     * Checks if the given string is a valid UUID.
19
     */
20
    public static function isValidUuid(string $uuid): bool
21
    {
22
        return preg_match('#[a-f0-9]{32}#i', $uuid) === 1 && mb_strlen($uuid) === 32;
23
    }
24
25
    /**
26
     * Check if is an email address has invalid characters.
27
     */
28
    public static function isValidEmail(string $email): bool
29
    {
30
        return preg_match('#^[a-zA-Z0-9\.\_\%\+\-]+@[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,8}$#', $email) === 1;
31
    }
32
}
33