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