Update PropertiesBase to new patterns and improve static analysis checks

This commit is contained in:
Alex Cabal 2022-06-30 13:23:05 -05:00
parent 5f0b57f7e9
commit 6c8414f844
33 changed files with 335 additions and 148 deletions

View file

@ -5,35 +5,16 @@ use Safe\DateTime;
class User extends PropertiesBase{
public $UserId;
public $FirstName;
protected $DisplayFirstName = null;
public $LastName;
protected $DisplayLastName = null;
protected $Name = null;
protected $DisplayName = null;
public $Email;
protected $DisplayEmail;
public $Created;
public $Uuid;
public static function Get(?int $userId): User{
$result = Db::Query('SELECT * from Users where UserId = ?', [$userId], 'User');
if(sizeof($result) == 0){
throw new Exceptions\InvalidUserException();
}
return $result[0];
}
public static function GetByEmail(?string $email): User{
$result = Db::Query('SELECT * from Users where Email = ?', [$email], 'User');
if(sizeof($result) == 0){
throw new Exceptions\InvalidUserException();
}
return $result[0];
}
// *******
// GETTERS
// *******
protected function GetName(): string{
if($this->Name === null){
@ -43,6 +24,11 @@ class User extends PropertiesBase{
return $this->Name;
}
// *******
// METHODS
// *******
public function Create(): void{
$uuid = Uuid::uuid4();
$this->Uuid = $uuid->toString();
@ -63,4 +49,29 @@ class User extends PropertiesBase{
$this->UserId = Db::GetLastInsertedId();
}
// ***********
// ORM METHODS
// ***********
public static function Get(?int $userId): User{
$result = Db::Query('SELECT * from Users where UserId = ?', [$userId], 'User');
if(sizeof($result) == 0){
throw new Exceptions\InvalidUserException();
}
return $result[0];
}
public static function GetByEmail(?string $email): User{
$result = Db::Query('SELECT * from Users where Email = ?', [$email], 'User');
if(sizeof($result) == 0){
throw new Exceptions\InvalidUserException();
}
return $result[0];
}
}