Advertisement
zukars3

Untitled

Apr 20th, 2020
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. <?php
  2.  
  3. class User
  4. {
  5.     private $name;
  6.     private $surname;
  7.     private $username;
  8.  
  9.     public function __construct(string $name, string $surname, string $username)
  10.     {
  11.         if($this->validate($name)) {
  12.             $this->name = $name;
  13.         }
  14.  
  15.         if($this->validate($surname)) {
  16.             $this->name = $surname;
  17.         }
  18.  
  19.         if($this->validate($username)) {
  20.             $this->name = $username;
  21.         }
  22.        
  23.     }
  24.  
  25.     public function validate(string $input): bool
  26.     {
  27.         if (strlen($input) < 5 && !preg_match('~[0-9]~', $input)) {
  28.             return false;
  29.         } return true;
  30.     }
  31.    
  32.     public function getInfo(): string
  33.     {
  34.         return 'Name of the user is: ' . $this->name . ', surname is: ' . $this->surname . ' and username is: ' . $this->username;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement