1111
1212namespace  App \Utils ;
1313
14+ use  Symfony \Component \Console \Exception \InvalidArgumentException ;
15+ 
1416/** 
1517 * This class is used to provide an example of integrating simple classes as 
1618 * services into a Symfony application. 
@@ -22,11 +24,11 @@ class Validator
2224    public  function  validateUsername (?string  $ usernamestring 
2325    {
2426        if  (empty ($ username
25-             throw  new  \ Exception ('The username can not be empty. ' );
27+             throw  new  InvalidArgumentException ('The username can not be empty. ' );
2628        }
2729
2830        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. ' );
3032        }
3133
3234        return  $ username
@@ -35,11 +37,11 @@ public function validateUsername(?string $username): string
3537    public  function  validatePassword (?string  $ plainPasswordstring 
3638    {
3739        if  (empty ($ plainPassword
38-             throw  new  \ Exception ('The password can not be empty. ' );
40+             throw  new  InvalidArgumentException ('The password can not be empty. ' );
3941        }
4042
4143        if  (mb_strlen (trim ($ plainPassword6 ) {
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. ' );
4345        }
4446
4547        return  $ plainPassword
@@ -48,11 +50,11 @@ public function validatePassword(?string $plainPassword): string
4850    public  function  validateEmail (?string  $ emailstring 
4951    {
5052        if  (empty ($ email
51-             throw  new  \ Exception ('The email can not be empty. ' );
53+             throw  new  InvalidArgumentException ('The email can not be empty. ' );
5254        }
5355
5456        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. ' );
5658        }
5759
5860        return  $ email
@@ -61,7 +63,7 @@ public function validateEmail(?string $email): string
6163    public  function  validateFullName (?string  $ fullNamestring 
6264    {
6365        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. ' );
6567        }
6668
6769        return  $ fullName
0 commit comments