Skip to content

Commit 81ca18d

Browse files
authored
Merge pull request #646 from hydephp/rector
Apply code refactors from Rector
2 parents 4949ad4 + 4d3cb77 commit 81ca18d

15 files changed

+19
-54
lines changed

packages/framework/src/Console/Commands/RebuildStaticSiteCommand.php

-4
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ public function handle(): int
7070

7171
/**
7272
* Perform a basic sanitation to strip trailing characters.
73-
*
74-
* @param string $path
75-
* @return string
7673
*/
7774
public function sanitizePathString(string $path): string
7875
{
@@ -103,7 +100,6 @@ public function validate(): void
103100
/**
104101
* Output the contents of an exception.
105102
*
106-
* @param Exception $exception
107103
* @return int Error code
108104
*/
109105
public function handleException(Exception $exception): int

packages/framework/src/Facades/Author.php

-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class Author
2323
* @param string $username The username of the author. This is the key used to find authors in the config.
2424
* @param string|null $name The optional display name of the author, leave blank to use the username.
2525
* @param string|null $website The author's optional website URL. Website, Twitter, etc.
26-
* @return \Hyde\Framework\Features\Blogging\Models\PostAuthor
2726
*/
2827
public static function create(string $username, ?string $name = null, ?string $website = null): PostAuthor
2928
{
@@ -33,9 +32,6 @@ public static function create(string $username, ?string $name = null, ?string $w
3332
/**
3433
* Get a Post Author instance from the config. If no author matching the username is found,
3534
* a new Post Author instance will be created with just username supplied to the method.
36-
*
37-
* @param string $username
38-
* @return \Hyde\Framework\Features\Blogging\Models\PostAuthor
3935
*/
4036
public static function get(string $username): PostAuthor
4137
{

packages/framework/src/Facades/Features.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ class Features implements Arrayable, JsonSerializable
3131

3232
/**
3333
* Determine if the given specified is enabled.
34-
*
35-
* @param string $feature
36-
* @return bool
3734
*/
3835
public static function enabled(string $feature): bool
3936
{
@@ -188,8 +185,8 @@ public function toArray(): array
188185
{
189186
$array = [];
190187
foreach (get_class_methods(static::class) as $method) {
191-
if (str_starts_with($method, 'has')) {
192-
$array[Str::kebab(substr($method, 3))] = static::{$method}();
188+
if (str_starts_with((string) $method, 'has')) {
189+
$array[Str::kebab(substr((string) $method, 3))] = static::{$method}();
193190
}
194191
}
195192

packages/framework/src/Facades/Meta.php

-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class Meta
2121
*
2222
* @param string $name The meta tag's name attribute.
2323
* @param string $content The content of the meta tag.
24-
* @return \Hyde\Framework\Features\Metadata\Elements\MetadataElement
2524
*
2625
* @link https://www.w3schools.com/tags/tag_meta.asp
2726
*/
@@ -35,7 +34,6 @@ public static function name(string $name, string $content): MetadataElement
3534
*
3635
* @param string $property The meta tag's property attribute. The "og:" prefix is optional.
3736
* @param string $content The content of the meta tag.
38-
* @return \Hyde\Framework\Features\Metadata\Elements\OpenGraphElement
3937
*
4038
* @link https://ogp.me/
4139
*/
@@ -50,7 +48,6 @@ public static function property(string $property, string $content): OpenGraphEle
5048
* @param string $rel The link tag's rel attribute.
5149
* @param string $href The link tag's href attribute.
5250
* @param array $attr An optional key-value array of additional attributes.
53-
* @return \Hyde\Framework\Features\Metadata\Elements\LinkElement
5451
*
5552
* @link https://www.w3schools.com/tags/tag_link.asp
5653
*/
@@ -69,8 +66,6 @@ public static function get(): GlobalMetadataBag
6966

7067
/**
7168
* Render the global metadata bag.
72-
*
73-
* @return string
7469
*/
7570
public static function render(): string
7671
{

packages/framework/src/Facades/Route.php

-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class Route
1515
* Get a route from the route index for the specified route key.
1616
*
1717
* @param string $routeKey Example: posts/foo.md
18-
* @return \Hyde\Support\Models\Route|null
1918
*/
2019
public static function get(string $routeKey): ?\Hyde\Support\Models\Route
2120
{
@@ -25,8 +24,6 @@ public static function get(string $routeKey): ?\Hyde\Support\Models\Route
2524
/**
2625
* Get a route from the route index for the specified route key or throw an exception.
2726
*
28-
* @param string $routeKey
29-
* @return \Hyde\Support\Models\Route
3027
*
3128
* @throws \Hyde\Framework\Exceptions\RouteNotFoundException
3229
*/
@@ -55,9 +52,6 @@ public static function current(): ?\Hyde\Support\Models\Route
5552

5653
/**
5754
* Determine if the supplied route key exists in the route index.
58-
*
59-
* @param string $routeKey
60-
* @return bool
6155
*/
6256
public static function exists(string $routeKey): bool
6357
{

packages/framework/src/Foundation/Concerns/ManagesViewData.php

-6
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ trait ManagesViewData
1717
{
1818
/**
1919
* Share data for the page being rendered.
20-
*
21-
* @param \Hyde\Pages\Concerns\HydePage $page
2220
*/
2321
public function shareViewData(HydePage $page): void
2422
{
@@ -29,8 +27,6 @@ public function shareViewData(HydePage $page): void
2927

3028
/**
3129
* Get the route key for the page being rendered.
32-
*
33-
* @return string|null
3430
*/
3531
public function currentPage(): ?string
3632
{
@@ -39,8 +35,6 @@ public function currentPage(): ?string
3935

4036
/**
4137
* Get the route for the page being rendered.
42-
*
43-
* @return \Hyde\Support\Models\Route|null
4438
*/
4539
public function currentRoute(): ?Route
4640
{

packages/framework/src/Foundation/FileCollection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected function discoverFilesFor(string $pageClass): void
8080
{
8181
// Scan the source directory, and directories therein, for files that match the model's file extension.
8282
foreach (glob($this->kernel->path($pageClass::sourcePath('{*,**/*}')), GLOB_BRACE) as $filepath) {
83-
if (! str_starts_with(basename($filepath), '_')) {
83+
if (! str_starts_with(basename((string) $filepath), '_')) {
8484
$this->put($this->kernel->pathToRelative($filepath), File::make($filepath)->belongsTo($pageClass));
8585
}
8686
}

packages/framework/src/Framework/Actions/ConvertsArrayToFrontMatter.php

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class ConvertsArrayToFrontMatter
1616
/**
1717
* Execute the action.
1818
*
19-
* @param array $array
2019
* @return string $yaml front matter
2120
*/
2221
public function execute(array $array): string

packages/framework/src/Framework/Actions/CreatesNewMarkdownPostFile.php

-5
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ public function save(bool $force = false): string|false
8383
* Get the class data as an array.
8484
*
8585
* The identifier property is removed from the array as it can't be set in the front matter.
86-
*
87-
* @return array
8886
*/
8987
public function toArray(): array
9088
{
@@ -97,9 +95,6 @@ public function toArray(): array
9795
];
9896
}
9997

100-
/**
101-
* @return string
102-
*/
10398
public function getIdentifier(): string
10499
{
105100
return $this->identifier;

packages/framework/src/Framework/Concerns/InteractsWithDirectories.php

-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ public static function needsDirectories(array $directories): void
3535

3636
/**
3737
* Ensure the supplied file's parent directory exists by creating it if it does not.
38-
*
39-
* @param string $file
40-
* @param int $levels
41-
* @return void
4238
*/
4339
public static function needsParentDirectory(string $file, int $levels = 1): void
4440
{

packages/framework/src/Framework/Concerns/RegistersFileLocations.php

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ trait RegistersFileLocations
2525
* @example registerSourceDirectories([HydePage::class => '_pages'])
2626
*
2727
* @param array $directoryMapping{class: string<HydePage>, location: string}
28-
* @return void
2928
*/
3029
protected function registerSourceDirectories(array $directoryMapping): void
3130
{

packages/framework/src/Framework/HydeServiceProvider.php

-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class HydeServiceProvider extends ServiceProvider
3030

3131
/**
3232
* Register any application services.
33-
*
34-
* @return void
3533
*/
3634
public function register(): void
3735
{
@@ -66,8 +64,6 @@ public function register(): void
6664

6765
/**
6866
* Bootstrap any application services.
69-
*
70-
* @return void
7167
*/
7268
public function boot(): void
7369
{

packages/framework/src/Framework/Services/DiscoveryService.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class DiscoveryService
3030
* Supply a model::class constant and get a list of all the existing source file base names.
3131
*
3232
* @param string<\Hyde\Pages\Concerns\HydePage> $model
33-
* @return array
3433
*
3534
* @throws \Hyde\Framework\Exceptions\UnsupportedPageTypeException
3635
*
@@ -95,7 +94,6 @@ public static function getMediaAssetFiles(): array
9594
* Create a filepath that can be opened in the browser from a terminal.
9695
*
9796
* @param string<\Hyde\Pages\Concerns\HydePage> $filepath
98-
* @return string
9997
*/
10098
public static function createClickableFilepath(string $filepath): string
10199
{
@@ -125,7 +123,7 @@ public static function formatSlugForModel(string $model, string $filepath): stri
125123
protected static function getMediaGlobPattern(): string
126124
{
127125
return sprintf('_media/*.{%s}', str_replace(' ', '',
128-
config('hyde.media_extensions', 'png,svg,jpg,jpeg,gif,ico,css,js')
126+
(string) config('hyde.media_extensions', 'png,svg,jpg,jpeg,gif,ico,css,js')
129127
));
130128
}
131129
}

packages/framework/src/helpers.php

-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
if (! function_exists('hyde')) {
88
/**
99
* Get the available HydeKernel instance.
10-
*
11-
* @return \Hyde\Foundation\HydeKernel
1210
*/
1311
function hyde(): HydeKernel
1412
{
@@ -19,9 +17,6 @@ function hyde(): HydeKernel
1917
if (! function_exists('unslash')) {
2018
/**
2119
* Remove trailing slashes from the start and end of a string.
22-
*
23-
* @param string $string
24-
* @return string
2520
*/
2621
function unslash(string $string): string
2722
{

rector.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Laravel\Set\LaravelSetList;
7+
8+
return static function (RectorConfig $rectorConfig): void {
9+
$rectorConfig->paths([__DIR__.'/packages/framework/src']);
10+
$rectorConfig->sets([
11+
LaravelSetList::LARAVEL_90,
12+
\Rector\Set\ValueObject\SetList::PHP_80,
13+
\Rector\Set\ValueObject\SetList::PHP_81,
14+
]);
15+
};

0 commit comments

Comments
 (0)