From 8067f06e01e0593d728cd7c148c03c9c5c39ab0c Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 28 Jan 2025 21:24:12 +1100 Subject: [PATCH] Update tests for strong types, drop type for transformer, at this stage we're going to skip this one --- src/Models/RestfulModel.php | 2 +- test/app/Models/Dates/ModelWithDates.php | 2 +- test/app/Models/Forum.php | 6 +++--- test/app/Models/Post.php | 8 ++++---- test/app/Models/Tag.php | 6 +++--- test/app/Models/Topic.php | 8 ++++---- test/app/Models/User.php | 21 ++++++++++++--------- 7 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/Models/RestfulModel.php b/src/Models/RestfulModel.php index 55ddd23..e7c9fee 100644 --- a/src/Models/RestfulModel.php +++ b/src/Models/RestfulModel.php @@ -56,7 +56,7 @@ class RestfulModel extends Model * * @var null|RestfulTransformer The transformer to use for this model, if overriding the default */ - public static ?RestfulTransformer $transformer = null; + public static $transformer = null; /** * Return the validation rules for this model diff --git a/test/app/Models/Dates/ModelWithDates.php b/test/app/Models/Dates/ModelWithDates.php index cac6807..fd17b06 100644 --- a/test/app/Models/Dates/ModelWithDates.php +++ b/test/app/Models/Dates/ModelWithDates.php @@ -32,7 +32,7 @@ class ModelWithDates extends BaseModel * * @return array Rules */ - public function getValidationRules() + public function getValidationRules(): array { return [ 'title' => 'required|string|unique:forums', diff --git a/test/app/Models/Forum.php b/test/app/Models/Forum.php index df16294..c655d05 100644 --- a/test/app/Models/Forum.php +++ b/test/app/Models/Forum.php @@ -18,9 +18,9 @@ class Forum extends BaseModel public $primaryKey = 'forum_id'; /** - * @var array Relations to load implicitly by Restful controllers + * @var ?array Relations to load implicitly by Restful controllers */ - public static $localWith = ['topics']; + public static ?array $itemWith = ['topics']; /** * @var null|BaseTransformer The transformer to use for this model, if overriding the default @@ -42,7 +42,7 @@ class Forum extends BaseModel * * @return array Rules */ - public function getValidationRules() + public function getValidationRules(): array { return [ 'name' => 'required|string|unique:forums', diff --git a/test/app/Models/Post.php b/test/app/Models/Post.php index d82e300..b45a76f 100644 --- a/test/app/Models/Post.php +++ b/test/app/Models/Post.php @@ -12,9 +12,9 @@ class Post extends BaseModel public $primaryKey = 'post_id'; /** - * @var array Relations to load implicitly by Restful controllers + * @var ?array Relations to load implicitly by Restful controllers */ - public static $localWith = ['topic', 'author']; + public static ?array $itemWith = ['topic', 'author']; /** * @var null|BaseTransformer The transformer to use for this model, if overriding the default @@ -36,7 +36,7 @@ class Post extends BaseModel * * @return array Rules */ - public function getValidationRules() + public function getValidationRules(): array { return [ 'content' => 'required', @@ -48,7 +48,7 @@ public function getValidationRules() * * Add various functionality in the model lifecycle hooks */ - public static function boot() + public static function boot(): void { parent::boot(); diff --git a/test/app/Models/Tag.php b/test/app/Models/Tag.php index b22a69a..e369230 100644 --- a/test/app/Models/Tag.php +++ b/test/app/Models/Tag.php @@ -12,9 +12,9 @@ class Tag extends BaseModel public $primaryKey = 'tag_id'; /** - * @var array Relations to load implicitly by Restful controllers + * @var ?array Relations to load implicitly by Restful controllers */ - public static $localWith = []; + public static ?array $itemWith; /** * @var null|BaseTransformer The transformer to use for this model, if overriding the default @@ -36,7 +36,7 @@ class Tag extends BaseModel * * @return array Rules */ - public function getValidationRules() + public function getValidationRules(): array { return []; } diff --git a/test/app/Models/Topic.php b/test/app/Models/Topic.php index f3e6b50..671bd16 100644 --- a/test/app/Models/Topic.php +++ b/test/app/Models/Topic.php @@ -12,9 +12,9 @@ class Topic extends BaseModel public $primaryKey = 'topic_id'; /** - * @var array Relations to load implicitly by Restful controllers + * @var ?array Relations to load implicitly by Restful controllers */ - public static $localWith = ['author', 'forum', 'posts']; + public static ?array $itemWith = ['author', 'forum', 'posts']; /** * @var null|BaseTransformer The transformer to use for this model, if overriding the default @@ -36,7 +36,7 @@ class Topic extends BaseModel * * @return array Rules */ - public function getValidationRules() + public function getValidationRules(): array { return [ 'title' => 'required|string', @@ -63,7 +63,7 @@ public function forum() * * Add various functionality in the model lifecycle hooks */ - public static function boot() + public static function boot(): void { parent::boot(); diff --git a/test/app/Models/User.php b/test/app/Models/User.php index 697768d..ea61c0a 100644 --- a/test/app/Models/User.php +++ b/test/app/Models/User.php @@ -27,9 +27,9 @@ class User extends BaseModel implements public $primaryKey = 'user_id'; /** - * @var array Relations to load implicitly by Restful controllers + * @var ?array Relations to load implicitly by Restful controllers */ - public static $localWith = ['primaryRole', 'roles']; + public static ?array $itemWith = ['primaryRole', 'roles']; /** * The attributes that are mass assignable. @@ -52,7 +52,7 @@ class User extends BaseModel implements /** * Model's boot function */ - public static function boot() + public static function boot(): void { parent::boot(); @@ -69,7 +69,8 @@ public static function boot() * * @return array Rules */ - public function getValidationRules() { + public function getValidationRules(): array + { return [ 'email' => 'email|max:255|unique:users', 'name' => 'required|min:3', @@ -98,7 +99,8 @@ public function roles() { /** * Get all user's roles */ - public function getRoles() { + public function getRoles(): ?array + { $allRoles = array_merge( [ $this->primaryRole->name, @@ -114,7 +116,8 @@ public function getRoles() { * * @return bool */ - public function isAdmin() { + public function isAdmin(): bool + { return $this->primaryRole->name == Role::ROLE_ADMIN; } @@ -124,7 +127,7 @@ public function isAdmin() { * * @return mixed */ - public function getJWTIdentifier() + public function getJWTIdentifier(): string { return $this->getKey(); } @@ -135,7 +138,7 @@ public function getJWTIdentifier() * * @return array */ - public function getJWTCustomClaims() + public function getJWTCustomClaims(): array { return [ 'user' => [ @@ -151,7 +154,7 @@ public function getJWTCustomClaims() * * @return string */ - public function getAuthIdentifierName() + public function getAuthIdentifierName(): string { return $this->getKeyName(); }