From 9b56dd3c3a4984a1a69b9097f52775ff7a4f1f67 Mon Sep 17 00:00:00 2001 From: Tommaso Bailetti Date: Wed, 17 Apr 2024 15:01:11 +0200 Subject: [PATCH] style: fixed style using pint --- app/Http/Controllers/HardwareController.php | 109 +++++++++--------- .../2024_04_11_145715_nethserver_view.php | 2 +- .../2024_04_11_154216_nethsecurity_view.php | 2 +- routes/web.php | 5 +- 4 files changed, 58 insertions(+), 60 deletions(-) diff --git a/app/Http/Controllers/HardwareController.php b/app/Http/Controllers/HardwareController.php index b70d4d7..6472eac 100644 --- a/app/Http/Controllers/HardwareController.php +++ b/app/Http/Controllers/HardwareController.php @@ -2,78 +2,77 @@ namespace App\Http\Controllers; -use App\Models\NethserverHardware; use App\Models\NethsecurityHardware; +use App\Models\NethserverHardware; use Illuminate\Http\Request; class HardwareController extends Controller { - public function index(Request $request, String $installation) + public function index(Request $request, string $installation) { // Retrieve search term from request $searchTerm = $request->input('search_term'); // Initialize variables for storing matches and count $matchingHardware = []; - $inputMatch = []; + $inputMatch = []; $count = 0; // If search term is empty, return an empty view - if($searchTerm === null || $searchTerm === '') - { + if ($searchTerm === null || $searchTerm === '') { return view('hardware', ['matchingHardware' => collect(), 'installation' => $installation]); } // Perform a query to find all hardware that contain the search term - if($installation === 'NethServer'){ - if(!empty($searchTerm)){ - $matchingHardware = NethserverHardware::where('product_name', 'ilike', '%' . $searchTerm . '%') - ->orWhere('manufacturer', 'ilike', '%' . $searchTerm . '%') - ->orWhere('processor', 'ilike', '%' . $searchTerm . '%') - ->orWhere('vga_controller', 'ilike', '%' . $searchTerm . '%') - ->orWhere('usb_controller', 'ilike', '%' . $searchTerm . '%') - ->orWhere('pci_bridge', 'ilike', '%' . $searchTerm . '%') - ->orWhere('sata_controller', 'ilike', '%' . $searchTerm . '%') - ->orWhere('communication_controller', 'ilike', '%' . $searchTerm . '%') - ->orWhere('scsi_controller', 'ilike', '%' . $searchTerm . '%') - ->orWhere('ethernet', 'ilike', '%' . $searchTerm . '%') + if ($installation === 'NethServer') { + if (! empty($searchTerm)) { + $matchingHardware = NethserverHardware::where('product_name', 'ilike', '%'.$searchTerm.'%') + ->orWhere('manufacturer', 'ilike', '%'.$searchTerm.'%') + ->orWhere('processor', 'ilike', '%'.$searchTerm.'%') + ->orWhere('vga_controller', 'ilike', '%'.$searchTerm.'%') + ->orWhere('usb_controller', 'ilike', '%'.$searchTerm.'%') + ->orWhere('pci_bridge', 'ilike', '%'.$searchTerm.'%') + ->orWhere('sata_controller', 'ilike', '%'.$searchTerm.'%') + ->orWhere('communication_controller', 'ilike', '%'.$searchTerm.'%') + ->orWhere('scsi_controller', 'ilike', '%'.$searchTerm.'%') + ->orWhere('ethernet', 'ilike', '%'.$searchTerm.'%') ->get(); } - }else if($installation === 'NethSecurity'){ - if(!empty($searchTerm)){ - $matchingHardware = NethsecurityHardware::where('product_name', 'ilike', '%' . $searchTerm . '%') - ->orWhere('manufacturer', 'ilike', '%' . $searchTerm . '%') - ->orWhere('processor', 'ilike', '%' . $searchTerm . '%') - ->orWhere('vga_controller', 'ilike', '%' . $searchTerm . '%') - ->orWhere('usb_controller', 'ilike', '%' . $searchTerm . '%') - ->orWhere('pci_bridge', 'ilike', '%' . $searchTerm . '%') - ->orWhere('sata_controller', 'ilike', '%' . $searchTerm . '%') - ->orWhere('communication_controller', 'ilike', '%' . $searchTerm . '%') - ->orWhere('scsi_controller', 'ilike', '%' . $searchTerm . '%') - ->orWhere('ethernet', 'ilike', '%' . $searchTerm . '%') + } elseif ($installation === 'NethSecurity') { + if (! empty($searchTerm)) { + $matchingHardware = NethsecurityHardware::where('product_name', 'ilike', '%'.$searchTerm.'%') + ->orWhere('manufacturer', 'ilike', '%'.$searchTerm.'%') + ->orWhere('processor', 'ilike', '%'.$searchTerm.'%') + ->orWhere('vga_controller', 'ilike', '%'.$searchTerm.'%') + ->orWhere('usb_controller', 'ilike', '%'.$searchTerm.'%') + ->orWhere('pci_bridge', 'ilike', '%'.$searchTerm.'%') + ->orWhere('sata_controller', 'ilike', '%'.$searchTerm.'%') + ->orWhere('communication_controller', 'ilike', '%'.$searchTerm.'%') + ->orWhere('scsi_controller', 'ilike', '%'.$searchTerm.'%') + ->orWhere('ethernet', 'ilike', '%'.$searchTerm.'%') ->get(); } } // Returning an array containing only the specific hardware elements that contain the search term foreach ($matchingHardware as $hardware) { - if(stripos($hardware->product_name, $searchTerm) !== false){ - $inputMatch[] = 'Product Name: ' . $hardware->product_name; - }else if(stripos($hardware->manufacturer, $searchTerm) !== false){ - $inputMatch[] = 'Manufacturer: ' . $hardware->manufacturer; - }else if(stripos($hardware->processor, $searchTerm) !== false){ - $inputMatch[] = 'Processor: ' . $hardware->processor; - }else if(stripos($hardware->vga_controller, $searchTerm) !== false){ - $inputMatch[] = 'Vga Controller: ' . $hardware->vga_controller; - }else if(stripos($hardware->usb_controller, $searchTerm) !== false){ - $inputMatch[] = 'Usb Controller: ' . $hardware->usb_controller; - }else if(stripos($hardware->pci_bridge, $searchTerm) !== false){ - $inputMatch[] = 'Pci Bridge: ' . $hardware->pci_bridge; - }else if(stripos($hardware->sata_controller, $searchTerm) !== false){ - $inputMatch[] = 'Sata Controller: ' . $hardware->sata_controller; - }else if(stripos($hardware->communication_controller, $searchTerm) !== false){ - $inputMatch[] = 'Communication Controller: ' . $hardware->communication_controller; - }else if(stripos($hardware->scsi_controller, $searchTerm) !== false){ - $inputMatch[] = 'SCSI Controller: ' . $hardware->scsi_controller; - }else if(stripos($hardware->ethernet, $searchTerm) !== false){ - $inputMatch[] = 'Ethernet: ' . $hardware->ethernet; + if (stripos($hardware->product_name, $searchTerm) !== false) { + $inputMatch[] = 'Product Name: '.$hardware->product_name; + } elseif (stripos($hardware->manufacturer, $searchTerm) !== false) { + $inputMatch[] = 'Manufacturer: '.$hardware->manufacturer; + } elseif (stripos($hardware->processor, $searchTerm) !== false) { + $inputMatch[] = 'Processor: '.$hardware->processor; + } elseif (stripos($hardware->vga_controller, $searchTerm) !== false) { + $inputMatch[] = 'Vga Controller: '.$hardware->vga_controller; + } elseif (stripos($hardware->usb_controller, $searchTerm) !== false) { + $inputMatch[] = 'Usb Controller: '.$hardware->usb_controller; + } elseif (stripos($hardware->pci_bridge, $searchTerm) !== false) { + $inputMatch[] = 'Pci Bridge: '.$hardware->pci_bridge; + } elseif (stripos($hardware->sata_controller, $searchTerm) !== false) { + $inputMatch[] = 'Sata Controller: '.$hardware->sata_controller; + } elseif (stripos($hardware->communication_controller, $searchTerm) !== false) { + $inputMatch[] = 'Communication Controller: '.$hardware->communication_controller; + } elseif (stripos($hardware->scsi_controller, $searchTerm) !== false) { + $inputMatch[] = 'SCSI Controller: '.$hardware->scsi_controller; + } elseif (stripos($hardware->ethernet, $searchTerm) !== false) { + $inputMatch[] = 'Ethernet: '.$hardware->ethernet; } $count++; } @@ -83,21 +82,21 @@ public function index(Request $request, String $installation) $rowsCount = 0; // Loop through inputMatch to group similar rows and count occurrences - foreach($inputMatch as $item){ - list($value, $row) = explode(': ', $item, 2); + foreach ($inputMatch as $item) { + [$value, $row] = explode(': ', $item, 2); //Check if the row already exists in the corresponding group $rowExists = in_array($row, $groupedInputMatch[$value]['rows'] ?? []); //If the row does not exist yet, add it - if(!$rowExists){ - if(isset($groupedInputMatch[$value])){ + if (! $rowExists) { + if (isset($groupedInputMatch[$value])) { $groupedInputMatch[$value]['rows'][] = $row; - }else{ + } else { $groupedInputMatch[$value] = ['rows' => [$row]]; } } - + // Count occurrences of each row $rowsCount = ($groupedInputMatch[$value]['occurrences'][$row] ?? 0) + 1; $groupedInputMatch[$value]['occurrences'][$row] = $rowsCount; diff --git a/database/migrations/2024_04_11_145715_nethserver_view.php b/database/migrations/2024_04_11_145715_nethserver_view.php index ba7c21b..4120b96 100644 --- a/database/migrations/2024_04_11_145715_nethserver_view.php +++ b/database/migrations/2024_04_11_145715_nethserver_view.php @@ -10,7 +10,7 @@ */ public function up(): void { - DB::statement(" + DB::statement(" CREATE OR REPLACE VIEW nethserver_view AS SELECT data->'facts'->'nodes'->'1'->'product'->>'name' AS product_name, diff --git a/database/migrations/2024_04_11_154216_nethsecurity_view.php b/database/migrations/2024_04_11_154216_nethsecurity_view.php index 159bf60..c2abe23 100644 --- a/database/migrations/2024_04_11_154216_nethsecurity_view.php +++ b/database/migrations/2024_04_11_154216_nethsecurity_view.php @@ -62,6 +62,6 @@ public function up(): void */ public function down(): void { - DB::statement("DROP VIEW IF EXISTS nethsecurity_view"); + DB::statement('DROP VIEW IF EXISTS nethsecurity_view'); } }; diff --git a/routes/web.php b/routes/web.php index cfca11c..d5e4dc1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -3,7 +3,6 @@ use App\Http\Controllers\CompatibilityController; use App\Http\Controllers\HardwareController; use Illuminate\Support\Facades\Route; -use App\Http\Controllers\SelectController; /* |-------------------------------------------------------------------------- @@ -24,8 +23,8 @@ ->withoutMiddleware('web') ->middleware('api'); -Route::get('/select', function() { +Route::get('/select', function () { return view('select'); })->name('select-hardware'); -Route::get('/hardware/{installation}', [HardwareController::class, 'index'])->name('hardware'); \ No newline at end of file +Route::get('/hardware/{installation}', [HardwareController::class, 'index'])->name('hardware');