X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/a6633642232efd164d4708967ab59e498fbff896..refs/pull/5280/head:/app/Entities/EntityProvider.php diff --git a/app/Entities/EntityProvider.php b/app/Entities/EntityProvider.php index c77a57d61..3276a6c7a 100644 --- a/app/Entities/EntityProvider.php +++ b/app/Entities/EntityProvider.php @@ -1,4 +1,6 @@ - + * + * @return array */ public function all(): array { return [ 'bookshelf' => $this->bookshelf, - 'book' => $this->book, - 'chapter' => $this->chapter, - 'page' => $this->page, + 'book' => $this->book, + 'chapter' => $this->chapter, + 'page' => $this->page, ]; } /** - * Get an entity instance by it's basic name. + * Get an entity instance by its basic name. */ public function get(string $type): Entity { $type = strtolower($type); - return $this->all()[$type]; + $instance = $this->all()[$type] ?? null; + + if (is_null($instance)) { + throw new \InvalidArgumentException("Provided type \"{$type}\" is not a valid entity type"); + } + + return $instance; } /** @@ -86,6 +74,7 @@ class EntityProvider $model = $this->get($type); $morphClasses[] = $model->getMorphClass(); } + return $morphClasses; } }