Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       100.00%  | 
       8 / 8  | 
               | 
       100.00%  | 
       2 / 2  | 
       CRAP |         | 
       100.00%  | 
       1 / 1  | 
      
| SearchController |         | 
       100.00%  | 
       8 / 8  | 
               | 
       100.00%  | 
       2 / 2  | 
       3 |         | 
       100.00%  | 
       1 / 1  | 
      
| __construct |         | 
       100.00%  | 
       1 / 1  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| searchProducts |         | 
       100.00%  | 
       7 / 7  | 
               | 
       100.00%  | 
       1 / 1  | 
       2 | |||
| 1 | <?php | 
| 2 | namespace Controllers; | 
| 3 | |
| 4 | class SearchController { | 
| 5 | private $conn; | 
| 6 | |
| 7 | public function __construct($conn) { | 
| 8 | $this->conn = $conn; | 
| 9 | } | 
| 10 | |
| 11 | public function searchProducts($searchTerm) { | 
| 12 | try { | 
| 13 | $searchTerm = "%{$searchTerm}%"; | 
| 14 | $stmt = $this->conn->prepare("SELECT * FROM products WHERE name LIKE ?"); | 
| 15 | $stmt->execute([$searchTerm]); | 
| 16 | |
| 17 | return $stmt->fetchAll(\PDO::FETCH_ASSOC); | 
| 18 | } catch (\Exception $e) { | 
| 19 | error_log("Error en búsqueda: " . $e->getMessage()); | 
| 20 | return []; | 
| 21 | } | 
| 22 | } | 
| 23 | } |