From 406eff56a904b8d3b5fd1ad6a55fae860e5e1330 Mon Sep 17 00:00:00 2001 From: Mike Colagrosso Date: Mon, 20 May 2024 20:37:25 -0600 Subject: [PATCH] Fix PHPStan errors --- lib/Ebook.php | 19 +++++++++++++++++++ lib/EbookTag.php | 10 ++++++++++ .../EbookDescriptionRequiredException.php | 1 + .../EbookIdentifierRequiredException.php | 1 + .../EbookIndexableTextRequiredException.php | 1 + .../EbookLongDescriptionRequiredException.php | 1 + .../EbookTitleRequiredException.php | 1 + .../InvalidEbookCreatedDatetimeException.php | 4 ++++ ...nvalidEbookRepoFilesystemPathException.php | 1 + .../InvalidEbookUpdatedDatetimeException.php | 4 ++++ ...InvalidEbookWwwFilesystemPathException.php | 1 + lib/LocSubject.php | 9 +++++++++ 12 files changed, 53 insertions(+) diff --git a/lib/Ebook.php b/lib/Ebook.php index af533117..e51028e7 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -580,6 +580,10 @@ public function __construct(?string $wwwFilesystemPath = null){ // METHODS // ******* + /** + * @throws \Exception + * @throws \Exceptions\ValidationException + */ public function Validate(): void{ $now = new DateTimeImmutable(); $error = new Exceptions\ValidationException(); @@ -739,6 +743,9 @@ public function Validate(): void{ } } + /** + * @throws \Exception + */ public function CreateOrUpdate(): void{ try{ $existingEbook = Ebook::GetByIdentifier($this->Identifier); @@ -750,6 +757,9 @@ public function CreateOrUpdate(): void{ } } + /** + * @throws \Exceptions\ValidationException + */ private function InsertTagStrings(): void{ $tags = []; foreach($this->Tags as $ebookTag){ @@ -758,6 +768,9 @@ private function InsertTagStrings(): void{ $this->Tags = $tags; } + /** + * @throws \Exceptions\ValidationException + */ private function InsertLocSubjectStrings(): void{ $subjects = []; foreach($this->LocSubjects as $locSubject){ @@ -1089,6 +1102,9 @@ public static function GetByIdentifier(?string $identifier): Ebook{ return $result[0]; } + /** + * @throws \Exception + */ public function Create(): void{ $this->Validate(); @@ -1140,6 +1156,9 @@ public function Create(): void{ $this->InsertTocEntries(); } + /** + * @throws \Exception + */ public function Save(): void{ $this->Validate(); diff --git a/lib/EbookTag.php b/lib/EbookTag.php index 1c6f1aa0..bdb4158c 100644 --- a/lib/EbookTag.php +++ b/lib/EbookTag.php @@ -22,6 +22,10 @@ protected function GetUrl(): string{ // ******* // METHODS // ******* + + /** + * @throws \Exceptions\ValidationException + */ public function Validate(): void{ $error = new Exceptions\ValidationException(); @@ -34,6 +38,9 @@ public function Validate(): void{ } } + /** + * @throws \Exceptions\ValidationException + */ public function Create(): void{ $this->Validate(); @@ -44,6 +51,9 @@ public function Create(): void{ $this->TagId = Db::GetLastInsertedId(); } + /** + * @throws \Exceptions\ValidationException + */ public function GetByNameOrCreate(string $name): EbookTag{ $result = Db::Query(' SELECT * diff --git a/lib/Exceptions/EbookDescriptionRequiredException.php b/lib/Exceptions/EbookDescriptionRequiredException.php index c2fc7ac0..6c10099e 100644 --- a/lib/Exceptions/EbookDescriptionRequiredException.php +++ b/lib/Exceptions/EbookDescriptionRequiredException.php @@ -2,5 +2,6 @@ namespace Exceptions; class EbookDescriptionRequiredException extends AppException{ + /** @var string $message */ protected $message = 'Ebook Description required.'; } diff --git a/lib/Exceptions/EbookIdentifierRequiredException.php b/lib/Exceptions/EbookIdentifierRequiredException.php index f2932509..a1ee7c0d 100644 --- a/lib/Exceptions/EbookIdentifierRequiredException.php +++ b/lib/Exceptions/EbookIdentifierRequiredException.php @@ -2,5 +2,6 @@ namespace Exceptions; class EbookIdentifierRequiredException extends AppException{ + /** @var string $message */ protected $message = 'Ebook Identifier required.'; } diff --git a/lib/Exceptions/EbookIndexableTextRequiredException.php b/lib/Exceptions/EbookIndexableTextRequiredException.php index f59516ea..5adfa53e 100644 --- a/lib/Exceptions/EbookIndexableTextRequiredException.php +++ b/lib/Exceptions/EbookIndexableTextRequiredException.php @@ -2,5 +2,6 @@ namespace Exceptions; class EbookIndexableTextRequiredException extends AppException{ + /** @var string $message */ protected $message = 'Ebook IndexableText required.'; } diff --git a/lib/Exceptions/EbookLongDescriptionRequiredException.php b/lib/Exceptions/EbookLongDescriptionRequiredException.php index 0e756532..0433705e 100644 --- a/lib/Exceptions/EbookLongDescriptionRequiredException.php +++ b/lib/Exceptions/EbookLongDescriptionRequiredException.php @@ -2,5 +2,6 @@ namespace Exceptions; class EbookLongDescriptionRequiredException extends AppException{ + /** @var string $message */ protected $message = 'Ebook LongDescription required.'; } diff --git a/lib/Exceptions/EbookTitleRequiredException.php b/lib/Exceptions/EbookTitleRequiredException.php index 789cf165..571b6ed9 100644 --- a/lib/Exceptions/EbookTitleRequiredException.php +++ b/lib/Exceptions/EbookTitleRequiredException.php @@ -2,5 +2,6 @@ namespace Exceptions; class EbookTitleRequiredException extends AppException{ + /** @var string $message */ protected $message = 'Ebook Title required.'; } diff --git a/lib/Exceptions/InvalidEbookCreatedDatetimeException.php b/lib/Exceptions/InvalidEbookCreatedDatetimeException.php index ca370bbf..8381b66e 100644 --- a/lib/Exceptions/InvalidEbookCreatedDatetimeException.php +++ b/lib/Exceptions/InvalidEbookCreatedDatetimeException.php @@ -4,8 +4,12 @@ use Safe\DateTimeImmutable; class InvalidEbookCreatedDatetimeException extends AppException{ + /** @var string $message */ protected $message = 'Invalid EbookCreated datetime.'; + /** + * @throws \Exception + */ public function __construct(DateTimeImmutable $createdDatetime){ $now = new DateTimeImmutable(); $this->message = 'Invalid EbookCreated datetime. ' . $createdDatetime->format('Y-m-d') . ' is not between ' . EBOOK_EARLIEST_CREATION_DATE->format('Y-m-d') . ' and ' . $now->format('Y-m-d') . '.'; diff --git a/lib/Exceptions/InvalidEbookRepoFilesystemPathException.php b/lib/Exceptions/InvalidEbookRepoFilesystemPathException.php index 6f01a917..7e23e0eb 100644 --- a/lib/Exceptions/InvalidEbookRepoFilesystemPathException.php +++ b/lib/Exceptions/InvalidEbookRepoFilesystemPathException.php @@ -4,6 +4,7 @@ use Safe\DateTimeImmutable; class InvalidEbookRepoFilesystemPathException extends AppException{ + /** @var string $message */ protected $message = 'Invalid RepoFilesystemPath.'; public function __construct(?string $path){ diff --git a/lib/Exceptions/InvalidEbookUpdatedDatetimeException.php b/lib/Exceptions/InvalidEbookUpdatedDatetimeException.php index 52d9fecf..d5c42d1f 100644 --- a/lib/Exceptions/InvalidEbookUpdatedDatetimeException.php +++ b/lib/Exceptions/InvalidEbookUpdatedDatetimeException.php @@ -4,8 +4,12 @@ use Safe\DateTimeImmutable; class InvalidEbookUpdatedDatetimeException extends AppException{ + /** @var string $message */ protected $message = 'Invalid EbookUpdated datetime.'; + /** + * @throws \Exception + */ public function __construct(DateTimeImmutable $updatedDatetime){ $now = new DateTimeImmutable(); $this->message = 'Invalid EbookUpdated datetime. ' . $updatedDatetime->format('Y-m-d') . ' is not between ' . EBOOK_EARLIEST_CREATION_DATE->format('Y-m-d') . ' and ' . $now->format('Y-m-d') . '.'; diff --git a/lib/Exceptions/InvalidEbookWwwFilesystemPathException.php b/lib/Exceptions/InvalidEbookWwwFilesystemPathException.php index efc01878..6b3aa488 100644 --- a/lib/Exceptions/InvalidEbookWwwFilesystemPathException.php +++ b/lib/Exceptions/InvalidEbookWwwFilesystemPathException.php @@ -4,6 +4,7 @@ use Safe\DateTimeImmutable; class InvalidEbookWwwFilesystemPathException extends AppException{ + /** @var string $message */ protected $message = 'Invalid WwwFilesystemPath.'; public function __construct(?string $path){ diff --git a/lib/LocSubject.php b/lib/LocSubject.php index e0ca42a1..e33e8ea8 100644 --- a/lib/LocSubject.php +++ b/lib/LocSubject.php @@ -2,6 +2,9 @@ class LocSubject extends Tag{ public int $LocSubjectId; + /** + * @throws \Exceptions\ValidationException + */ public function Validate(): void{ $error = new Exceptions\ValidationException(); @@ -14,6 +17,9 @@ public function Validate(): void{ } } + /** + * @throws \Exceptions\ValidationException + */ public function Create(): void{ $this->Validate(); @@ -24,6 +30,9 @@ public function Create(): void{ $this->LocSubjectId = Db::GetLastInsertedId(); } + /** + * @throws \Exceptions\ValidationException + */ public function GetByNameOrCreate(string $name): LocSubject{ $result = Db::Query(' SELECT *