refactor(model): Use match expression for PDO type detection

This commit is contained in:
kj
2026-06-19 14:52:25 -03:00
parent ee9c109ed9
commit 01c5eceeb4

View File

@@ -157,17 +157,13 @@ class Model
try {
$prepared = $db->prepare($query);
foreach (static::$dbQueryVariables as $key => $value) {
// Detectar el tipo de dato para elegir la constante de PDO
$type = PDO::PARAM_STR; // Por defecto string
if (is_int($value)) {
$type = PDO::PARAM_INT;
}
if (is_bool($value)) {
$type = PDO::PARAM_BOOL;
}
if (is_null($value)) {
$type = PDO::PARAM_NULL;
}
// Detect data type to choose the PDO constant
$type = match (gettype($value)) {
'integer' => PDO::PARAM_INT,
'boolean' => PDO::PARAM_BOOL,
'NULL' => PDO::PARAM_NULL,
default => PDO::PARAM_STR,
};
$prepared->bindValue($key, $value, $type);
}