From 2273367c6d6974c475b9af6d8672f2659cfd4284 Mon Sep 17 00:00:00 2001 From: Mike Colagrosso Date: Thu, 3 Oct 2024 14:05:53 -0600 Subject: [PATCH] Collection validation: Pass enum to InvalidCollectionTypeException, not value --- lib/Collection.php | 2 +- lib/Exceptions/InvalidCollectionTypeException.php | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Collection.php b/lib/Collection.php index 5931ab24..66e7d9ce 100644 --- a/lib/Collection.php +++ b/lib/Collection.php @@ -60,7 +60,7 @@ class Collection{ } if($this->Type !== null && ($this->Type != CollectionType::Series && $this->Type != CollectionType::Set)){ - $error->Add(new Exceptions\InvalidCollectionTypeException($this->Type->value)); + $error->Add(new Exceptions\InvalidCollectionTypeException($this->Type)); } if($error->HasExceptions){ diff --git a/lib/Exceptions/InvalidCollectionTypeException.php b/lib/Exceptions/InvalidCollectionTypeException.php index 7d7f3334..f113a82b 100644 --- a/lib/Exceptions/InvalidCollectionTypeException.php +++ b/lib/Exceptions/InvalidCollectionTypeException.php @@ -2,13 +2,15 @@ namespace Exceptions; +use \CollectionType; + class InvalidCollectionTypeException extends AppException{ /** @var string $message */ protected $message = 'Collection type should be `series` or `set` according to the EPUB specification.'; - public function __construct(?string $collectionType){ - if($collectionType !== null && trim($collectionType) != ''){ - $this->message .= ' Type provided: ' . $collectionType; + public function __construct(?CollectionType $collectionType){ + if($collectionType !== null){ + $this->message .= ' Type provided: ' . $collectionType->value; } parent::__construct($this->message);