@@ -51,9 +51,7 @@ class Component
5151
5252 public function getComponentCount ($ device_id = null )
5353 {
54- $ counts = \App \Models \Component::query ()->when ($ device_id , function ($ query , $ device_id ) {
55- return $ query ->where ('device_id ' , $ device_id );
56- })->selectRaw ('type, count(*) as count ' )->groupBy ('type ' )->pluck ('count ' , 'type ' );
54+ $ counts = \App \Models \Component::query ()->when ($ device_id , fn ($ query , $ device_id ) => $ query ->where ('device_id ' , $ device_id ))->selectRaw ('type, count(*) as count ' )->groupBy ('type ' )->pluck ('count ' , 'type ' );
5755
5856 return $ counts ->isEmpty () ? false : $ counts ->all ();
5957 }
@@ -115,12 +113,8 @@ public function getComponents($device_id = null, $options = [])
115113 }
116114
117115 // get and format results as expected by receivers
118- return $ query ->get ()->groupBy ('device_id ' )->map (function ($ group ) {
119- return $ group ->keyBy ('id ' )->map (function ($ component ) {
120- return $ component ->prefs ->pluck ('value ' , 'attribute ' )
121- ->merge ($ component ->only (array_keys ($ this ->reserved )));
122- });
123- })->toArray ();
116+ return $ query ->get ()->groupBy ('device_id ' )->map (fn ($ group ) => $ group ->keyBy ('id ' )->map (fn ($ component ) => $ component ->prefs ->pluck ('value ' , 'attribute ' )
117+ ->merge ($ component ->only (array_keys ($ this ->reserved )))))->toArray ();
124118 }
125119
126120 public function getComponentStatus ($ device = null )
@@ -233,9 +227,7 @@ public function setComponentPrefs($device_id, $updated)
233227 if ($ component ->isDirty ()) {
234228 // Log the update to the Eventlog.
235229 $ message = "Component $ component ->id has been modified: " ;
236- $ message .= collect ($ component ->getDirty ())->map (function ($ value , $ key ) {
237- return "$ key => $ value " ;
238- })->implode (', ' );
230+ $ message .= collect ($ component ->getDirty ())->map (fn ($ value , $ key ) => "$ key => $ value " )->implode (', ' );
239231
240232 // If the Status has changed we need to add a log entry
241233 if ($ component ->isDirty ('status ' )) {
@@ -248,9 +240,7 @@ public function setComponentPrefs($device_id, $updated)
248240 }
249241
250242 // update preferences
251- $ prefs = collect ($ updated [$ component ->id ])->filter (function ($ value , $ attr ) {
252- return ! array_key_exists ($ attr , $ this ->reserved );
253- });
243+ $ prefs = collect ($ updated [$ component ->id ])->filter (fn ($ value , $ attr ) => ! array_key_exists ($ attr , $ this ->reserved ));
254244
255245 $ invalid = $ component ->prefs ->keyBy ('id ' );
256246
0 commit comments