mirror of
https://github.com/standardebooks/web.git
synced 2025-07-18 20:36:38 -04:00
Standardize trim and other validation of nullable and non-nullable properties
This commit is contained in:
parent
0eaf2e8e47
commit
85307a7c7e
21 changed files with 347 additions and 16 deletions
|
@ -55,13 +55,34 @@ class Collection{
|
|||
public function Validate(): void{
|
||||
$error = new Exceptions\ValidationException();
|
||||
|
||||
$this->Name = trim($this->Name ?? '');
|
||||
if($this->Name == ''){
|
||||
if(isset($this->Name)){
|
||||
$this->Name = trim($this->Name);
|
||||
|
||||
if($this->Name == ''){
|
||||
$error->Add(new Exceptions\CollectionNameRequiredException());
|
||||
}
|
||||
|
||||
if(strlen($this->Name) > EBOOKS_MAX_STRING_LENGTH){
|
||||
$error->Add(new Exceptions\StringTooLongException('Collection name: '. $this->Name));
|
||||
}
|
||||
}
|
||||
else{
|
||||
$error->Add(new Exceptions\CollectionNameRequiredException());
|
||||
}
|
||||
|
||||
if(strlen($this->Name) > EBOOKS_MAX_STRING_LENGTH){
|
||||
$error->Add(new Exceptions\StringTooLongException('Collection name: '. $this->Name));
|
||||
if(isset($this->UrlName)){
|
||||
$this->UrlName = trim($this->UrlName);
|
||||
|
||||
if($this->UrlName == ''){
|
||||
$error->Add(new Exceptions\CollectionUrlNameRequiredException());
|
||||
}
|
||||
|
||||
if(strlen($this->UrlName) > EBOOKS_MAX_STRING_LENGTH){
|
||||
$error->Add(new Exceptions\StringTooLongException('Collection UrlName: '. $this->UrlName));
|
||||
}
|
||||
}
|
||||
else{
|
||||
$error->Add(new Exceptions\CollectionUrlNameRequiredException());
|
||||
}
|
||||
|
||||
if($this->Type !== null && ($this->Type != CollectionType::Series && $this->Type != CollectionType::Set)){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue