| Conditions | 4 | 
| Paths | 4 | 
| Total Lines | 26 | 
| Code Lines | 15 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Tests | 0 | 
| CRAP Score | 20 | 
| Changes | 0 | ||
| 1 | <?php | ||
| 22 | public function handle(Request $request) | ||
| 23 |     { | ||
| 24 | // Strict protection enabled: we won't remove assets who are still being used... | ||
| 25 |         $assetIds = collect($request->input('asset_ids', []))->reject(function($assetId){ | ||
| 26 |             return DB::table('asset_pivots') | ||
| 27 |                 ->where('asset_id', $assetId) | ||
| 28 |                 ->where('unused', 0) | ||
| 29 | ->exists(); | ||
| 30 | })->toArray(); | ||
| 31 | |||
| 32 | if($assetIds) | ||
|  | |||
| 33 |         { | ||
| 34 |                 foreach($assetIds as $k => $assetId) { | ||
| 35 |                     try{ | ||
| 36 | $this->deleteAsset->remove($assetId); | ||
| 37 |                     } catch(FileNotAccessibleException $e) { | ||
| 38 | unset($assetIds[$k]); // So our count of removed assets is correct in the log. | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 |                 Audit::activity()->log('removed ' . count($assetIds) . ' assets from the mediagallery.'); | ||
| 43 | |||
| 44 | return true; | ||
| 45 | } | ||
| 46 | |||
| 47 | return false; | ||
| 48 | } | ||
| 50 | 
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.