Skip to content

Commit

Permalink
Merge pull request #1868 from hydephp/increase-type-coverage
Browse files Browse the repository at this point in the history
Refactor code to increase code quality and type coverage hydephp/develop@05dd78e
  • Loading branch information
github-actions committed Jul 17, 2024
1 parent 01df8b0 commit d744fa8
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 39 deletions.
5 changes: 5 additions & 0 deletions src/Foundation/Concerns/BaseFoundationCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
/**
* Base class for the kernel auto-discovery collections.
*
* @template TKey of array-key
* @template TValue
*
* @extends \Illuminate\Support\Collection<TKey, TValue>
*
* These collections are the heart of the discovery process.
*
* They are responsible for discovering the files, pages, and routes,
Expand Down
3 changes: 0 additions & 3 deletions src/Foundation/Concerns/HandlesFoundationCollections.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,20 @@
*/
trait HandlesFoundationCollections
{
/** @return \Hyde\Foundation\Kernel\FileCollection<string, \Hyde\Support\Filesystem\ProjectFile> */
public function files(): FileCollection
{
$this->needsToBeBooted();

return $this->files;
}

/** @return \Hyde\Foundation\Kernel\PageCollection<string, \Hyde\Pages\Concerns\HydePage> */
public function pages(): PageCollection
{
$this->needsToBeBooted();

return $this->pages;
}

/** @return \Hyde\Foundation\Kernel\RouteCollection<string, \Hyde\Support\Models\Route> */
public function routes(): RouteCollection
{
$this->needsToBeBooted();
Expand Down
1 change: 0 additions & 1 deletion src/Foundation/Facades/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
class Files extends Facade
{
/** @return \Hyde\Foundation\Kernel\FileCollection<string, \Hyde\Support\Filesystem\SourceFile> */
public static function getFacadeRoot(): FileCollection
{
return HydeKernel::getInstance()->files();
Expand Down
1 change: 0 additions & 1 deletion src/Foundation/Facades/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
class Pages extends Facade
{
/** @return \Hyde\Foundation\Kernel\PageCollection<string, \Hyde\Pages\Concerns\HydePage> */
public static function getFacadeRoot(): PageCollection
{
return HydeKernel::getInstance()->pages();
Expand Down
2 changes: 0 additions & 2 deletions src/Foundation/Facades/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
class Routes extends Facade
{
/** @return \Hyde\Foundation\Kernel\RouteCollection<string, \Hyde\Support\Models\Route> */
public static function getFacadeRoot(): RouteCollection
{
return HydeKernel::getInstance()->routes();
Expand All @@ -41,7 +40,6 @@ public static function getOrFail(string $routeKey): Route
return static::getFacadeRoot()->getRoute($routeKey);
}

/** @return \Hyde\Foundation\Kernel\RouteCollection<\Hyde\Support\Models\Route> */
public static function all(): RouteCollection
{
return static::getFacadeRoot()->getRoutes();
Expand Down
7 changes: 6 additions & 1 deletion src/Foundation/Internal/LoadYamlConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@
class LoadYamlConfiguration
{
protected YamlConfigurationRepository $yaml;

/** @var array<string, array<string, null|scalar|array>> */
protected array $config;

public function bootstrap(Application $app): void
{
$this->yaml = $app->make(YamlConfigurationRepository::class);

if ($this->yaml->hasYamlConfigFile()) {
tap($app->make('config'), function (Repository $config): void {
/** @var Repository $config */
$config = $app->make('config');

tap($config, function (Repository $config): void {
$this->config = $config->all();
$this->mergeParsedConfiguration();
})->set($this->config);
Expand Down
7 changes: 2 additions & 5 deletions src/Foundation/Kernel/FileCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @template T of \Hyde\Support\Filesystem\SourceFile
*
* @template-extends \Hyde\Foundation\Concerns\BaseFoundationCollection<string, T>
* @extends \Hyde\Foundation\Concerns\BaseFoundationCollection<string, T>
*
* @property array<string, SourceFile> $items The files in the collection.
*
Expand Down Expand Up @@ -71,10 +71,7 @@ public function getFile(string $path): SourceFile
return $this->get($path) ?? throw new FileNotFoundException($path);
}

/**
* @param class-string<\Hyde\Pages\Concerns\HydePage>|null $pageClass
* @return \Hyde\Foundation\Kernel\FileCollection<string, \Hyde\Support\Filesystem\SourceFile>
*/
/** @param class-string<\Hyde\Pages\Concerns\HydePage>|null $pageClass */
public function getFiles(?string $pageClass = null): FileCollection
{
return $pageClass ? $this->filter(function (SourceFile $file) use ($pageClass): bool {
Expand Down
7 changes: 2 additions & 5 deletions src/Foundation/Kernel/PageCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @template T of \Hyde\Pages\Concerns\HydePage
*
* @template-extends \Hyde\Foundation\Concerns\BaseFoundationCollection<string, T>
* @extends \Hyde\Foundation\Concerns\BaseFoundationCollection<string, T>
*
* @property array<string, HydePage> $items The pages in the collection.
*
Expand Down Expand Up @@ -59,10 +59,7 @@ public function getPage(string $sourcePath): HydePage
return $this->get($sourcePath) ?? throw new FileNotFoundException($sourcePath);
}

/**
* @param class-string<\Hyde\Pages\Concerns\HydePage>|null $pageClass
* @return \Hyde\Foundation\Kernel\PageCollection<string, \Hyde\Pages\Concerns\HydePage>
*/
/** @param class-string<\Hyde\Pages\Concerns\HydePage>|null $pageClass */
public function getPages(?string $pageClass = null): PageCollection
{
return $pageClass ? $this->filter(function (HydePage $page) use ($pageClass): bool {
Expand Down
7 changes: 2 additions & 5 deletions src/Foundation/Kernel/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @template T of \Hyde\Support\Models\Route
*
* @template-extends \Hyde\Foundation\Concerns\BaseFoundationCollection<string, T>
* @extends \Hyde\Foundation\Concerns\BaseFoundationCollection<string, T>
*
* @property array<string, Route> $items The routes in the collection.
*
Expand Down Expand Up @@ -53,10 +53,7 @@ public function getRoute(string $routeKey): Route
return $this->get($routeKey) ?? throw new RouteNotFoundException($routeKey);
}

/**
* @param class-string<\Hyde\Pages\Concerns\HydePage>|null $pageClass
* @return \Hyde\Foundation\Kernel\RouteCollection<string, \Hyde\Support\Models\Route>
*/
/** @param class-string<\Hyde\Pages\Concerns\HydePage>|null $pageClass */
public function getRoutes(?string $pageClass = null): RouteCollection
{
return $pageClass ? $this->filter(function (Route $route) use ($pageClass): bool {
Expand Down
17 changes: 5 additions & 12 deletions src/Framework/Features/Metadata/MetadataBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,19 @@ public function get(): array

public function add(MetadataElementContract|string $element): static
{
return match (true) {
$element instanceof LinkElement => $this->addElement('links', $element),
$element instanceof MetadataElement => $this->addElement('metadata', $element),
$element instanceof OpenGraphElement => $this->addElement('properties', $element),
match (true) {
$element instanceof LinkElement => $this->links[$element->uniqueKey()] = $element,
$element instanceof MetadataElement => $this->metadata[$element->uniqueKey()] = $element,
$element instanceof OpenGraphElement => $this->properties[$element->uniqueKey()] = $element,
default => $this->addGenericElement((string) $element),
};
}

protected function addElement(string $type, MetadataElementContract $element): static
{
$this->{$type}[$element->uniqueKey()] = $element;

return $this;
}

protected function addGenericElement(string $element): static
protected function addGenericElement(string $element): void
{
$this->generics[] = $element;

return $this;
}

/** @return array<string, MetadataElementContract> */
Expand Down
7 changes: 3 additions & 4 deletions src/Hyde.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Hyde\Foundation\Kernel\RouteCollection;
use Hyde\Pages\Concerns\HydePage;
use Hyde\Support\Models\Route;
use Hyde\Support\Filesystem\SourceFile;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\HtmlString;
use JetBrains\PhpStorm\Pure;
Expand Down Expand Up @@ -53,9 +52,9 @@
* @method static string getMediaDirectory()
* @method static string getMediaOutputDirectory()
* @method static Features features()
* @method static FileCollection<string, SourceFile> files()
* @method static PageCollection<string, HydePage> pages()
* @method static RouteCollection<string, Route> routes()
* @method static FileCollection files()
* @method static PageCollection pages()
* @method static RouteCollection routes()
* @method static Route|null currentRoute()
* @method static HydeKernel getInstance()
* @method static Filesystem filesystem()
Expand Down

0 comments on commit d744fa8

Please sign in to comment.