Skip to content

Commit

Permalink
Update tests for strong types, drop type for transformer, at this sta…
Browse files Browse the repository at this point in the history
…ge we're going to skip this one
  • Loading branch information
specialtactics committed Jan 28, 2025
1 parent d0fb438 commit 8067f06
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/Models/RestfulModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/app/Models/Dates/ModelWithDates.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ModelWithDates extends BaseModel
*
* @return array Rules
*/
public function getValidationRules()
public function getValidationRules(): array
{
return [
'title' => 'required|string|unique:forums',
Expand Down
6 changes: 3 additions & 3 deletions test/app/Models/Forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,7 +42,7 @@ class Forum extends BaseModel
*
* @return array Rules
*/
public function getValidationRules()
public function getValidationRules(): array
{
return [
'name' => 'required|string|unique:forums',
Expand Down
8 changes: 4 additions & 4 deletions test/app/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,7 +36,7 @@ class Post extends BaseModel
*
* @return array Rules
*/
public function getValidationRules()
public function getValidationRules(): array
{
return [
'content' => 'required',
Expand All @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions test/app/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,7 +36,7 @@ class Tag extends BaseModel
*
* @return array Rules
*/
public function getValidationRules()
public function getValidationRules(): array
{
return [];
}
Expand Down
8 changes: 4 additions & 4 deletions test/app/Models/Topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,7 +36,7 @@ class Topic extends BaseModel
*
* @return array Rules
*/
public function getValidationRules()
public function getValidationRules(): array
{
return [
'title' => 'required|string',
Expand All @@ -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();

Expand Down
21 changes: 12 additions & 9 deletions test/app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -52,7 +52,7 @@ class User extends BaseModel implements
/**
* Model's boot function
*/
public static function boot()
public static function boot(): void
{
parent::boot();

Expand All @@ -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',
Expand Down Expand Up @@ -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,
Expand All @@ -114,7 +116,8 @@ public function getRoles() {
*
* @return bool
*/
public function isAdmin() {
public function isAdmin(): bool
{
return $this->primaryRole->name == Role::ROLE_ADMIN;
}

Expand All @@ -124,7 +127,7 @@ public function isAdmin() {
*
* @return mixed
*/
public function getJWTIdentifier()
public function getJWTIdentifier(): string
{
return $this->getKey();
}
Expand All @@ -135,7 +138,7 @@ public function getJWTIdentifier()
*
* @return array
*/
public function getJWTCustomClaims()
public function getJWTCustomClaims(): array
{
return [
'user' => [
Expand All @@ -151,7 +154,7 @@ public function getJWTCustomClaims()
*
* @return string
*/
public function getAuthIdentifierName()
public function getAuthIdentifierName(): string
{
return $this->getKeyName();
}
Expand Down

0 comments on commit 8067f06

Please sign in to comment.