From 1613261b75f2f954402da7606eca58cb3bde7e68 Mon Sep 17 00:00:00 2001 From: Mateusz Charytoniuk <mateusz.charytoniuk@protonmail.com> Date: Sat, 23 Mar 2024 23:21:09 +0100 Subject: [PATCH] chore: stricter static pages types --- src/StaticPage.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/StaticPage.php b/src/StaticPage.php index bf0876cc..15678028 100644 --- a/src/StaticPage.php +++ b/src/StaticPage.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Distantmagic\Resonance; use Distantmagic\Resonance\InputValidatedData\FrontMatter; +use RuntimeException; use Symfony\Component\Finder\SplFileInfo; readonly class StaticPage @@ -25,12 +26,21 @@ readonly class StaticPage return mb_strtolower($this->frontMatter->title) <=> mb_strtolower($other->frontMatter->title); } + /** + * @return non-empty-string + */ public function getBasename(): string { $relativePath = $this->file->getRelativePath(); if (empty($relativePath)) { - return $this->file->getFilenameWithoutExtension(); + $filename = $this->file->getFilenameWithoutExtension(); + + if (empty($filename)) { + throw new RuntimeException('Unable to determine filename'); + } + + return $filename; } return sprintf( @@ -40,6 +50,9 @@ readonly class StaticPage ); } + /** + * @return non-empty-string + */ public function getHref(): string { if ('index' === $this->file->getFilenameWithoutExtension()) { @@ -55,6 +68,9 @@ readonly class StaticPage return '/'.$this->getBasename().'.html'; } + /** + * @return non-empty-string + */ public function getOutputDirectory(): string { return sprintf( @@ -64,6 +80,9 @@ readonly class StaticPage ); } + /** + * @return non-empty-string + */ public function getOutputPathname(): string { return sprintf( -- GitLab