Skip to content

Commit a27e718

Browse files
author
github-actions
committed
Merge pull request #403 from hydephp/improve-types
Improve types hydephp/develop@77a1251
1 parent 16dad51 commit a27e718

20 files changed

+45
-25
lines changed

src/Actions/BladeMatterParser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public static function extractValue(string $line): string
111111
}
112112

113113
/** @internal Return the proper type for the string */
114-
public static function normalizeValue($value): mixed
114+
public static function normalizeValue(string $value): mixed
115115
{
116116
$value = trim($value);
117117

src/Actions/SourceFileParser.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public function __construct(string $pageClass, string $identifier)
3737

3838
protected function parseBladePage(): BladePage
3939
{
40-
return new BladePage($this->identifier,
40+
return new BladePage(
41+
$this->identifier,
4142
(BladeMatterParser::parseFile(BladePage::qualifyBasename($this->identifier)))
4243
);
4344
}

src/Commands/HydeMakePostCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function handle(): int
8484
$this->comment('If you want to overwrite the file supply the --force flag.');
8585
}
8686

87-
return $exception->getCode();
87+
return (int) $exception->getCode();
8888
}
8989
}
9090
}

src/Commands/HydePackageDiscoverCommand.php

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
class HydePackageDiscoverCommand extends BaseCommand
1313
{
14+
/** @var true */
1415
protected $hidden = true;
1516

1617
public function handle(PackageManifest $manifest)

src/Commands/HydePublishViewsCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function handle(): int
3232
return 0;
3333
}
3434

35-
protected function publishOption($selected): void
35+
protected function publishOption(string $selected): void
3636
{
3737
(new PublishesHydeViews($selected))->execute();
3838

src/Commands/HydeRebuildStaticSiteCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function handleException(Exception $exception): int
122122
$this->error('Something went wrong!');
123123
$this->warn($exception->getMessage());
124124

125-
return $exception->getCode();
125+
return (int) $exception->getCode();
126126
}
127127

128128
/**

src/Concerns/FrontMatter/Schemas/BlogPostSchema.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected function makeDescription(): string
6666
return substr($this->markdown, 0, 125).'...';
6767
}
6868

69-
return $this->markdown;
69+
return (string) $this->markdown;
7070
}
7171

7272
protected function getAuthor(): ?Author

src/Contracts/RouteFacadeContract.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static function getFromModel(PageContract $page): RouteContract;
5656
/**
5757
* Get all routes from the Router index.
5858
*
59-
* @return \Illuminate\Support\Collection<\Hyde\Framework\Contracts\RouteContract>
59+
* @return \Hyde\Framework\RouteCollection<\Hyde\Framework\Contracts\RouteContract>
6060
*/
6161
public static function all(): Collection;
6262

src/HydeKernel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function getBasePath(): string
7474
return $this->basePath;
7575
}
7676

77-
public function setBasePath(string $basePath)
77+
public function setBasePath(string $basePath): void
7878
{
7979
$this->basePath = rtrim($basePath, '/\\');
8080
}

src/Models/Pages/MarkdownPost.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ public function getCanonicalLink(): string
3838
}
3939

4040
/** @deprecated v0.58.x-beta (pull description instead) */
41-
public function getPostDescription(): string
41+
public function getPostDescription(): string|null
4242
{
4343
return $this->description;
4444
}
4545

46+
/**
47+
* @return \Illuminate\Support\Collection<\Hyde\Framework\Models\Pages\MarkdownPost>
48+
*/
4649
public static function getLatestPosts(): Collection
4750
{
4851
return static::all()->sortByDesc('matter.date');

src/Models/Route.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Hyde\Framework\Hyde;
1111
use Hyde\Framework\Services\RoutingService;
1212
use Illuminate\Contracts\Support\Arrayable;
13-
use Illuminate\Support\Collection;
1413

1514
/**
1615
* @see \Hyde\Framework\Testing\Feature\RouteTest
@@ -131,7 +130,7 @@ public static function getFromModel(PageContract $page): RouteContract
131130
}
132131

133132
/** @inheritDoc */
134-
public static function all(): Collection
133+
public static function all(): \Hyde\Framework\RouteCollection
135134
{
136135
return RoutingService::getInstance()->getRoutes();
137136
}

src/Models/ValidationResult.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct(string $defaultMessage = 'Generic check')
1919
$this->message = $defaultMessage;
2020
}
2121

22-
public function pass(?string $withMessage = null): self
22+
public function pass(?string $withMessage = null): static
2323
{
2424
$this->passed = true;
2525
if ($withMessage) {
@@ -29,7 +29,7 @@ public function pass(?string $withMessage = null): self
2929
return $this;
3030
}
3131

32-
public function fail(?string $withMessage = null): self
32+
public function fail(?string $withMessage = null): static
3333
{
3434
$this->passed = false;
3535
if ($withMessage) {
@@ -39,7 +39,7 @@ public function fail(?string $withMessage = null): self
3939
return $this;
4040
}
4141

42-
public function skip(?string $withMessage = null): self
42+
public function skip(?string $withMessage = null): static
4343
{
4444
$this->skipped = true;
4545
if ($withMessage) {
@@ -49,7 +49,7 @@ public function skip(?string $withMessage = null): self
4949
return $this;
5050
}
5151

52-
public function withTip(string $withTip): self
52+
public function withTip(string $withTip): static
5353
{
5454
$this->tip = $withTip;
5555

src/Modules/DataCollections/DataCollection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getMarkdownFiles(): array
5151
* @param string $key for a subdirectory of the _data directory
5252
* @return DataCollection<\Hyde\Framework\Models\MarkdownDocument>
5353
*/
54-
public static function markdown(string $key): DataCollection
54+
public static function markdown(string $key): static
5555
{
5656
$collection = new DataCollection($key);
5757
foreach ($collection->getMarkdownFiles() as $file) {

src/Modules/Markdown/CodeblockFilepathProcessor.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public static function process(string $html): string
3636
{
3737
$lines = explode("\n", $html);
3838

39+
/** @var int $index */
3940
foreach ($lines as $index => $line) {
4041
if (str_starts_with($line, '<!-- HYDE[Filepath]')) {
4142
$path = static::trimHydeDirective($line);
@@ -90,7 +91,7 @@ protected static function resolveTemplate(string $path): string
9091
return sprintf('<small class="filepath"><span class="sr-only">Filepath: </span>%s</small>', $path);
9192
}
9293

93-
protected static function resolveTorchlightCodeLine(string $label, $lines): string|array
94+
protected static function resolveTorchlightCodeLine(string $label, string $lines): string
9495
{
9596
return str_replace(
9697
static::$torchlightKey,
@@ -99,7 +100,7 @@ protected static function resolveTorchlightCodeLine(string $label, $lines): stri
99100
);
100101
}
101102

102-
protected static function resolveCodeLine(string $label, $lines): string|array|null
103+
protected static function resolveCodeLine(string $label, string $lines): string
103104
{
104105
return preg_replace(
105106
'/<pre><code class="language-(.*?)">/',

src/Modules/Markdown/Shortcodes/AbstractColoredBlockquote.php

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ protected static function getClassNameFromSignature(string $signature): string
3737
return str_replace('>', '', $signature);
3838
}
3939

40+
/**
41+
* @return array (AbstractColoredBlockquote)[]
42+
*/
4043
public static function get(): array
4144
{
4245
return [

src/PageCollection.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function getPage(string $sourcePath): PageContract
3232
return $this->items[$sourcePath] ?? throw new FileNotFoundException($sourcePath.' in page collection');
3333
}
3434

35-
public function getPages(?string $pageClass = null): Collection
35+
public function getPages(?string $pageClass = null): self
3636
{
3737
return ! $pageClass ? $this : $this->filter(function (PageContract $page) use ($pageClass): bool {
3838
return $page instanceof $pageClass;
@@ -67,6 +67,10 @@ protected function discoverPagesFor(string $pageClass): void
6767
});
6868
}
6969

70+
/**
71+
* @param string<\Hyde\Framework\Contracts\PageContract> $pageClass
72+
* @return \Illuminate\Support\Collection<\Hyde\Framework\Contracts\PageContract>
73+
*/
7074
protected function parsePagesFor(string $pageClass): Collection
7175
{
7276
$collection = new Collection();

src/Services/BuildService.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
use Hyde\Framework\Concerns\InteractsWithDirectories;
66
use Hyde\Framework\Contracts\RouteContract as Route;
77
use Hyde\Framework\Hyde;
8+
use Hyde\Framework\RouteCollection;
89
use Hyde\Framework\StaticPageBuilder;
910
use Illuminate\Console\Concerns\InteractsWithIO;
1011
use Illuminate\Console\OutputStyle;
11-
use Illuminate\Support\Collection;
1212
use Illuminate\Support\Facades\File;
1313

1414
/**
@@ -67,7 +67,10 @@ function ($filepath) {
6767
$this->newLine(2);
6868
}
6969

70-
protected function getDiscoveredModels(): Collection
70+
/**
71+
* @return \Hyde\Framework\RouteCollection<array-key, class-string<\Hyde\Framework\Contracts\PageContract>>
72+
*/
73+
protected function getDiscoveredModels(): RouteCollection
7174
{
7275
return $this->router->getRoutes()->map(function (Route $route) {
7376
return $route->getPageType();
@@ -88,6 +91,9 @@ protected function compilePagesForClass(string $pageClass): void
8891
$this->newLine(2);
8992
}
9093

94+
/**
95+
* @return \Closure(Route):string
96+
*/
9197
protected function compileRoute(): \Closure
9298
{
9399
return function (Route $route) {

src/Services/MarkdownService.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ protected function determineIfTorchlightAttributionShouldBeInjected(): bool
216216
protected function injectTorchlightAttribution(): string
217217
{
218218
return '<br>'.$this->converter->convert(config(
219-
'torchlight.attribution.markdown',
220-
'Syntax highlighted by torchlight.dev'
221-
));
219+
'torchlight.attribution.markdown',
220+
'Syntax highlighted by torchlight.dev'
221+
));
222222
}
223223
}

src/Services/ValidationService.php

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
class ValidationService
1414
{
15+
/** @return string[] */
1516
public static function checks(): array
1617
{
1718
$service = new self();

src/Views/Components/LinkComponent.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public function __construct(string $href)
1616
$this->href = Hyde::relativeLink($href);
1717
}
1818

19-
public function render(): View|Factory
19+
/** @interitDoc */
20+
public function render(): Factory|View
2021
{
2122
return view('hyde::components.link');
2223
}

0 commit comments

Comments
 (0)