Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply code refactors from Rector #646

Merged
merged 5 commits into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ public function handle(): int

/**
* Perform a basic sanitation to strip trailing characters.
*
* @param string $path
* @return string
*/
public function sanitizePathString(string $path): string
{
Expand Down Expand Up @@ -103,7 +100,6 @@ public function validate(): void
/**
* Output the contents of an exception.
*
* @param Exception $exception
* @return int Error code
*/
public function handleException(Exception $exception): int
Expand Down
4 changes: 0 additions & 4 deletions packages/framework/src/Facades/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class Author
* @param string $username The username of the author. This is the key used to find authors in the config.
* @param string|null $name The optional display name of the author, leave blank to use the username.
* @param string|null $website The author's optional website URL. Website, Twitter, etc.
* @return \Hyde\Framework\Features\Blogging\Models\PostAuthor
*/
public static function create(string $username, ?string $name = null, ?string $website = null): PostAuthor
{
Expand All @@ -33,9 +32,6 @@ public static function create(string $username, ?string $name = null, ?string $w
/**
* Get a Post Author instance from the config. If no author matching the username is found,
* a new Post Author instance will be created with just username supplied to the method.
*
* @param string $username
* @return \Hyde\Framework\Features\Blogging\Models\PostAuthor
*/
public static function get(string $username): PostAuthor
{
Expand Down
7 changes: 2 additions & 5 deletions packages/framework/src/Facades/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ class Features implements Arrayable, JsonSerializable

/**
* Determine if the given specified is enabled.
*
* @param string $feature
* @return bool
*/
public static function enabled(string $feature): bool
{
Expand Down Expand Up @@ -188,8 +185,8 @@ public function toArray(): array
{
$array = [];
foreach (get_class_methods(static::class) as $method) {
if (str_starts_with($method, 'has')) {
$array[Str::kebab(substr($method, 3))] = static::{$method}();
if (str_starts_with((string) $method, 'has')) {
$array[Str::kebab(substr((string) $method, 3))] = static::{$method}();
}
}

Expand Down
5 changes: 0 additions & 5 deletions packages/framework/src/Facades/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class Meta
*
* @param string $name The meta tag's name attribute.
* @param string $content The content of the meta tag.
* @return \Hyde\Framework\Features\Metadata\Elements\MetadataElement
*
* @link https://www.w3schools.com/tags/tag_meta.asp
*/
Expand All @@ -35,7 +34,6 @@ public static function name(string $name, string $content): MetadataElement
*
* @param string $property The meta tag's property attribute. The "og:" prefix is optional.
* @param string $content The content of the meta tag.
* @return \Hyde\Framework\Features\Metadata\Elements\OpenGraphElement
*
* @link https://ogp.me/
*/
Expand All @@ -50,7 +48,6 @@ public static function property(string $property, string $content): OpenGraphEle
* @param string $rel The link tag's rel attribute.
* @param string $href The link tag's href attribute.
* @param array $attr An optional key-value array of additional attributes.
* @return \Hyde\Framework\Features\Metadata\Elements\LinkElement
*
* @link https://www.w3schools.com/tags/tag_link.asp
*/
Expand All @@ -69,8 +66,6 @@ public static function get(): GlobalMetadataBag

/**
* Render the global metadata bag.
*
* @return string
*/
public static function render(): string
{
Expand Down
6 changes: 0 additions & 6 deletions packages/framework/src/Facades/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class Route
* Get a route from the route index for the specified route key.
*
* @param string $routeKey Example: posts/foo.md
* @return \Hyde\Support\Models\Route|null
*/
public static function get(string $routeKey): ?\Hyde\Support\Models\Route
{
Expand All @@ -25,8 +24,6 @@ public static function get(string $routeKey): ?\Hyde\Support\Models\Route
/**
* Get a route from the route index for the specified route key or throw an exception.
*
* @param string $routeKey
* @return \Hyde\Support\Models\Route
*
* @throws \Hyde\Framework\Exceptions\RouteNotFoundException
*/
Expand Down Expand Up @@ -55,9 +52,6 @@ public static function current(): ?\Hyde\Support\Models\Route

/**
* Determine if the supplied route key exists in the route index.
*
* @param string $routeKey
* @return bool
*/
public static function exists(string $routeKey): bool
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ trait ManagesViewData
{
/**
* Share data for the page being rendered.
*
* @param \Hyde\Pages\Concerns\HydePage $page
*/
public function shareViewData(HydePage $page): void
{
Expand All @@ -29,8 +27,6 @@ public function shareViewData(HydePage $page): void

/**
* Get the route key for the page being rendered.
*
* @return string|null
*/
public function currentPage(): ?string
{
Expand All @@ -39,8 +35,6 @@ public function currentPage(): ?string

/**
* Get the route for the page being rendered.
*
* @return \Hyde\Support\Models\Route|null
*/
public function currentRoute(): ?Route
{
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Foundation/FileCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function discoverFilesFor(string $pageClass): void
{
// Scan the source directory, and directories therein, for files that match the model's file extension.
foreach (glob($this->kernel->path($pageClass::sourcePath('{*,**/*}')), GLOB_BRACE) as $filepath) {
if (! str_starts_with(basename($filepath), '_')) {
if (! str_starts_with(basename((string) $filepath), '_')) {
$this->put($this->kernel->pathToRelative($filepath), File::make($filepath)->belongsTo($pageClass));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class ConvertsArrayToFrontMatter
/**
* Execute the action.
*
* @param array $array
* @return string $yaml front matter
*/
public function execute(array $array): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ public function save(bool $force = false): string|false
* Get the class data as an array.
*
* The identifier property is removed from the array as it can't be set in the front matter.
*
* @return array
*/
public function toArray(): array
{
Expand All @@ -97,9 +95,6 @@ public function toArray(): array
];
}

/**
* @return string
*/
public function getIdentifier(): string
{
return $this->identifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ public static function needsDirectories(array $directories): void

/**
* Ensure the supplied file's parent directory exists by creating it if it does not.
*
* @param string $file
* @param int $levels
* @return void
*/
public static function needsParentDirectory(string $file, int $levels = 1): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ trait RegistersFileLocations
* @example registerSourceDirectories([HydePage::class => '_pages'])
*
* @param array $directoryMapping{class: string<HydePage>, location: string}
* @return void
*/
protected function registerSourceDirectories(array $directoryMapping): void
{
Expand Down
4 changes: 0 additions & 4 deletions packages/framework/src/Framework/HydeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class HydeServiceProvider extends ServiceProvider

/**
* Register any application services.
*
* @return void
*/
public function register(): void
{
Expand Down Expand Up @@ -66,8 +64,6 @@ public function register(): void

/**
* Bootstrap any application services.
*
* @return void
*/
public function boot(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class DiscoveryService
* Supply a model::class constant and get a list of all the existing source file base names.
*
* @param string<\Hyde\Pages\Concerns\HydePage> $model
* @return array
*
* @throws \Hyde\Framework\Exceptions\UnsupportedPageTypeException
*
Expand Down Expand Up @@ -95,7 +94,6 @@ public static function getMediaAssetFiles(): array
* Create a filepath that can be opened in the browser from a terminal.
*
* @param string<\Hyde\Pages\Concerns\HydePage> $filepath
* @return string
*/
public static function createClickableFilepath(string $filepath): string
{
Expand Down Expand Up @@ -125,7 +123,7 @@ public static function formatSlugForModel(string $model, string $filepath): stri
protected static function getMediaGlobPattern(): string
{
return sprintf('_media/*.{%s}', str_replace(' ', '',
config('hyde.media_extensions', 'png,svg,jpg,jpeg,gif,ico,css,js')
(string) config('hyde.media_extensions', 'png,svg,jpg,jpeg,gif,ico,css,js')
));
}
}
5 changes: 0 additions & 5 deletions packages/framework/src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
if (! function_exists('hyde')) {
/**
* Get the available HydeKernel instance.
*
* @return \Hyde\Foundation\HydeKernel
*/
function hyde(): HydeKernel
{
Expand All @@ -19,9 +17,6 @@ function hyde(): HydeKernel
if (! function_exists('unslash')) {
/**
* Remove trailing slashes from the start and end of a string.
*
* @param string $string
* @return string
*/
function unslash(string $string): string
{
Expand Down
15 changes: 15 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Laravel\Set\LaravelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([__DIR__.'/packages/framework/src']);
$rectorConfig->sets([
LaravelSetList::LARAVEL_90,
\Rector\Set\ValueObject\SetList::PHP_80,
\Rector\Set\ValueObject\SetList::PHP_81,
]);
};