Skip to content
Snippets Groups Projects
Commit 1613261b authored by Mateusz Charytoniuk's avatar Mateusz Charytoniuk
Browse files

chore: stricter static pages types

parent 4c25116d
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ declare(strict_types=1); ...@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Distantmagic\Resonance; namespace Distantmagic\Resonance;
use Distantmagic\Resonance\InputValidatedData\FrontMatter; use Distantmagic\Resonance\InputValidatedData\FrontMatter;
use RuntimeException;
use Symfony\Component\Finder\SplFileInfo; use Symfony\Component\Finder\SplFileInfo;
readonly class StaticPage readonly class StaticPage
...@@ -25,12 +26,21 @@ readonly class StaticPage ...@@ -25,12 +26,21 @@ readonly class StaticPage
return mb_strtolower($this->frontMatter->title) <=> mb_strtolower($other->frontMatter->title); return mb_strtolower($this->frontMatter->title) <=> mb_strtolower($other->frontMatter->title);
} }
/**
* @return non-empty-string
*/
public function getBasename(): string public function getBasename(): string
{ {
$relativePath = $this->file->getRelativePath(); $relativePath = $this->file->getRelativePath();
if (empty($relativePath)) { 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( return sprintf(
...@@ -40,6 +50,9 @@ readonly class StaticPage ...@@ -40,6 +50,9 @@ readonly class StaticPage
); );
} }
/**
* @return non-empty-string
*/
public function getHref(): string public function getHref(): string
{ {
if ('index' === $this->file->getFilenameWithoutExtension()) { if ('index' === $this->file->getFilenameWithoutExtension()) {
...@@ -55,6 +68,9 @@ readonly class StaticPage ...@@ -55,6 +68,9 @@ readonly class StaticPage
return '/'.$this->getBasename().'.html'; return '/'.$this->getBasename().'.html';
} }
/**
* @return non-empty-string
*/
public function getOutputDirectory(): string public function getOutputDirectory(): string
{ {
return sprintf( return sprintf(
...@@ -64,6 +80,9 @@ readonly class StaticPage ...@@ -64,6 +80,9 @@ readonly class StaticPage
); );
} }
/**
* @return non-empty-string
*/
public function getOutputPathname(): string public function getOutputPathname(): string
{ {
return sprintf( return sprintf(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment