diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 2641f145928..b9119bd8bb5 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -21,6 +21,8 @@ This serves two purposes: - Updated the realtime compiler to generate the documentation search index each time it's requested in https://github.com/hydephp/develop/pull/1405 (fixes https://github.com/hydephp/develop/issues/1404) - Updated the navigation menu generator to remove duplicates after running the sorting method in https://github.com/hydephp/develop/pull/1407 (fixes https://github.com/hydephp/develop/issues/1406) - Updated the exception message caused by missing source option for featured images to include the path of the file that caused the error in https://github.com/hydephp/develop/pull/1409 +- Narrows down parsed `BladeMatter` array types to `array` (Experimental feature not covered by BC promise) in https://github.com/hydephp/develop/pull/1410 +- Internal code refactors and improvements in https://github.com/hydephp/develop/pull/1410 ### Deprecated - for soon-to-be removed features. diff --git a/packages/framework/src/Console/Commands/PublishHomepageCommand.php b/packages/framework/src/Console/Commands/PublishHomepageCommand.php index 9b10552f81e..05744d01028 100644 --- a/packages/framework/src/Console/Commands/PublishHomepageCommand.php +++ b/packages/framework/src/Console/Commands/PublishHomepageCommand.php @@ -31,6 +31,7 @@ class PublishHomepageCommand extends Command /** @var string */ protected $description = 'Publish one of the default homepages to index.blade.php.'; + /** @var array */ protected array $options = [ 'welcome'=> [ 'name' => 'Welcome', @@ -96,6 +97,7 @@ protected function formatPublishableChoices(): array })->values()->toArray(); } + /** @return Collection */ protected function getTemplateOptions(): Collection { return new Collection($this->options); diff --git a/packages/framework/src/Facades/Filesystem.php b/packages/framework/src/Facades/Filesystem.php index d1f3bdadf44..56991dd0604 100644 --- a/packages/framework/src/Facades/Filesystem.php +++ b/packages/framework/src/Facades/Filesystem.php @@ -63,7 +63,7 @@ public static function relativePath(string $path): string * * @param string $pattern * @param int $flags - * @return \Illuminate\Support\Collection + * @return \Illuminate\Support\Collection */ public static function smartGlob(string $pattern, int $flags = 0): Collection { diff --git a/packages/framework/src/Foundation/Kernel/Filesystem.php b/packages/framework/src/Foundation/Kernel/Filesystem.php index a51df395883..dcc8f79ed73 100644 --- a/packages/framework/src/Foundation/Kernel/Filesystem.php +++ b/packages/framework/src/Foundation/Kernel/Filesystem.php @@ -65,6 +65,8 @@ public function path(string $path = ''): string * Get an absolute file path from a supplied relative path. * * Input types are matched, meaning that if the input is a string so will the output be. + * + * @param string|array $path */ public function pathToAbsolute(string|array $path): string|array { @@ -143,6 +145,8 @@ public function vendorPath(string $path = '', string $package = 'framework'): st /** * Touch one or more files in the project's directory. + * + * @param string|array $path */ public function touch(string|array $path): bool { @@ -159,6 +163,8 @@ public function touch(string|array $path): bool /** * Unlink one or more files in the project's directory. + * + * @param string|array $path */ public function unlink(string|array $path): bool { @@ -185,9 +191,11 @@ public function unlinkIfExists(string $path): bool return false; } + /** @return \Illuminate\Support\Collection */ public function smartGlob(string $pattern, int $flags = 0): Collection { return collect(\Hyde\Facades\Filesystem::glob($pattern, $flags)) - ->map(fn (string $path): string => $this->pathToRelative($path)); + ->map(fn (string $path): string => $this->pathToRelative($path)) + ->values(); } } diff --git a/packages/framework/src/Framework/Actions/BladeMatterParser.php b/packages/framework/src/Framework/Actions/BladeMatterParser.php index 78aefd59605..1f6c03f2530 100644 --- a/packages/framework/src/Framework/Actions/BladeMatterParser.php +++ b/packages/framework/src/Framework/Actions/BladeMatterParser.php @@ -121,6 +121,7 @@ protected static function extractValue(string $line): string return trim($key); } + /** @return scalar|array */ protected static function getValueWithType(string $value): mixed { $value = trim($value); @@ -138,6 +139,7 @@ protected static function getValueWithType(string $value): mixed return json_decode($value) ?? $value; } + /** @return array */ protected static function parseArrayString(string $string): array { $array = []; @@ -167,7 +169,9 @@ protected static function parseArrayString(string $string): array $pair = explode('=>', $token); // Add key/value pair to array - $array[static::getValueWithType(trim(trim($pair[0]), "'"))] = static::getValueWithType(trim(trim($pair[1]), "'")); + $key = (string) static::getValueWithType(trim(trim($pair[0]), "'")); + $value = static::getValueWithType(trim(trim($pair[1]), "'")); + $array[$key] = $value; } return $array; diff --git a/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php b/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php index d7ea838fdb0..d03c6a9dedf 100644 --- a/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php +++ b/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php @@ -57,8 +57,10 @@ protected function askIfUnsafeDirectoryShouldBeEmptied(): bool )); } + /** @return array */ protected function safeOutputDirectories(): array { + /** @var array $directories */ return Config::getArray('hyde.safe_output_directories', ['_site', 'docs', 'build']); } } diff --git a/packages/framework/src/Framework/Factories/NavigationDataFactory.php b/packages/framework/src/Framework/Factories/NavigationDataFactory.php index 3c8267f8f75..3068855c630 100644 --- a/packages/framework/src/Framework/Factories/NavigationDataFactory.php +++ b/packages/framework/src/Framework/Factories/NavigationDataFactory.php @@ -201,6 +201,7 @@ protected function getSubdirectoryConfiguration(): string return Config::getString('hyde.navigation.subdirectories', 'hidden'); } + /** @param class-string $class */ protected function isInstanceOf(string $class): bool { return is_a($this->pageClass, $class, true); diff --git a/packages/framework/src/Framework/Features/Metadata/MetadataBag.php b/packages/framework/src/Framework/Features/Metadata/MetadataBag.php index e39c6171e24..5d0c2aa40d6 100644 --- a/packages/framework/src/Framework/Features/Metadata/MetadataBag.php +++ b/packages/framework/src/Framework/Features/Metadata/MetadataBag.php @@ -20,9 +20,16 @@ */ class MetadataBag implements Htmlable { + /** @var array */ protected array $links = []; + + /** @var array */ protected array $metadata = []; + + /** @var array */ protected array $properties = []; + + /** @var array */ protected array $generics = []; public function toHtml(): string @@ -59,7 +66,7 @@ public function add(MetadataElementContract|string $element): static return $this->addElement('properties', $element); } - return $this->addGenericElement($element); + return $this->addGenericElement((string) $element); } protected function addElement(string $type, MetadataElementContract $element): static @@ -76,12 +83,15 @@ protected function addGenericElement(string $element): static return $this; } + /** @return array */ protected function getPrefixedArray(string $type): array { + /** @var array $bag */ + $bag = $this->{$type}; + $array = []; - /** @var MetadataElementContract $element */ - foreach ($this->{$type} as $key => $element) { + foreach ($bag as $key => $element) { $array["$type:$key"] = $element; } diff --git a/packages/framework/src/Framework/Features/Navigation/DropdownNavItem.php b/packages/framework/src/Framework/Features/Navigation/DropdownNavItem.php index f1adc1cc2d4..aef24a99973 100644 --- a/packages/framework/src/Framework/Features/Navigation/DropdownNavItem.php +++ b/packages/framework/src/Framework/Features/Navigation/DropdownNavItem.php @@ -26,11 +26,13 @@ public function __construct(string $label, array $items, ?int $priority = null) $this->items = $items; } + /** @param array $items */ public static function fromArray(string $name, array $items): static { return new static($name, $items); } + /** @return Collection */ public function getItems(): Collection { return collect($this->items); @@ -38,10 +40,13 @@ public function getItems(): Collection private function searchForDropdownPriorityInNavigationConfig(string $groupKey): ?int { - return Config::getArray('hyde.navigation.order', [ + /** @var array $config */ + $config = Config::getArray('hyde.navigation.order', [ 'index' => 0, 'posts' => 10, 'docs/index' => 100, - ])[$groupKey] ?? null; + ]); + + return $config[$groupKey] ?? null; } } diff --git a/packages/framework/src/Framework/Services/BuildTaskService.php b/packages/framework/src/Framework/Services/BuildTaskService.php index 2e58293b551..a976526e214 100644 --- a/packages/framework/src/Framework/Services/BuildTaskService.php +++ b/packages/framework/src/Framework/Services/BuildTaskService.php @@ -42,7 +42,7 @@ public function __construct() { $this->registerFrameworkTasks(); - $this->registerTasks(Config::getArray('hyde.build_tasks', [])); + $this->registerTasks($this->findTasksInConfig()); $this->registerTasks($this->findTasksInAppDirectory()); } @@ -52,7 +52,7 @@ public function setOutput(?OutputStyle $output): void $this->output = $output; } - /** @return array> */ + /** @return array|class-string<\Hyde\Framework\Features\BuildTasks\PostBuildTask>> */ public function getRegisteredTasks(): array { return array_map(fn (BuildTask $task): string => $task::class, array_values($this->buildTasks)); @@ -87,6 +87,7 @@ protected function registerTaskInService(PreBuildTask|PostBuildTask $task): void $this->buildTasks[$this->makeTaskIdentifier($task)] = $task; } + /** @param class-string<\Hyde\Framework\Features\BuildTasks\PreBuildTask|\Hyde\Framework\Features\BuildTasks\PostBuildTask> $task */ protected function registerIf(string $task, bool $condition): void { if ($condition) { @@ -94,6 +95,7 @@ protected function registerIf(string $task, bool $condition): void } } + /** @param array<\Hyde\Framework\Features\BuildTasks\PreBuildTask|\Hyde\Framework\Features\BuildTasks\PostBuildTask|class-string<\Hyde\Framework\Features\BuildTasks\PreBuildTask|\Hyde\Framework\Features\BuildTasks\PostBuildTask>> $tasks */ protected function registerTasks(array $tasks): void { foreach ($tasks as $task) { @@ -101,6 +103,13 @@ protected function registerTasks(array $tasks): void } } + /** @return array|class-string<\Hyde\Framework\Features\BuildTasks\PostBuildTask>> */ + protected function findTasksInConfig(): array + { + return Config::getArray('hyde.build_tasks', []); + } + + /** @return array|class-string<\Hyde\Framework\Features\BuildTasks\PostBuildTask>> */ protected function findTasksInAppDirectory(): array { return Filesystem::smartGlob('app/Actions/*BuildTask.php')->map(function (string $file): string {