@@ -12,7 +12,7 @@ class JsonMeasurableEncoder implements MeasurableEncoder
1212 */
1313 public function encode (Measurable $ metric ): string
1414 {
15- $ model = $ metric ->measurable ();
15+ $ measurable = $ metric ->measurable ();
1616
1717 return json_encode ([
1818 'name ' => Enum::value ($ metric ->name ()),
@@ -21,9 +21,10 @@ public function encode(Measurable $metric): string
2121 'month ' => $ metric ->month (),
2222 'day ' => $ metric ->day (),
2323 'hour ' => $ metric ->hour (),
24- 'measurable ' => $ model ? get_class ($ model ) : null ,
25- 'measurable_key ' => $ model ?->getKeyName() ?? null ,
26- 'measurable_id ' => $ model ?->getKey() ?? null ,
24+ 'model ' => $ metric ->model (),
25+ 'measurable ' => $ measurable ? get_class ($ measurable ) : null ,
26+ 'measurable_key ' => $ measurable ?->getKeyName() ?? null ,
27+ 'measurable_id ' => $ measurable ?->getKey() ?? null ,
2728 'additional ' => $ metric ->additional (),
2829 ]);
2930 }
@@ -36,12 +37,12 @@ public function decode(string $key, int $value): Measurable
3637 $ attributes = json_decode ($ key , true );
3738
3839 if ($ attributes ['measurable ' ] && class_exists ($ attributes ['measurable ' ])) {
39- /** @var \Illuminate\Database\Eloquent\Model $model */
40- $ model = (new $ attributes ['measurable ' ])->newFromBuilder ([
40+ /** @var \Illuminate\Database\Eloquent\Model $measurable */
41+ $ measurable = (new $ attributes ['measurable ' ])->newFromBuilder ([
4142 $ attributes ['measurable_key ' ] => $ attributes ['measurable_id ' ],
4243 ]);
4344 } else {
44- $ model = null ;
45+ $ measurable = null ;
4546 }
4647
4748 $ date = CarbonImmutable::create (
@@ -56,9 +57,10 @@ public function decode(string $key, int $value): Measurable
5657 category: $ attributes ['category ' ],
5758 value: $ value ,
5859 date: $ date ,
59- measurable: $ model ,
60+ measurable: $ measurable ,
6061 additional: $ attributes ['additional ' ] ?? [],
6162 hourly: $ attributes ['hour ' ] ?? false ,
63+ model: $ attributes ['model ' ] ?? null ,
6264 );
6365 }
6466}
0 commit comments