From 05bf3ca25bd2d8d55511ba1aa31655dad192c120 Mon Sep 17 00:00:00 2001 From: Simon Mundy Date: Sat, 3 Oct 2026 21:46:35 +1000 Subject: [PATCH] Cast scalar values to string before quoting them PlatformInterface::quoteValue() takes a string, so an integer limit, offset or column value raised a TypeError under strict types once a platform with a driver tried to quote it. The test platform now keeps the string type, so the suite catches the same mistake again. Signed-off-by: Simon Mundy --- analyzer-baseline.toml | 12 ------------ src/Sql/AbstractSql.php | 2 +- src/Sql/Select.php | 4 ++-- test/unit/TestAsset/TrustingSql92Platform.php | 2 +- 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/analyzer-baseline.toml b/analyzer-baseline.toml index 6a0f82f4..efbee666 100644 --- a/analyzer-baseline.toml +++ b/analyzer-baseline.toml @@ -1908,12 +1908,6 @@ code = "mixed-argument" message = 'Invalid argument type for argument #1 of `PhpDb\Adapter\Platform\PlatformInterface::quoteIdentifier`: expected `string`, but found `mixed`.' count = 1 -[[issues]] -file = "src/Sql/AbstractSql.php" -code = "mixed-argument" -message = 'Invalid argument type for argument #1 of `PhpDb\Adapter\Platform\PlatformInterface::quoteValue`: expected `string`, but found `nonnull`.' -count = 1 - [[issues]] file = "src/Sql/AbstractSql.php" code = "mixed-argument" @@ -4470,12 +4464,6 @@ code = "possibly-false-iterator" message = 'Expression being iterated (type `array|false|list`) might be `false` at runtime.' count = 1 -[[issues]] -file = "src/Sql/Select.php" -code = "possibly-invalid-argument" -message = 'Possible argument type mismatch for argument #1 of `PhpDb\Adapter\Platform\PlatformInterface::quoteValue`: expected `string`, but possibly received `int|string`.' -count = 2 - [[issues]] file = "src/Sql/Select.php" code = "possibly-invalid-argument" diff --git a/src/Sql/AbstractSql.php b/src/Sql/AbstractSql.php index b5e818d8..671ee1a9 100644 --- a/src/Sql/AbstractSql.php +++ b/src/Sql/AbstractSql.php @@ -442,7 +442,7 @@ protected function resolveColumnValue( return $isIdentifier ? $fromTable . $platform->quoteIdentifierInFragment($column) - : $platform->quoteValue($column); + : $platform->quoteValue((string) $column); } protected function resolveTable( diff --git a/src/Sql/Select.php b/src/Sql/Select.php index 9aa88fe3..a1b65d64 100644 --- a/src/Sql/Select.php +++ b/src/Sql/Select.php @@ -519,7 +519,7 @@ protected function processLimit( return [$driver->formatParameterName("{$paramPrefix}limit")]; } - return [$platform->quoteValue($this->limit)]; + return [$platform->quoteValue((string) $this->limit)]; } protected function processOffset( @@ -537,7 +537,7 @@ protected function processOffset( return [$driver->formatParameterName("{$paramPrefix}offset")]; } - return [$platform->quoteValue($this->offset)]; + return [$platform->quoteValue((string) $this->offset)]; } protected function processOrder( diff --git a/test/unit/TestAsset/TrustingSql92Platform.php b/test/unit/TestAsset/TrustingSql92Platform.php index 81b82d6f..28e99fcd 100644 --- a/test/unit/TestAsset/TrustingSql92Platform.php +++ b/test/unit/TestAsset/TrustingSql92Platform.php @@ -13,7 +13,7 @@ final class TrustingSql92Platform extends Sql92 * {@inheritDoc} */ #[Override] - public function quoteValue($value): string + public function quoteValue(string $value): string { return $this->quoteTrustedValue($value); }