@@ -39,9 +39,7 @@ public function __construct(Request $request)
3939 public function index (Request $ request ): JsonResponse
4040 {
4141 try {
42- return $ this ->prepareResponse (
43- $ this ->scope ->getPreferences ($ this ->group )
44- );
42+ return response ()->json ($ this ->scope ->getPreferences ($ this ->group ));
4543 } catch (Throwable $ exception ) {
4644 $ this ->handleException ($ exception );
4745 }
@@ -50,9 +48,7 @@ public function index(Request $request): JsonResponse
5048 public function get (Request $ request ): JsonResponse
5149 {
5250 try {
53- return $ this ->prepareResponse (
54- $ this ->scope ->getPreference ($ this ->group )
55- );
51+ return $ this ->prepareResponse ();
5652 } catch (Throwable $ exception ) {
5753 $ this ->handleException ($ exception );
5854 }
@@ -67,9 +63,7 @@ public function update(PreferenceUpdateRequest $request): JsonResponse
6763
6864 $ this ->scope ->setPreference ($ this ->group , $ value );
6965
70- return $ this ->prepareResponse (
71- $ this ->scope ->getPreference ($ this ->group )
72- );
66+ return $ this ->prepareResponse ();
7367 } catch (Throwable $ exception ) {
7468 return $ this ->handleException ($ exception );
7569 }
@@ -80,9 +74,7 @@ public function delete(Request $request): JsonResponse
8074 try {
8175 $ this ->scope ->removePreference ($ this ->group );
8276
83- return $ this ->prepareResponse (
84- $ this ->scope ->getPreference ($ this ->group )
85- );
77+ return $ this ->prepareResponse ();
8678 } catch (Throwable $ exception ) {
8779 $ this ->handleException ($ exception );
8880 }
@@ -149,18 +141,13 @@ private function extractScopeAndGroup($routeName): array
149141 ];
150142 }
151143
152- private function prepareResponse (mixed $ pref ): JsonResponse
144+ /**
145+ * @throws AuthorizationException
146+ * @throws PreferenceNotFoundException
147+ */
148+ private function prepareResponse (): JsonResponse
153149 {
154- if (!empty ($ pref ) && is_object ($ pref ) && method_exists ($ pref , 'toArray ' )) {
155- $ pref = $ pref ->toArray ();
156- }
157-
158- if (!is_array ($ pref )) {
159- $ pref = [
160- 'value ' => $ pref ,
161- ];
162- }
163- return response ()->json ($ pref );
150+ return response ()->json ($ this ->scope ->getPreferenceDto ($ this ->group ));
164151 }
165152
166153 /**
@@ -176,7 +163,7 @@ private function handleException(Throwable|\Exception $exception)
176163 };
177164 }
178165
179- private function clean (mixed &$ value )
166+ private function clean (mixed &$ value ): void
180167 {
181168 if (ConfigHelper::isXssCleanEnabled ()) {
182169 if (is_string ($ value )) {
0 commit comments