Skip to content

Commit 7828479

Browse files
committed
Clarify CastsAttributes::set() phpdoc to accept TGet and recommend symmetric casts
- Update @param type to `TGet|TSet|null` to reflect that `set()` may receive the runtime cast value (TGet) as well as raw DB-compatible value (TSet). - Add note on assignment symmetry to avoid surprises when `$a = $a = $b` is used (common with caching). - Recommend symmetric casts (TGet == TSet) where possible for safer and more predictable behavior. - No runtime behavior changes.
1 parent ab76a52 commit 7828479

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/Illuminate/Contracts/Database/Eloquent/CastsAttributes.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
use Illuminate\Database\Eloquent\Model;
66

77
/**
8+
* Recommendation:
9+
* Prefer symmetric casts (TGet == TSet) so "$a = $a = $b"
10+
* remain safe and unsurprising.
11+
*
812
* @template TGet
913
* @template TSet
1014
*/
@@ -24,10 +28,12 @@ public function get(Model $model, string $key, mixed $value, array $attributes);
2428
/**
2529
* Transform the attribute to its underlying model values.
2630
*
27-
* @param \Illuminate\Database\Eloquent\Model $model
28-
* @param string $key
29-
* @param TSet|null $value
30-
* @param array<string, mixed> $attributes
31+
* Important:
32+
* Implementations must tolerate receiving the runtime cast value (TGet) here.
33+
* As with object caching, `set()` may receive the value returned by `get()` (TGet).
34+
* Implementations should therefore accept both TGet and TSet.
35+
*
36+
* @param TGet|TSet|null $value
3137
* @return mixed
3238
*/
3339
public function set(Model $model, string $key, mixed $value, array $attributes);

0 commit comments

Comments
 (0)