Skip to content

Commit

Permalink
Merge pull request #440 from hydephp/code-cleanup
Browse files Browse the repository at this point in the history
Code cleanup without affecting functionality
  • Loading branch information
caendesilva authored May 22, 2022
2 parents 7731e0d + 01ff887 commit 5aa6d55
Show file tree
Hide file tree
Showing 21 changed files with 41 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/Actions/FindsContentLengthForImageObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Hyde\Framework\Contracts\ActionContract;
use Hyde\Framework\Models\Image;
use Illuminate\Support\Facades\Http;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand All @@ -23,7 +24,7 @@ public function __construct(Image $image)
{
$this->image = $image;

$this->output = new \Symfony\Component\Console\Output\ConsoleOutput();
$this->output = new ConsoleOutput();
}

public function execute(): int
Expand Down
2 changes: 0 additions & 2 deletions src/Actions/GeneratesNavigationMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Hyde\Framework\Hyde;
use Hyde\Framework\Services\CollectionService;
use Illuminate\Support\Str;
use JetBrains\PhpStorm\Pure;

/**
* Generate the dynamic navigation menu.
Expand Down Expand Up @@ -152,7 +151,6 @@ public function getTitleFromSlug(string $slug): string
*
* @return array
*/
#[Pure]
private function getListOfCustomPages(): array
{
return array_unique(
Expand Down
1 change: 0 additions & 1 deletion src/Actions/MarkdownConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class MarkdownConverter
/**
* Parse the Markdown into HTML.
*
* @param string $markdown
* @return string $html
*/
public static function parse(string $markdown, ?string $sourceModel = null): string
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/HydeDebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct()
parent::__construct();

if (config('app.env', 'production') !== 'development') {
$this->setHidden(true);
$this->setHidden();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/HydeRebuildStaticSiteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function handleException(Exception $exception): int
* Get the output path for the given source file path.
* Will fall back to the input path when using non-standard source paths.
*
* @deprecated, reimplementing path information in StaticPageBuilder,
* @deprecated reimplementing path information in StaticPageBuilder,
* alternatively, recreating in the DiscoveryService
*
* @param string $path
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/Commands/AsksToRebuildSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
trait AsksToRebuildSite
{
protected function askToRebuildSite()
protected function askToRebuildSite(): void
{
if ($this->option('no-interaction')) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/Concerns/GeneratesPageMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Hyde\Framework\Hyde;
use Hyde\Framework\Models\MarkdownPost;
use Hyde\Framework\Models\Metadata;
use Hyde\Framework\Services\AuthorService;
use Tests\TestCase;

/**
* Generates metadata for page models that have front matter.
Expand All @@ -22,7 +22,7 @@ public function constructMetadata(): void
{
$this->parseFrontMatterMetadata();

if ($this instanceof MarkdownPost || $this instanceof \Tests\TestCase) {
if ($this instanceof MarkdownPost || $this instanceof TestCase) {
$this->makeOpenGraphPropertiesForArticle();
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Concerns/HasDateString.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ trait HasDateString
{
public ?DateString $date = null;

/**
* @throws \Exception
*/
public function constructDateString(): void
{
if (isset($this->matter['date'])) {
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/HasTableOfContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Hyde\Framework\Actions\GeneratesTableOfContents;

/**
* Generate a Table of Contents HTML string from a Markdown document body.
* Generate Table of Contents as HTML from a Markdown document body.
*
* @see \Tests\Unit\HasTableOfContentsTest
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/Internal/AssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait AssetManager
/**
* Get the asset service instance.
*
* @return \Hyde\Framework\Services\AssetServiceContract
* @return \Hyde\Framework\Contracts\AssetServiceContract
*/
public static function assetManager(): AssetServiceContract
{
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/Internal/BuildActionRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function canRunBuildAction(array $collection, string $name, ?string $v
}

/** @internal */
protected function runBuildAction(string $model)
protected function runBuildAction(string $model): void
{
$collection = CollectionService::getSourceFileListForModel($model);
$modelName = $this->getModelPluralName($model);
Expand Down
6 changes: 5 additions & 1 deletion src/Concerns/RegistersDefaultDirectories.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

namespace Hyde\Framework\Concerns;

use Hyde\Framework\Contracts\AbstractPage;

trait RegistersDefaultDirectories
{
/**
* Register the default directories.
*
* @param array $directoryMapping
* @return void
*/
protected function registerDefaultDirectories(array $directoryMapping)
protected function registerDefaultDirectories(array $directoryMapping): void
{
foreach ($directoryMapping as $class => $location) {
/** @var AbstractPage $class */
$class::$sourceDirectory = $location;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Concerns/ValidatesExistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Hyde\Framework\Hyde;

/**
* Validate the existance of a Page model's source file.
* Validate the existence of a Page model's source file.
*/
trait ValidatesExistence
{
Expand All @@ -17,6 +17,7 @@ trait ValidatesExistence
*/
public function validateExistence(string $model, string $slug): void
{
/** @var \Hyde\Framework\Contracts\AbstractPage $model */
$filepath = $model::$sourceDirectory.'/'.
$slug.$model::$fileExtension;

Expand Down
2 changes: 2 additions & 0 deletions src/Contracts/AbstractPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ abstract class AbstractPage
public static string $fileExtension;
public static string $parserClass;

public string $slug;

public function getCurrentPagePath(): string
{
return $this->slug;
Expand Down
3 changes: 3 additions & 0 deletions src/Hyde.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public static function titleFromSlug(string $slug): string
return Str::title(str_replace('-', ' ', ($slug)));
}

/**
* @throws \Exception
*/
public static function getLatestPosts(): Collection
{
$collection = new Collection();
Expand Down
4 changes: 2 additions & 2 deletions src/HydeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class HydeServiceProvider extends ServiceProvider
*
* @return void
*/
public function register()
public function register(): void
{
/**
* @deprecated
Expand Down Expand Up @@ -84,7 +84,7 @@ function () {
*
* @return void
*/
public function boot()
public function boot(): void
{
if (config('hyde.create_default_directories', true)) {
(new CreatesDefaultDirectories)->__invoke();
Expand Down
3 changes: 3 additions & 0 deletions src/Models/MarkdownPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class MarkdownPost extends MarkdownDocument
public static string $sourceDirectory = '_posts';
public static string $parserClass = MarkdownPostParser::class;

/**
* @throws \Exception
*/
public function __construct(array $matter, string $body, string $title = '', string $slug = '')
{
parent::__construct($matter, $body, $title, $slug);
Expand Down
2 changes: 1 addition & 1 deletion src/Services/AuthorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct()
*
* If the file does not exist, it will be created.
*/
public function publishFile()
public function publishFile(): void
{
file_put_contents($this->filepath, <<<'EOF'
# In this file you can declare custom authors.
Expand Down
5 changes: 5 additions & 0 deletions src/Services/DiscoveryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Hyde\Framework\Services;

use Hyde\Framework\Contracts\AbstractPage;
use Hyde\Framework\Models\BladePage;
use Hyde\Framework\Models\DocumentationPage;
use Hyde\Framework\Models\MarkdownPage;
Expand All @@ -16,6 +17,7 @@ class DiscoveryService
{
public static function getParserClassForModel(string $model): string
{
/** @var AbstractPage $model */
return $model::$parserClass;
}

Expand All @@ -31,6 +33,7 @@ public static function getParserClassForModel(string $model): string
*/
public static function getParserInstanceForModel(string $model, string $slug): object
{
/** @var AbstractPage $model */
return new $model::$parserClass($slug);
}

Expand All @@ -39,6 +42,7 @@ public static function getParserInstanceForModel(string $model, string $slug): o
*/
public static function getFileExtensionForModelFiles(string $model): string
{
/** @var AbstractPage $model */
return $model::$fileExtension;
}

Expand All @@ -47,6 +51,7 @@ public static function getFileExtensionForModelFiles(string $model): string
*/
public static function getFilePathForModelClassFiles(string $model): string
{
/** @var AbstractPage $model */
return $model::$sourceDirectory;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Services/RssFeedService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public function __construct()
$this->addInitialChannelItems();
}

/**
* @throws \Exception
*/
public function generate(): self
{
/** @var MarkdownPost $post */
Expand Down
2 changes: 2 additions & 0 deletions src/Services/SitemapService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class SitemapService
{
public SimpleXMLElement $xmlElement;
protected float $time_start;

public function __construct()
{
Expand Down Expand Up @@ -82,6 +83,7 @@ public function addPageModelUrls(string $pageClass, string $routePrefix = ''): v
protected function getLastModDate(string $pageClass, string $slug): string
{
return date('c', filemtime(
/** @var \Hyde\Framework\Contracts\AbstractPage $pageClass */
Hyde::path($pageClass::$sourceDirectory.DIRECTORY_SEPARATOR.$slug.$pageClass::$fileExtension)
));
}
Expand Down

0 comments on commit 5aa6d55

Please sign in to comment.