From e8827cbd507b7299d59bfcf6d8ae8c7b852671f1 Mon Sep 17 00:00:00 2001 From: James Collins Date: Thu, 25 May 2023 08:18:51 +1000 Subject: [PATCH] fix hinting and tests for L10 and PHP8 --- app/Conductors/ArticleConductor.php | 4 ++-- app/Conductors/Conductor.php | 8 ++++---- app/Conductors/EventConductor.php | 4 ++-- app/Http/Middleware/Authenticate.php | 3 +++ app/Models/User.php | 8 ++++++++ 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/Conductors/ArticleConductor.php b/app/Conductors/ArticleConductor.php index 2a1a0b5..f088691 100644 --- a/app/Conductors/ArticleConductor.php +++ b/app/Conductors/ArticleConductor.php @@ -142,9 +142,9 @@ class ArticleConductor extends Conductor * Transform the Hero field. * * @param mixed $value The current value. - * @return array The new value. + * @return array|null The new value. */ - public function transformHero(mixed $value): array + public function transformHero(mixed $value): array|null { return MediaConductor::includeModel(request(), 'hero', Media::find($value)); } diff --git a/app/Conductors/Conductor.php b/app/Conductors/Conductor.php index f25d0a2..d7518ac 100644 --- a/app/Conductors/Conductor.php +++ b/app/Conductors/Conductor.php @@ -519,9 +519,9 @@ class Conductor * @param Request $request The request data. * @param string $key The key prefix to use. * @param Model|null $model The model. - * @return array The processed and transformed model data. + * @return array|null The processed and transformed model data. */ - final public static function includeModel(Request $request, string $key, mixed $model): array + final public static function includeModel(Request $request, string $key, mixed $model): array|null { $fields = []; @@ -547,9 +547,9 @@ class Conductor * * @param mixed $fields The fields to show. * @param Model|null $model The model. - * @return array The processed and transformed model data. + * @return array|null The processed and transformed model data. */ - final public static function model(mixed $fields, mixed $model): array + final public static function model(mixed $fields, mixed $model): array|null { if ($model === null) { return null; diff --git a/app/Conductors/EventConductor.php b/app/Conductors/EventConductor.php index 260b547..3651093 100644 --- a/app/Conductors/EventConductor.php +++ b/app/Conductors/EventConductor.php @@ -118,9 +118,9 @@ class EventConductor extends Conductor * Transform the Hero field. * * @param mixed $value The current value. - * @return array The new value. + * @return array|null The new value. */ - public function transformHero(mixed $value): array + public function transformHero(mixed $value): array|null { return MediaConductor::includeModel(request(), 'hero', Media::find($value)); } diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index 76a7ff5..9515a4a 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -10,11 +10,14 @@ class Authenticate extends Middleware * Get the path the user should be redirected to when they are not authenticated. * * @param mixed $request Request. + * @return ?string */ protected function redirectTo(mixed $request): ?string { if ($request->expectsJson() === false) { return route('login'); } + + return null; } } diff --git a/app/Models/User.php b/app/Models/User.php index 3e8fe41..484e98c 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -5,8 +5,10 @@ namespace App\Models; // use Illuminate\Contracts\Auth\MustVerifyEmail; use App\Traits\Uuids; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; @@ -79,6 +81,8 @@ class User extends Authenticatable implements Auditable /** * Get the list of files of the user + * + * @return Illuminate\Database\Eloquent\Relations\HasMany */ public function permissions(): HasMany { @@ -87,6 +91,8 @@ class User extends Authenticatable implements Auditable /** * Get the permission attribute + * + * @return array */ public function getPermissionsAttribute(): array { @@ -97,6 +103,7 @@ class User extends Authenticatable implements Auditable * Test if user has permission * * @param string $permission Permission to test. + * @return boolean */ public function hasPermission(string $permission): bool { @@ -107,6 +114,7 @@ class User extends Authenticatable implements Auditable * Give permissions to the user * * @param string|array $permissions The permission(s) to give. + * @return Illuminate\Database\Eloquent\Collection */ public function givePermission($permissions): Collection {