33namespace Ark4ne \JsonApi \Descriptors ;
44
55use Closure ;
6- use Illuminate \Database \Eloquent \Model ;
76use Illuminate \Http \Request ;
87use Illuminate \Http \Resources \MissingValue ;
98
109/**
11- * @template T as \Illuminate\Database\Eloquent\Model
10+ * @template T
1211 */
1312abstract class Describer
1413{
@@ -28,8 +27,8 @@ public function when(bool|Closure $condition): static
2827 {
2928 $ this ->rules [] = static fn (
3029 Request $ request ,
31- Model $ model ,
32- string $ attribute
30+ mixed $ model ,
31+ string $ attribute
3332 ): bool => value ($ condition , $ request , $ model , $ attribute );
3433
3534 return $ this ;
@@ -44,8 +43,8 @@ public function whenNotNull(): static
4443 {
4544 return $ this ->when (fn (
4645 Request $ request ,
47- Model $ model ,
48- string $ attribute
46+ mixed $ model ,
47+ string $ attribute
4948 ): bool => null !== $ this ->retrieveValue ($ model , $ attribute ));
5049 }
5150
@@ -58,19 +57,19 @@ public function whenFilled(): static
5857 {
5958 return $ this ->when (fn (
6059 Request $ request ,
61- Model $ model ,
62- string $ attribute
60+ mixed $ model ,
61+ string $ attribute
6362 ): bool => filled ($ this ->retrieveValue ($ model , $ attribute )));
6463 }
6564
6665 /**
6766 * @param \Illuminate\Http\Request $request
68- * @param T $model
69- * @param string $field
67+ * @param T $model
68+ * @param string $field
7069 *
7170 * @return mixed
7271 */
73- public function valueFor (Request $ request , Model $ model , string $ field ): mixed
72+ public function valueFor (Request $ request , mixed $ model , string $ field ): mixed
7473 {
7574 if (!$ this ->check ($ request , $ model , $ field )) {
7675 return new MissingValue ();
@@ -82,13 +81,13 @@ public function valueFor(Request $request, Model $model, string $field): mixed
8281 /**
8382 * Checks if the field should be displayed
8483 *
85- * @param \Illuminate\Http\Request $request
86- * @param \Illuminate\Database\Eloquent\Model $model
87- * @param string $attribute
84+ * @param \Illuminate\Http\Request $request
85+ * @param T $model
86+ * @param string $attribute
8887 *
8988 * @return bool
9089 */
91- protected function check (Request $ request , Model $ model , string $ attribute ): bool
90+ protected function check (Request $ request , mixed $ model , string $ attribute ): bool
9291 {
9392 foreach ($ this ->rules as $ rule ) {
9493 if (!$ rule ($ request , $ model , $ attribute )) {
@@ -99,7 +98,7 @@ protected function check(Request $request, Model $model, string $attribute): boo
9998 return true ;
10099 }
101100
102- private function retrieveValue (Model $ model , string $ attribute ): mixed
101+ private function retrieveValue (mixed $ model , string $ attribute ): mixed
103102 {
104103 $ retriever = $ this ->retriever ();
105104 if ($ retriever === null ) {
@@ -113,20 +112,20 @@ private function retrieveValue(Model $model, string $attribute): mixed
113112
114113 /**
115114 * @param \Illuminate\Http\Request $request
116- * @param T $model
117- * @param string $field
115+ * @param T $model
116+ * @param string $field
118117 *
119118 * @return mixed
120119 */
121- abstract protected function resolveFor (Request $ request , Model $ model , string $ field ): mixed ;
120+ abstract protected function resolveFor (Request $ request , mixed $ model , string $ field ): mixed ;
122121
123122 /**
124123 * @return string|Closure|null
125124 */
126125 abstract public function retriever (): null |string |Closure ;
127126
128127 /**
129- * @param mixed $value
128+ * @param mixed $value
130129 * @param int|string $key
131130 *
132131 * @return int|string
0 commit comments