Skip to content

Commit 06f7848

Browse files
authored
fix: add generics to Model attribute related methods (#55962)
1 parent a48260a commit 06f7848

File tree

3 files changed

+43
-43
lines changed

3 files changed

+43
-43
lines changed

src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ public function totallyGuarded()
248248
/**
249249
* Get the fillable attributes of a given array.
250250
*
251-
* @param array $attributes
252-
* @return array
251+
* @param array<string, mixed> $attributes
252+
* @return array<string, mixed>
253253
*/
254254
protected function fillableFromArray(array $attributes)
255255
{

src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,28 @@ trait HasAttributes
5050
/**
5151
* The model's attributes.
5252
*
53-
* @var array
53+
* @var array<string, mixed>
5454
*/
5555
protected $attributes = [];
5656

5757
/**
5858
* The model attribute's original state.
5959
*
60-
* @var array
60+
* @var array<string, mixed>
6161
*/
6262
protected $original = [];
6363

6464
/**
6565
* The changed model attributes.
6666
*
67-
* @var array
67+
* @var array<string, mixed>
6868
*/
6969
protected $changes = [];
7070

7171
/**
7272
* The previous state of the changed model attributes.
7373
*
74-
* @var array
74+
* @var array<string, mixed>
7575
*/
7676
protected $previous = [];
7777

@@ -209,7 +209,7 @@ protected function initializeHasAttributes()
209209
/**
210210
* Convert the model's attributes to an array.
211211
*
212-
* @return array
212+
* @return array<string, mixed>
213213
*/
214214
public function attributesToArray()
215215
{
@@ -244,8 +244,8 @@ public function attributesToArray()
244244
/**
245245
* Add the date attributes to the attributes array.
246246
*
247-
* @param array $attributes
248-
* @return array
247+
* @param array<string, mixed> $attributes
248+
* @return array<string, mixed>
249249
*/
250250
protected function addDateAttributesToArray(array $attributes)
251251
{
@@ -265,9 +265,9 @@ protected function addDateAttributesToArray(array $attributes)
265265
/**
266266
* Add the mutated attributes to the attributes array.
267267
*
268-
* @param array $attributes
269-
* @param array $mutatedAttributes
270-
* @return array
268+
* @param array<string, mixed> $attributes
269+
* @param array<string, mixed> $mutatedAttributes
270+
* @return array<string, mixed>
271271
*/
272272
protected function addMutatedAttributesToArray(array $attributes, array $mutatedAttributes)
273273
{
@@ -293,9 +293,9 @@ protected function addMutatedAttributesToArray(array $attributes, array $mutated
293293
/**
294294
* Add the casted attributes to the attributes array.
295295
*
296-
* @param array $attributes
297-
* @param array $mutatedAttributes
298-
* @return array
296+
* @param array<string, mixed> $attributes
297+
* @param array<string, mixed> $mutatedAttributes
298+
* @return array<string, mixed>
299299
*/
300300
protected function addCastAttributesToArray(array $attributes, array $mutatedAttributes)
301301
{
@@ -348,7 +348,7 @@ protected function addCastAttributesToArray(array $attributes, array $mutatedAtt
348348
/**
349349
* Get an attribute array of all arrayable attributes.
350350
*
351-
* @return array
351+
* @return array<string, mixed>
352352
*/
353353
protected function getArrayableAttributes()
354354
{
@@ -2032,8 +2032,8 @@ public function getRawOriginal($key = null, $default = null)
20322032
/**
20332033
* Get a subset of the model's attributes.
20342034
*
2035-
* @param array|mixed $attributes
2036-
* @return array
2035+
* @param array<string>|mixed $attributes
2036+
* @return array<string, mixed>
20372037
*/
20382038
public function only($attributes)
20392039
{
@@ -2049,7 +2049,7 @@ public function only($attributes)
20492049
/**
20502050
* Get all attributes except the given ones.
20512051
*
2052-
* @param array|mixed $attributes
2052+
* @param array<string>|mixed $attributes
20532053
* @return array
20542054
*/
20552055
public function except($attributes)
@@ -2093,7 +2093,7 @@ public function syncOriginalAttribute($attribute)
20932093
/**
20942094
* Sync multiple original attribute with their current values.
20952095
*
2096-
* @param array|string $attributes
2096+
* @param array<string>|string $attributes
20972097
* @return $this
20982098
*/
20992099
public function syncOriginalAttributes($attributes)
@@ -2125,7 +2125,7 @@ public function syncChanges()
21252125
/**
21262126
* Determine if the model or any of the given attribute(s) have been modified.
21272127
*
2128-
* @param array|string|null $attributes
2128+
* @param array<string>|string|null $attributes
21292129
* @return bool
21302130
*/
21312131
public function isDirty($attributes = null)
@@ -2138,7 +2138,7 @@ public function isDirty($attributes = null)
21382138
/**
21392139
* Determine if the model or all the given attribute(s) have remained the same.
21402140
*
2141-
* @param array|string|null $attributes
2141+
* @param array<string>|string|null $attributes
21422142
* @return bool
21432143
*/
21442144
public function isClean($attributes = null)
@@ -2161,7 +2161,7 @@ public function discardChanges()
21612161
/**
21622162
* Determine if the model or any of the given attribute(s) were changed when the model was last saved.
21632163
*
2164-
* @param array|string|null $attributes
2164+
* @param array<string>|string|null $attributes
21652165
* @return bool
21662166
*/
21672167
public function wasChanged($attributes = null)
@@ -2174,8 +2174,8 @@ public function wasChanged($attributes = null)
21742174
/**
21752175
* Determine if any of the given attributes were changed when the model was last saved.
21762176
*
2177-
* @param array $changes
2178-
* @param array|string|null $attributes
2177+
* @param array<string> $changes
2178+
* @param array<string>|string|null $attributes
21792179
* @return bool
21802180
*/
21812181
protected function hasChanges($changes, $attributes = null)
@@ -2202,7 +2202,7 @@ protected function hasChanges($changes, $attributes = null)
22022202
/**
22032203
* Get the attributes that have been changed since the last sync.
22042204
*
2205-
* @return array
2205+
* @return array<string, mixed>
22062206
*/
22072207
public function getDirty()
22082208
{
@@ -2220,7 +2220,7 @@ public function getDirty()
22202220
/**
22212221
* Get the attributes that have been changed since the last sync for an update operation.
22222222
*
2223-
* @return array
2223+
* @return array<string, mixed>
22242224
*/
22252225
protected function getDirtyForUpdate()
22262226
{
@@ -2230,7 +2230,7 @@ protected function getDirtyForUpdate()
22302230
/**
22312231
* Get the attributes that were changed when the model was last saved.
22322232
*
2233-
* @return array
2233+
* @return array<string, mixed>
22342234
*/
22352235
public function getChanges()
22362236
{
@@ -2240,7 +2240,7 @@ public function getChanges()
22402240
/**
22412241
* Get the attributes that were previously original before the model was last saved.
22422242
*
2243-
* @return array
2243+
* @return array<string, mixed>
22442244
*/
22452245
public function getPrevious()
22462246
{
@@ -2347,7 +2347,7 @@ protected function transformModelValue($key, $value)
23472347
/**
23482348
* Append attributes to query when building a query.
23492349
*
2350-
* @param array|string $attributes
2350+
* @param array<string>|string $attributes
23512351
* @return $this
23522352
*/
23532353
public function append($attributes)

src/Illuminate/Database/Eloquent/Model.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ abstract class Model implements Arrayable, ArrayAccess, CanBeEscapedWhenCastToSt
265265
/**
266266
* Create a new Eloquent model instance.
267267
*
268-
* @param array $attributes
268+
* @param array<string, mixed> $attributes
269269
*/
270270
public function __construct(array $attributes = [])
271271
{
@@ -568,7 +568,7 @@ public static function withoutBroadcasting(callable $callback)
568568
/**
569569
* Fill the model with an array of attributes.
570570
*
571-
* @param array $attributes
571+
* @param array<string, mixed> $attributes
572572
* @return $this
573573
*
574574
* @throws \Illuminate\Database\Eloquent\MassAssignmentException
@@ -618,7 +618,7 @@ public function fill(array $attributes)
618618
/**
619619
* Fill the model with an array of attributes. Force mass assignment.
620620
*
621-
* @param array $attributes
621+
* @param array<string, mixed> $attributes
622622
* @return $this
623623
*/
624624
public function forceFill(array $attributes)
@@ -657,7 +657,7 @@ public function qualifyColumns($columns)
657657
/**
658658
* Create a new instance of the given model.
659659
*
660-
* @param array $attributes
660+
* @param array<string, mixed> $attributes
661661
* @param bool $exists
662662
* @return static
663663
*/
@@ -686,7 +686,7 @@ public function newInstance($attributes = [], $exists = false)
686686
/**
687687
* Create a new model instance that is existing.
688688
*
689-
* @param array $attributes
689+
* @param array<string, mixed> $attributes
690690
* @param string|null $connection
691691
* @return static
692692
*/
@@ -1049,8 +1049,8 @@ protected function incrementOrDecrement($column, $amount, $extra, $method)
10491049
/**
10501050
* Update the model in the database.
10511051
*
1052-
* @param array $attributes
1053-
* @param array $options
1052+
* @param array<string, mixed> $attributes
1053+
* @param array<string, mixed> $options
10541054
* @return bool
10551055
*/
10561056
public function update(array $attributes = [], array $options = [])
@@ -1065,8 +1065,8 @@ public function update(array $attributes = [], array $options = [])
10651065
/**
10661066
* Update the model in the database within a transaction.
10671067
*
1068-
* @param array $attributes
1069-
* @param array $options
1068+
* @param array<string, mixed> $attributes
1069+
* @param array<string, mixed> $options
10701070
* @return bool
10711071
*
10721072
* @throws \Throwable
@@ -1083,8 +1083,8 @@ public function updateOrFail(array $attributes = [], array $options = [])
10831083
/**
10841084
* Update the model in the database without raising any events.
10851085
*
1086-
* @param array $attributes
1087-
* @param array $options
1086+
* @param array<string, mixed> $attributes
1087+
* @param array<string, mixed> $options
10881088
* @return bool
10891089
*/
10901090
public function updateQuietly(array $attributes = [], array $options = [])
@@ -1400,7 +1400,7 @@ protected function performInsert(Builder $query)
14001400
* Insert the given attributes and set the ID on the model.
14011401
*
14021402
* @param \Illuminate\Database\Eloquent\Builder<static> $query
1403-
* @param array $attributes
1403+
* @param array<string, mixed> $attributes
14041404
* @return void
14051405
*/
14061406
protected function insertAndSetId(Builder $query, $attributes)
@@ -1668,7 +1668,7 @@ protected function newBaseQueryBuilder()
16681668
* Create a new pivot model instance.
16691669
*
16701670
* @param \Illuminate\Database\Eloquent\Model $parent
1671-
* @param array $attributes
1671+
* @param array<string, mixed> $attributes
16721672
* @param string $table
16731673
* @param bool $exists
16741674
* @param string|null $using

0 commit comments

Comments
 (0)