Skip to content

Commit

Permalink
Merge pull request #302 from hydephp/fix-types
Browse files Browse the repository at this point in the history
Fix type issues hydephp/develop@529dea1
  • Loading branch information
github-actions committed Jul 31, 2022
1 parent 9f67e3b commit cbfcadd
Show file tree
Hide file tree
Showing 25 changed files with 63 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/Actions/GeneratesDocumentationSearchIndexFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function execute(): void
$this->save();
}

public function generate(): self
public function generate(): static
{
foreach ($this->getSourceFileSlugs() as $page) {
$this->searchIndex->push(
Expand Down Expand Up @@ -88,7 +88,7 @@ public function getJson(): string
return json_encode($this->getObject());
}

public function save(): self
public function save(): static
{
$this->needsDirectory(Hyde::path(str_replace('/search.json', '', static::$filePath)));

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/HydeBuildSearchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function createSearchPage(): void
/** @internal Estimated processing time per file in ms */
public static float $guesstimationFactor = 52.5;

protected function guesstimateGenerationTime(): int
protected function guesstimateGenerationTime(): int|float
{
return (int) round(count(DiscoveryService::getDocumentationPageFiles()) * static::$guesstimationFactor) / 1000;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/HydePublishHomepageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ protected function canExistingIndexFileBeOverwritten(): bool

return FileCacheService::checksumMatchesAny(FileCacheService::unixsumFile(
Hyde::getBladePagePath('index.blade.php')
)) ?? $this->option('force');
)) || $this->option('force');
}
}
2 changes: 1 addition & 1 deletion src/Commands/HydePublishViewsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function handle(): int
return 0;
}

protected function publishOption($selected)
protected function publishOption($selected): void
{
(new PublishesHydeViews($selected))->execute();

Expand Down
5 changes: 5 additions & 0 deletions src/Concerns/HasPageMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public function getCanonicalUrl(): string
return $this->getRoute()->getQualifiedUrl();
}

/**
* @return string[]
*
* @psalm-return list<string>
*/
public function getDynamicMetadata(): array
{
$array = [];
Expand Down
12 changes: 8 additions & 4 deletions src/Concerns/Markdown/HasConfigurableMarkdownFeatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ trait HasConfigurableMarkdownFeatures
{
protected array $features = [];

public function addFeature(string $feature): self
/** @return $this */
public function addFeature(string $feature): static
{
if (! in_array($feature, $this->features)) {
$this->features[] = $feature;
Expand All @@ -24,7 +25,8 @@ public function addFeature(string $feature): self
return $this;
}

public function removeFeature(string $feature): self
/** @return $this */
public function removeFeature(string $feature): static
{
if (in_array($feature, $this->features)) {
$this->features = array_diff($this->features, [$feature]);
Expand All @@ -33,14 +35,16 @@ public function removeFeature(string $feature): self
return $this;
}

public function withTableOfContents(): self
/** @return $this */
public function withTableOfContents(): static
{
$this->addFeature('table-of-contents');

return $this;
}

public function withPermalinks(): self
/** @return $this */
public function withPermalinks(): static
{
$this->addFeature('permalinks');

Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/AbstractPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static function parse(string $slug): static
}

/** @inheritDoc */
public static function files(): array
public static function files(): array|false
{
return DiscoveryService::getSourceFileListForModel(static::class);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Contracts/PageContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public static function parse(string $slug): static;
* Get an array of all the source file slugs for the model.
* Essentially an alias of DiscoveryService::getAbstractPageList().
*
* @return array<string>
* @return array<string>|false
*
* @see \Hyde\Framework\Testing\Unit\PageModelGetAllFilesHelperTest
*/
public static function files(): array;
public static function files(): array|false;

/**
* Get a collection of all pages, parsed into page models.
Expand Down
1 change: 1 addition & 0 deletions src/Facades/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
class Asset extends Facade
{
/** @psalm-return AssetServiceContract::class */
protected static function getFacadeAccessor(): string
{
return AssetServiceContract::class;
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function vendorPath(string $path = ''): string
* @param bool $force If true, existing files will be overwritten.
* @return bool|int Returns true|false on copy() success|failure, or an error code on failure
*/
public function copy(string $from, string $to, bool $force = false): bool|int
public function copy(string $from, string $to, bool $force = false): int|bool
{
if (! file_exists($from)) {
return 404;
Expand Down
3 changes: 2 additions & 1 deletion src/Hyde.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@
*/
class Hyde extends Facade
{
/** @psalm-return HydeKernel::class */
protected static function getFacadeAccessor(): string
{
return HydeKernel::class;
}

public static function version()
public static function version(): string
{
return HydeKernel::version();
}
Expand Down
3 changes: 2 additions & 1 deletion src/Models/DocumentationSidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

class DocumentationSidebar extends NavigationMenu
{
public function generate(): self
/** @return $this */
public function generate(): static
{
RoutingService::getInstance()->getRoutesForModel(DocumentationPage::class)->each(function (Route $route) {
$this->items->push(NavItem::fromRoute($route)->setPriority($this->getPriorityForRoute($route)));
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function getContentLength(): int
return (new FindsContentLengthForImageObject($this))->execute();
}

public function getImageAuthorAttributionString(): ?string
public function getImageAuthorAttributionString(): string|null
{
if (isset($this->author)) {
if (isset($this->credit)) {
Expand All @@ -124,7 +124,7 @@ public function getImageAuthorAttributionString(): ?string
return null;
}

public function getCopyrightString(): ?string
public function getCopyrightString(): string|null
{
if (isset($this->copyright)) {
return '<span itemprop="copyrightNotice">'.e($this->copyright).'</span>';
Expand All @@ -133,7 +133,7 @@ public function getCopyrightString(): ?string
return null;
}

public function getLicenseString(): ?string
public function getLicenseString(): string|null
{
if (isset($this->license) && isset($this->licenseUrl)) {
return '<a href="'.e($this->licenseUrl).'" rel="license nofollow noopener" itemprop="license">'.e($this->license).'</a>';
Expand Down
9 changes: 6 additions & 3 deletions src/Models/NavigationMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public static function create(?RouteContract $currentRoute = null): static
return (new static())->generate()->filter()->sort();
}

public function generate(): self
/** @return $this */
public function generate(): static
{
RoutingService::getInstance()->getRoutes()->each(function (Route $route) {
$this->items->push(NavItem::fromRoute($route));
Expand All @@ -38,15 +39,17 @@ public function generate(): self
return $this;
}

public function filter(): self
/** @return $this */
public function filter(): static
{
$this->items = $this->filterHiddenItems();
$this->items = $this->filterDuplicateItems();

return $this;
}

public function sort(): self
/** @return $this */
public function sort(): static
{
$this->items = $this->items->sortBy('priority')->values();

Expand Down
2 changes: 1 addition & 1 deletion src/Modules/DataCollections/DataCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(string $key)
parent::__construct();
}

public function getCollection(): DataCollection
public function getCollection(): static
{
$this->parseTimeInMs = round((microtime(true) - $this->timeStart) * 1000, 2);
unset($this->timeStart);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function register()
);
}

public function boot()
public function boot(): void
{
if (Features::hasDataCollections()) {
// Create the _data directory if it doesn't exist
Expand Down
6 changes: 3 additions & 3 deletions src/Services/BuildHookService.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public function getPostBuildTasks(): array
);
}

public function run(string $task): self
public function run(string $task): static
{
$this->runTask(new $task($this->output));

return $this;
}

public function runIf(string $task, callable|bool $condition): self
public function runIf(string $task, callable|bool $condition): static
{
if (is_bool($condition) ? $condition : $condition()) {
$this->run($task);
Expand All @@ -58,7 +58,7 @@ public function runIf(string $task, callable|bool $condition): self
return $this;
}

protected function runTask(BuildTaskContract $task): self
protected function runTask(BuildTaskContract $task): static
{
$task->handle();

Expand Down
21 changes: 8 additions & 13 deletions src/Services/DiscoveryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,9 @@ public static function createClickableFilepath(string $filepath): string
}

/**
* Get all the Markdown files in the _docs directory.
*
* @return array
* Get all the Markdown files in the _docs directory.
*/
public static function getDocumentationPageFiles(): array
public static function getDocumentationPageFiles(): array|false
{
return self::getSourceFileListForModel(DocumentationPage::class);
}
Expand Down Expand Up @@ -163,11 +161,10 @@ public static function formatSlugForModel(string $model, string $filepath): stri
}

/**
* Get all the Markdown files in the _pages directory.
*
* @return array
* Get all the Markdown files in the _pages directory.
*/
public static function getMarkdownPageFiles(): array
public static function getMarkdownPageFiles(): array|false
{
return self::getSourceFileListForModel(MarkdownPage::class);
}
Expand All @@ -186,21 +183,19 @@ public static function getMediaAssetFiles(): array
}

/**
* Get all the Blade files in the _pages directory.
*
* @return array
* Get all the Blade files in the _pages directory.
*/
public static function getBladePageFiles(): array
public static function getBladePageFiles(): array|false
{
return self::getSourceFileListForModel(BladePage::class);
}

/**
* Get all the Markdown files in the _posts directory.
*
* @return array
* Get all the Markdown files in the _posts directory.
*/
public static function getMarkdownPostFiles(): array
public static function getMarkdownPostFiles(): array|false
{
return self::getSourceFileListForModel(MarkdownPost::class);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Services/HydeSmartDocs.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function process(): self
return $this;
}

protected function tokenize(): self
protected function tokenize(): static
{
// The HTML content is expected to be two parts. To create semantic HTML,
// we need to split the content into header and body. We do this by
Expand All @@ -73,7 +73,7 @@ protected function tokenize(): self
return $this;
}

protected function addDynamicHeaderContent(): self
protected function addDynamicHeaderContent(): static
{
// Hook to add dynamic content to the header.
// This is where we can add TOC, breadcrumbs, etc.
Expand All @@ -85,7 +85,7 @@ protected function addDynamicHeaderContent(): self
return $this;
}

protected function addDynamicFooterContent(): self
protected function addDynamicFooterContent(): static
{
// Hook to add dynamic content to the footer.
// This is where we can add copyright, attributions, info, etc.
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Markdown/BladeDownProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(string $html, ?array $pageData = [])
$this->pageData = $pageData;
}

public function run(): self
public function run(): static
{
$this->output = implode("\n", array_map(function ($line) {
return $this->lineStartsWithDirective($line)
Expand Down
6 changes: 3 additions & 3 deletions src/Services/Markdown/ShortcodeProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(string $input)
$this->discoverShortcodes();
}

public function processInput(): self
public function processInput(): static
{
$this->output = implode("\n", array_map(function ($line) {
return $this->expandShortcode($line);
Expand Down Expand Up @@ -78,7 +78,7 @@ protected function discoverShortcodes(): void
));
}

public function addShortcodesFromArray(array $shortcodes): self
public function addShortcodesFromArray(array $shortcodes): static
{
foreach ($shortcodes as $shortcode) {
$this->addShortcode($shortcode);
Expand All @@ -87,7 +87,7 @@ public function addShortcodesFromArray(array $shortcodes): self
return $this;
}

public function addShortcode(MarkdownShortcodeContract $shortcode): self
public function addShortcode(MarkdownShortcodeContract $shortcode): static
{
$this->shortcodes[$shortcode::signature()] = $shortcode;

Expand Down
4 changes: 2 additions & 2 deletions src/Services/RoutingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ public function addRoute(RouteContract $route): self
return $this;
}

protected function discover(PageContract $page): self
protected function discover(PageContract $page): static
{
// Create a new route for the given page, and add it to the index.
$this->addRoute(new Route($page));

return $this;
}

protected function discoverRoutes(): self
protected function discoverRoutes(): static
{
$this->routes = new Collection();

Expand Down
Loading

0 comments on commit cbfcadd

Please sign in to comment.