Skip to content

Commit

Permalink
Merge branch 'dependabot/composer/phpstan/phpstan-1.12.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Oct 11, 2024
2 parents c184c90 + 1bd5c40 commit 4b3074c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion src/Drivers/Mysqli/MysqliResultAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
6 changes: 5 additions & 1 deletion src/Drivers/Mysqli/MysqliResultNormalizerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/Drivers/PdoMysql/PdoMysqlResultNormalizerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4b3074c

Please sign in to comment.