mirror of
https://github.com/standardebooks/web.git
synced 2025-07-10 00:30:28 -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
|
@ -24,7 +24,60 @@ class GitCommit{
|
|||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exceptions\ValidationException
|
||||
*/
|
||||
public function Validate(): void{
|
||||
/** @throws void */
|
||||
$now = new DateTimeImmutable();
|
||||
|
||||
$error = new Exceptions\ValidationException();
|
||||
|
||||
if(!isset($this->EbookId)){
|
||||
$error->Add(new Exceptions\GitCommitEbookIdRequiredException());
|
||||
}
|
||||
|
||||
if(isset($this->Created)){
|
||||
if($this->Created > $now || $this->Created < EBOOK_EARLIEST_CREATION_DATE){
|
||||
$error->Add(new Exceptions\InvalidGitCommitCreatedDatetimeException($this->Created));
|
||||
}
|
||||
}
|
||||
else{
|
||||
$error->Add(new Exceptions\GitCommitCreatedDatetimeRequiredException());
|
||||
}
|
||||
|
||||
if(isset($this->Message)){
|
||||
$this->Message = trim($this->Message);
|
||||
|
||||
if($this->Message == ''){
|
||||
$error->Add(new Exceptions\GitCommitMessageRequiredException());
|
||||
}
|
||||
}
|
||||
else{
|
||||
$error->Add(new Exceptions\GitCommitMessageRequiredException());
|
||||
}
|
||||
|
||||
if(isset($this->Hash)){
|
||||
$this->Hash = trim($this->Hash);
|
||||
|
||||
if($this->Hash == ''){
|
||||
$error->Add(new Exceptions\GitCommitHashRequiredException());
|
||||
}
|
||||
}
|
||||
else{
|
||||
$error->Add(new Exceptions\GitCommitHashRequiredException());
|
||||
}
|
||||
|
||||
if($error->HasExceptions){
|
||||
throw $error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exceptions\ValidationException
|
||||
*/
|
||||
public function Create(): void{
|
||||
$this->Validate();
|
||||
Db::Query('
|
||||
INSERT into GitCommits (EbookId, Created, Message, Hash)
|
||||
values (?,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue