From 8a912f2061ef01edc0b0ab7c2f4682a0d786f0d4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:11:09 +0000 Subject: [PATCH 1/2] build(deps-dev): update phpstan/phpstan requirement Updates the requirements on [phpstan/phpstan](https://github.com/phpstan/phpstan) to permit the latest version. - [Release notes](https://github.com/phpstan/phpstan/releases) - [Changelog](https://github.com/phpstan/phpstan/blob/2.0.x/CHANGELOG.md) - [Commits](https://github.com/phpstan/phpstan/compare/1.10.66...1.12.6) --- updated-dependencies: - dependency-name: phpstan/phpstan dependency-type: direct:development ... Signed-off-by: dependabot[bot] --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ec1f858..31af6b9 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "nette/neon": "~3.0", "nextras/multi-query-parser": "1.0.0", "phpstan/extension-installer": "1.4.3", - "phpstan/phpstan": "1.10.66", + "phpstan/phpstan": "1.12.6", "phpstan/phpstan-deprecation-rules": "1.1.4", "phpstan/phpstan-strict-rules": "1.5.2", "symfony/config": "~4.4 || ~5.0", From 1bd5c401acdb1a836a6619a851e3ae7ce040a912 Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Fri, 11 Oct 2024 22:47:14 +0200 Subject: [PATCH 2/2] add exception safeguards for failure states --- src/Drivers/Mysqli/MysqliResultAdapter.php | 4 +++- src/Drivers/Mysqli/MysqliResultNormalizerFactory.php | 6 +++++- src/Drivers/PdoMysql/PdoMysqlResultNormalizerFactory.php | 6 +++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Drivers/Mysqli/MysqliResultAdapter.php b/src/Drivers/Mysqli/MysqliResultAdapter.php index 24037b1..b50df9e 100644 --- a/src/Drivers/Mysqli/MysqliResultAdapter.php +++ b/src/Drivers/Mysqli/MysqliResultAdapter.php @@ -57,7 +57,9 @@ public function seek(int $index): void public function fetch(): ?array { - return $this->result->fetch_assoc(); + $fetched = $this->result->fetch_assoc(); + if ($fetched === false) throw new InvalidStateException(); + return $fetched; } diff --git a/src/Drivers/Mysqli/MysqliResultNormalizerFactory.php b/src/Drivers/Mysqli/MysqliResultNormalizerFactory.php index b5df9ff..1de9f19 100644 --- a/src/Drivers/Mysqli/MysqliResultNormalizerFactory.php +++ b/src/Drivers/Mysqli/MysqliResultNormalizerFactory.php @@ -6,6 +6,7 @@ use Closure; use DateInterval; use DateTimeZone; +use Nextras\Dbal\Exception\InvalidArgumentException; use Nextras\Dbal\Utils\DateTimeImmutable; use Nextras\Dbal\Utils\StrictObjectTrait; use function date_default_timezone_get; @@ -42,7 +43,10 @@ public function __construct(MysqliDriver $driver) $this->timeNormalizer = static function($value): ?DateInterval { if ($value === null) return null; - preg_match('#^(-?)(\d+):(\d+):(\d+)#', $value, $m); + $matched = preg_match('#^(-?)(\d+):(\d+):(\d+)#', $value, $m); + if ($matched !== 1) { + throw new InvalidArgumentException("Unsupported value format for TIME column: $value. Unable to parse to DateInterval"); + } $value = new DateInterval("PT{$m[2]}H{$m[3]}M{$m[4]}S"); $value->invert = $m[1] === '-' ? 1 : 0; return $value; diff --git a/src/Drivers/PdoMysql/PdoMysqlResultNormalizerFactory.php b/src/Drivers/PdoMysql/PdoMysqlResultNormalizerFactory.php index b4a20d5..8e81c24 100644 --- a/src/Drivers/PdoMysql/PdoMysqlResultNormalizerFactory.php +++ b/src/Drivers/PdoMysql/PdoMysqlResultNormalizerFactory.php @@ -6,6 +6,7 @@ use Closure; use DateInterval; use DateTimeZone; +use Nextras\Dbal\Exception\InvalidArgumentException; use Nextras\Dbal\Utils\DateTimeImmutable; use Nextras\Dbal\Utils\StrictObjectTrait; use function date_default_timezone_get; @@ -43,7 +44,10 @@ public function __construct(PdoMysqlDriver $driver) $this->timeNormalizer = static function ($value): ?DateInterval { if ($value === null) return null; - preg_match('#^(-?)(\d+):(\d+):(\d+)#', $value, $m); + $matched = preg_match('#^(-?)(\d+):(\d+):(\d+)#', $value, $m); + if ($matched !== 1) { + throw new InvalidArgumentException("Unsupported value format for TIME column: $value. Unable to parse to DateInterval"); + } $value = new DateInterval("PT{$m[2]}H{$m[3]}M{$m[4]}S"); $value->invert = $m[1] === '-' ? 1 : 0; return $value;