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", 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;