22
33namespace Finller \Invoice \Casts ;
44
5+ use Finller \Invoice \InvoiceDiscount ;
56use Illuminate \Contracts \Database \Eloquent \CastsAttributes ;
67use Illuminate \Database \Eloquent \Casts \Json ;
78use Illuminate \Database \Eloquent \Model ;
89
10+ /**
11+ * @implements CastsAttributes<null|InvoiceDiscount[], array<string, mixed>>
12+ */
913class Discounts implements CastsAttributes
1014{
1115 /**
12- * Cast the given value.
13- *
1416 * @param array<string, mixed> $attributes
17+ * @return null|InvoiceDiscount[]
1518 */
1619 public function get (Model $ model , string $ key , mixed $ value , array $ attributes ): mixed
1720 {
1821 $ data = Json::decode (data_get ($ attributes , $ key , '' ));
1922
23+ /** @var string $class */
2024 $ class = config ('invoices.discount_class ' );
2125
2226 return is_array ($ data ) ? array_map (fn (?array $ item ) => $ class ::fromArray ($ item ), $ data ) : null ;
@@ -25,7 +29,9 @@ public function get(Model $model, string $key, mixed $value, array $attributes):
2529 /**
2630 * Prepare the given value for storage.
2731 *
32+ * @param null|InvoiceDiscount[] $value
2833 * @param array<string, mixed> $attributes
34+ * @return array<string, mixed>
2935 */
3036 public function set (Model $ model , string $ key , mixed $ value , array $ attributes ): mixed
3137 {
0 commit comments