Skip to content

Commit

Permalink
fixes for PHP 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Nov 1, 2020
1 parent f076e0a commit 2db8dc1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ parameters:
Nextras\Dbal\Drivers\Sqlsrv\SqlsrvDriver:
- throwErrors

reportUnmatchedIgnoredErrors: false

ignoreErrors:
-
message: '~Call to an undefined method .+::children\(\)\.~'
Expand Down
7 changes: 4 additions & 3 deletions src/Drivers/Mysqli/MysqliDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ public function connect(array $params, ILogger $logger): void
throw $this->createException(
$this->connection->connect_error ?? $this->connection->error, // @phpstan-ignore-line
$this->connection->connect_errno,
// @phpstan-ignore-next-line - Property access is not allowed yet
@$this->connection->sqlstate ?: 'HY000'
'HY000'
);
}

Expand Down Expand Up @@ -376,8 +375,10 @@ public function convertIdentifierToSql(string $value): string

public function convertDateTimeToSql(DateTimeInterface $value): string
{
$valueTimezone = $value->getTimezone();
assert($value instanceof DateTime || $value instanceof DateTimeImmutable);
if ($value->getTimezone()->getName() !== $this->connectionTz->getName()) {
assert($valueTimezone !== false); // @phpstan-ignore-line
if ($valueTimezone->getName() !== $this->connectionTz->getName()) {
if ($value instanceof DateTimeImmutable) {
$value = $value->setTimezone($this->connectionTz);
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/Drivers/Pgsql/PgsqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function getResourceHandle()
public function query(string $query): Result
{
assert($this->connection !== null);
if (!pg_send_query($this->connection, $query)) {
if (pg_send_query($this->connection, $query) === false) {
throw $this->createException(pg_last_error($this->connection), 0, null);
}

Expand Down Expand Up @@ -344,8 +344,10 @@ public function convertIdentifierToSql(string $value): string

public function convertDateTimeToSql(DateTimeInterface $value): string
{
$valueTimezone = $value->getTimezone();
assert($value instanceof DateTime || $value instanceof DateTimeImmutable);
if ($value->getTimezone()->getName() !== $this->connectionTz->getName()) {
assert($valueTimezone !== false); // @phpstan-ignore-line
if ($valueTimezone->getName() !== $this->connectionTz->getName()) {
if ($value instanceof DateTimeImmutable) {
$value = $value->setTimezone($this->connectionTz);
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/Utils/DateTimeImmutable.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public function setTimestamp($timestamp): self
{
$zone = $this->getTimezone();
$datetime = new static('@' . (string) $timestamp);
if ($zone === false) { // @phpstan-ignore-line
return $datetime;
}
return $datetime->setTimezone($zone);
}
}

0 comments on commit 2db8dc1

Please sign in to comment.