Skip to content

Commit 8067f06

Browse files
Update tests for strong types, drop type for transformer, at this stage we're going to skip this one
1 parent d0fb438 commit 8067f06

File tree

7 files changed

+28
-25
lines changed

7 files changed

+28
-25
lines changed

src/Models/RestfulModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class RestfulModel extends Model
5656
*
5757
* @var null|RestfulTransformer The transformer to use for this model, if overriding the default
5858
*/
59-
public static ?RestfulTransformer $transformer = null;
59+
public static $transformer = null;
6060

6161
/**
6262
* Return the validation rules for this model

test/app/Models/Dates/ModelWithDates.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ModelWithDates extends BaseModel
3232
*
3333
* @return array Rules
3434
*/
35-
public function getValidationRules()
35+
public function getValidationRules(): array
3636
{
3737
return [
3838
'title' => 'required|string|unique:forums',

test/app/Models/Forum.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class Forum extends BaseModel
1818
public $primaryKey = 'forum_id';
1919

2020
/**
21-
* @var array Relations to load implicitly by Restful controllers
21+
* @var ?array Relations to load implicitly by Restful controllers
2222
*/
23-
public static $localWith = ['topics'];
23+
public static ?array $itemWith = ['topics'];
2424

2525
/**
2626
* @var null|BaseTransformer The transformer to use for this model, if overriding the default
@@ -42,7 +42,7 @@ class Forum extends BaseModel
4242
*
4343
* @return array Rules
4444
*/
45-
public function getValidationRules()
45+
public function getValidationRules(): array
4646
{
4747
return [
4848
'name' => 'required|string|unique:forums',

test/app/Models/Post.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ class Post extends BaseModel
1212
public $primaryKey = 'post_id';
1313

1414
/**
15-
* @var array Relations to load implicitly by Restful controllers
15+
* @var ?array Relations to load implicitly by Restful controllers
1616
*/
17-
public static $localWith = ['topic', 'author'];
17+
public static ?array $itemWith = ['topic', 'author'];
1818

1919
/**
2020
* @var null|BaseTransformer The transformer to use for this model, if overriding the default
@@ -36,7 +36,7 @@ class Post extends BaseModel
3636
*
3737
* @return array Rules
3838
*/
39-
public function getValidationRules()
39+
public function getValidationRules(): array
4040
{
4141
return [
4242
'content' => 'required',
@@ -48,7 +48,7 @@ public function getValidationRules()
4848
*
4949
* Add various functionality in the model lifecycle hooks
5050
*/
51-
public static function boot()
51+
public static function boot(): void
5252
{
5353
parent::boot();
5454

test/app/Models/Tag.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ class Tag extends BaseModel
1212
public $primaryKey = 'tag_id';
1313

1414
/**
15-
* @var array Relations to load implicitly by Restful controllers
15+
* @var ?array Relations to load implicitly by Restful controllers
1616
*/
17-
public static $localWith = [];
17+
public static ?array $itemWith;
1818

1919
/**
2020
* @var null|BaseTransformer The transformer to use for this model, if overriding the default
@@ -36,7 +36,7 @@ class Tag extends BaseModel
3636
*
3737
* @return array Rules
3838
*/
39-
public function getValidationRules()
39+
public function getValidationRules(): array
4040
{
4141
return [];
4242
}

test/app/Models/Topic.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ class Topic extends BaseModel
1212
public $primaryKey = 'topic_id';
1313

1414
/**
15-
* @var array Relations to load implicitly by Restful controllers
15+
* @var ?array Relations to load implicitly by Restful controllers
1616
*/
17-
public static $localWith = ['author', 'forum', 'posts'];
17+
public static ?array $itemWith = ['author', 'forum', 'posts'];
1818

1919
/**
2020
* @var null|BaseTransformer The transformer to use for this model, if overriding the default
@@ -36,7 +36,7 @@ class Topic extends BaseModel
3636
*
3737
* @return array Rules
3838
*/
39-
public function getValidationRules()
39+
public function getValidationRules(): array
4040
{
4141
return [
4242
'title' => 'required|string',
@@ -63,7 +63,7 @@ public function forum()
6363
*
6464
* Add various functionality in the model lifecycle hooks
6565
*/
66-
public static function boot()
66+
public static function boot(): void
6767
{
6868
parent::boot();
6969

test/app/Models/User.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class User extends BaseModel implements
2727
public $primaryKey = 'user_id';
2828

2929
/**
30-
* @var array Relations to load implicitly by Restful controllers
30+
* @var ?array Relations to load implicitly by Restful controllers
3131
*/
32-
public static $localWith = ['primaryRole', 'roles'];
32+
public static ?array $itemWith = ['primaryRole', 'roles'];
3333

3434
/**
3535
* The attributes that are mass assignable.
@@ -52,7 +52,7 @@ class User extends BaseModel implements
5252
/**
5353
* Model's boot function
5454
*/
55-
public static function boot()
55+
public static function boot(): void
5656
{
5757
parent::boot();
5858

@@ -69,7 +69,8 @@ public static function boot()
6969
*
7070
* @return array Rules
7171
*/
72-
public function getValidationRules() {
72+
public function getValidationRules(): array
73+
{
7374
return [
7475
'email' => 'email|max:255|unique:users',
7576
'name' => 'required|min:3',
@@ -98,7 +99,8 @@ public function roles() {
9899
/**
99100
* Get all user's roles
100101
*/
101-
public function getRoles() {
102+
public function getRoles(): ?array
103+
{
102104
$allRoles = array_merge(
103105
[
104106
$this->primaryRole->name,
@@ -114,7 +116,8 @@ public function getRoles() {
114116
*
115117
* @return bool
116118
*/
117-
public function isAdmin() {
119+
public function isAdmin(): bool
120+
{
118121
return $this->primaryRole->name == Role::ROLE_ADMIN;
119122
}
120123

@@ -124,7 +127,7 @@ public function isAdmin() {
124127
*
125128
* @return mixed
126129
*/
127-
public function getJWTIdentifier()
130+
public function getJWTIdentifier(): string
128131
{
129132
return $this->getKey();
130133
}
@@ -135,7 +138,7 @@ public function getJWTIdentifier()
135138
*
136139
* @return array
137140
*/
138-
public function getJWTCustomClaims()
141+
public function getJWTCustomClaims(): array
139142
{
140143
return [
141144
'user' => [
@@ -151,7 +154,7 @@ public function getJWTCustomClaims()
151154
*
152155
* @return string
153156
*/
154-
public function getAuthIdentifierName()
157+
public function getAuthIdentifierName(): string
155158
{
156159
return $this->getKeyName();
157160
}

0 commit comments

Comments
 (0)