From 2c0e349ba36e561c99ff06e5cb6757fa236657d8 Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 26 Oct 2022 14:51:54 +0000 Subject: [PATCH] Merge pull request #590 from hydephp/code-refactors Code refactors https://github.com/hydephp/develop/commit/8c99b4411ee259b89e6c45d7acb140677cea783c --- src/Actions/GeneratesSidebarTableOfContents.php | 5 +++-- src/Concerns/JsonSerializesArrayable.php | 2 +- src/Foundation/Concerns/ForwardsHyperlinks.php | 4 ++-- src/Models/Pages/DocumentationPage.php | 7 ++++--- src/Models/Pages/MarkdownPost.php | 1 - src/Models/Support/Route.php | 15 +++++++++------ src/Services/RssFeedService.php | 4 ++-- .../GeneratesSidebarTableOfContentsTest.php | 4 +++- 8 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/Actions/GeneratesSidebarTableOfContents.php b/src/Actions/GeneratesSidebarTableOfContents.php index 19e178b1..19470895 100644 --- a/src/Actions/GeneratesSidebarTableOfContents.php +++ b/src/Actions/GeneratesSidebarTableOfContents.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Actions; +use Hyde\Framework\Models\Markdown\Markdown; use League\CommonMark\Environment\Environment; use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; use League\CommonMark\Extension\HeadingPermalink\HeadingPermalinkExtension; @@ -19,9 +20,9 @@ class GeneratesSidebarTableOfContents { protected string $markdown; - public function __construct(string $markdown) + public function __construct(Markdown|string $markdown) { - $this->markdown = $markdown; + $this->markdown = (string) $markdown; } public function execute(): string diff --git a/src/Concerns/JsonSerializesArrayable.php b/src/Concerns/JsonSerializesArrayable.php index 8e4b1b69..6e905dfc 100644 --- a/src/Concerns/JsonSerializesArrayable.php +++ b/src/Concerns/JsonSerializesArrayable.php @@ -14,7 +14,7 @@ trait JsonSerializesArrayable { /** @inheritDoc */ - public function jsonSerialize(): mixed + public function jsonSerialize(): array { return $this->toArray(); } diff --git a/src/Foundation/Concerns/ForwardsHyperlinks.php b/src/Foundation/Concerns/ForwardsHyperlinks.php index 84f52db4..b0b577d3 100644 --- a/src/Foundation/Concerns/ForwardsHyperlinks.php +++ b/src/Foundation/Concerns/ForwardsHyperlinks.php @@ -31,8 +31,8 @@ public function hasSiteUrl(): bool return $this->hyperlinks->hasSiteUrl(); } - public function url(string $path = '', ?string $default = null): string + public function url(string $path = ''): string { - return $this->hyperlinks->url($path, $default); + return $this->hyperlinks->url($path); } } diff --git a/src/Models/Pages/DocumentationPage.php b/src/Models/Pages/DocumentationPage.php index 2a76ab2c..ce6d9247 100644 --- a/src/Models/Pages/DocumentationPage.php +++ b/src/Models/Pages/DocumentationPage.php @@ -7,7 +7,6 @@ use Hyde\Framework\Actions\GeneratesSidebarTableOfContents; use Hyde\Framework\Concerns\BaseMarkdownPage; use Hyde\Framework\Contracts\FrontMatter\DocumentationPageSchema; -use Hyde\Framework\Models\Markdown\Markdown; use Hyde\Framework\Models\Support\Route; /** @@ -42,7 +41,9 @@ public function getOnlineSourcePath(): string|false public static function home(): ?Route { - return Route::exists(static::$outputDirectory.'/index') ? Route::get(static::$outputDirectory.'/index') : null; + return Route::exists(static::$outputDirectory.'/index') + ? Route::get(static::$outputDirectory.'/index') + : null; } public static function hasTableOfContents(): bool @@ -55,7 +56,7 @@ public static function hasTableOfContents(): bool */ public function getTableOfContents(): string { - return (new GeneratesSidebarTableOfContents((string) $this->markdown))->execute(); + return (new GeneratesSidebarTableOfContents($this->markdown))->execute(); } /** diff --git a/src/Models/Pages/MarkdownPost.php b/src/Models/Pages/MarkdownPost.php index a3085168..7837cf1e 100644 --- a/src/Models/Pages/MarkdownPost.php +++ b/src/Models/Pages/MarkdownPost.php @@ -7,7 +7,6 @@ use Hyde\Framework\Concerns\BaseMarkdownPage; use Hyde\Framework\Contracts\FrontMatter\BlogPostSchema; use Hyde\Framework\Foundation\PageCollection; -use Hyde\Framework\Models\Markdown\Markdown; use Hyde\Framework\Models\Support\Author; use Hyde\Framework\Models\Support\DateString; use Hyde\Framework\Models\Support\Image; diff --git a/src/Models/Support/Route.php b/src/Models/Support/Route.php index 44a8fbff..37f89102 100644 --- a/src/Models/Support/Route.php +++ b/src/Models/Support/Route.php @@ -151,7 +151,10 @@ public function getQualifiedUrl(): string } /** - * @param \Hyde\Framework\Models\Route|string $route A route instance or route key string + * Determine if the route instance matches another route or route key. + * + * @param \Hyde\Framework\Models\Support\Route|string $route A route instance or route key string + * @return bool */ public function is(Route|string $route): bool { @@ -168,7 +171,7 @@ public function is(Route|string $route): bool * Alias for static::getFromKey(). * * @param string $routeKey Example: posts/foo.md - * @return \Hyde\Framework\Models\Route + * @return \Hyde\Framework\Models\Support\Route * * @throws \Hyde\Framework\Exceptions\RouteNotFoundException */ @@ -181,7 +184,7 @@ public static function get(string $routeKey): static * Get a route from the route index for the specified route key. * * @param string $routeKey Example: posts/foo, posts.foo - * @return \Hyde\Framework\Models\Route + * @return \Hyde\Framework\Models\Support\Route * * @throws \Hyde\Framework\Exceptions\RouteNotFoundException */ @@ -195,7 +198,7 @@ public static function getFromKey(string $routeKey): static * Get a route from the route index for the specified source file path. * * @param string $sourceFilePath Example: _posts/foo.md - * @return \Hyde\Framework\Models\Route + * @return \Hyde\Framework\Models\Support\Route * * @throws \Hyde\Framework\Exceptions\RouteNotFoundException */ @@ -210,7 +213,7 @@ public static function getFromSource(string $sourceFilePath): static * Get a route from the route index for the supplied page model. * * @param \Hyde\Framework\Concerns\HydePage $page - * @return \Hyde\Framework\Models\Route + * @return \Hyde\Framework\Models\Support\Route */ public static function getFromModel(HydePage $page): Route { @@ -220,7 +223,7 @@ public static function getFromModel(HydePage $page): Route /** * Get all routes from the route index. * - * @return \Hyde\Framework\Foundation\RouteCollection<\Hyde\Framework\Models\Route> + * @return \Hyde\Framework\Foundation\RouteCollection<\Hyde\Framework\Models\Support\Route> */ public static function all(): RouteCollection { diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index 7b482972..24c1ade9 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -1,10 +1,10 @@ execute(); - $this->assertEquals('', str_replace("\n", '', $result)); + $this->assertEquals('', + str_replace("\n", '', $result) + ); } }