Skip to content

Commit

Permalink
Merge pull request #590 from hydephp/code-refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Oct 26, 2022
1 parent 599ad49 commit 2c0e349
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/Actions/GeneratesSidebarTableOfContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/JsonSerializesArrayable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
trait JsonSerializesArrayable
{
/** @inheritDoc */
public function jsonSerialize(): mixed
public function jsonSerialize(): array
{
return $this->toArray();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Foundation/Concerns/ForwardsHyperlinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
7 changes: 4 additions & 3 deletions src/Models/Pages/DocumentationPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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
Expand All @@ -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();
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/Models/Pages/MarkdownPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 9 additions & 6 deletions src/Models/Support/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
{
Expand All @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions src/Services/RssFeedService.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

declare(strict_types=1);

/** @noinspection PhpComposerExtensionStubsInspection */
/** @noinspection XmlUnusedNamespaceDeclaration */

declare(strict_types=1);

namespace Hyde\Framework\Services;

use Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function testReturnStringContainsExpectedContent()
$markdown = "# Level 1\n## Level 2\n### Level 3\n";
$result = (new GeneratesSidebarTableOfContents($markdown))->execute();

$this->assertEquals('<ul class="table-of-contents"><li><a href="#level-2">Level 2</a><ul><li><a href="#level-3">Level 3</a></li></ul></li></ul>', str_replace("\n", '', $result));
$this->assertEquals('<ul class="table-of-contents"><li><a href="#level-2">Level 2</a><ul><li><a href="#level-3">Level 3</a></li></ul></li></ul>',
str_replace("\n", '', $result)
);
}
}

0 comments on commit 2c0e349

Please sign in to comment.