From 6bf6710049588b1b7f9e13856e897b87de76b3d6 Mon Sep 17 00:00:00 2001 From: Thomas David Baker Date: Mon, 7 Oct 2024 20:22:26 -0700 Subject: [PATCH] Defend against an essentially impossible type issue --- gatherling/Data/DB.php | 3 +++ phpstan-baseline.neon | 5 ----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/gatherling/Data/DB.php b/gatherling/Data/DB.php index 966c10a5..7a96a0e0 100644 --- a/gatherling/Data/DB.php +++ b/gatherling/Data/DB.php @@ -240,6 +240,9 @@ private static function _execute(string $sql, array $params, callable $operation private static function safeName(string $name): string { $safeName = preg_replace('/[^a-zA-Z0-9_]/', '_', $name); + if ($safeName === null) { + throw new DatabaseException("Failed to safely name $name"); + } $safeName = trim($safeName, '_'); if (empty($safeName) || is_numeric($safeName[0])) { $safeName = 'sp_'.$safeName; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 016a6595..c056b1da 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -70,11 +70,6 @@ parameters: count: 1 path: gatherling/Data/DB.php - - - message: "#^Parameter \\#1 \\$string of function trim expects string, string\\|null given\\.$#" - count: 1 - path: gatherling/Data/DB.php - - message: "#^Parameter \\#2 \\$params of static method Gatherling\\\\Data\\\\DB\\:\\:_execute\\(\\) expects array\\, mixed given\\.$#" count: 1