11
11
12
12
namespace App \Utils ;
13
13
14
+ use Symfony \Component \Console \Exception \InvalidArgumentException ;
15
+
14
16
/**
15
17
* This class is used to provide an example of integrating simple classes as
16
18
* services into a Symfony application.
@@ -22,11 +24,11 @@ class Validator
22
24
public function validateUsername (?string $ username ): string
23
25
{
24
26
if (empty ($ username )) {
25
- throw new \ Exception ('The username can not be empty. ' );
27
+ throw new InvalidArgumentException ('The username can not be empty. ' );
26
28
}
27
29
28
30
if (1 !== preg_match ('/^[a-z_]+$/ ' , $ username )) {
29
- throw new \ Exception ('The username must contain only lowercase latin characters and underscores. ' );
31
+ throw new InvalidArgumentException ('The username must contain only lowercase latin characters and underscores. ' );
30
32
}
31
33
32
34
return $ username ;
@@ -35,11 +37,11 @@ public function validateUsername(?string $username): string
35
37
public function validatePassword (?string $ plainPassword ): string
36
38
{
37
39
if (empty ($ plainPassword )) {
38
- throw new \ Exception ('The password can not be empty. ' );
40
+ throw new InvalidArgumentException ('The password can not be empty. ' );
39
41
}
40
42
41
43
if (mb_strlen (trim ($ plainPassword )) < 6 ) {
42
- throw new \ Exception ('The password must be at least 6 characters long. ' );
44
+ throw new InvalidArgumentException ('The password must be at least 6 characters long. ' );
43
45
}
44
46
45
47
return $ plainPassword ;
@@ -48,11 +50,11 @@ public function validatePassword(?string $plainPassword): string
48
50
public function validateEmail (?string $ email ): string
49
51
{
50
52
if (empty ($ email )) {
51
- throw new \ Exception ('The email can not be empty. ' );
53
+ throw new InvalidArgumentException ('The email can not be empty. ' );
52
54
}
53
55
54
56
if (false === mb_strpos ($ email , '@ ' )) {
55
- throw new \ Exception ('The email should look like a real email. ' );
57
+ throw new InvalidArgumentException ('The email should look like a real email. ' );
56
58
}
57
59
58
60
return $ email ;
@@ -61,7 +63,7 @@ public function validateEmail(?string $email): string
61
63
public function validateFullName (?string $ fullName ): string
62
64
{
63
65
if (empty ($ fullName )) {
64
- throw new \ Exception ('The full name can not be empty. ' );
66
+ throw new InvalidArgumentException ('The full name can not be empty. ' );
65
67
}
66
68
67
69
return $ fullName ;
0 commit comments