Skip to content

Commit

Permalink
Fix deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
Bohan Yang committed Mar 22, 2024
1 parent aee7580 commit 3d434ee
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 17 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"require": {
"chubbyphp/chubbyphp-workerman-request-handler": "^2.0",
"doctrine/dbal": "^3.5.1|^4.0",
"doctrine/dbal": "^4.0",
"doctrine/doctrine-bundle": "^2.7",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/migrations": "^3.2",
Expand Down Expand Up @@ -62,6 +62,7 @@
}
},
"require-dev": {
"doctrine/coding-standard": "^12.0",
"lcobucci/jwt": "^4.0|^5.0",
"moneyphp/money": "^4.1",
"monolog/monolog": "^3.0",
Expand All @@ -70,8 +71,7 @@
"symfony/process": "^6.4|^7.0",
"symfony/validator": "^6.4|^7.0",
"symfony/yaml": "^6.4|^7.0",
"twig/twig": "^3.0",
"doctrine/coding-standard": "^12.0"
"twig/twig": "^3.0"
},
"replace": {
"manyou/aria2": "self.version",
Expand Down
6 changes: 5 additions & 1 deletion packages/mango/Doctrine/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,10 @@ public function getQueryResult(): Result
public function queryWithWriteLock(): self
{
$this->result = $this->connection->executeQuery(
$this->getSQL() . ' ' . $this->connection->getDatabasePlatform()->getWriteLockSQL(),
// TODO: Find replacement for the deprecation:
// The methods `AbstractPlatform::getReadLockSQL()`, `::getWriteLockSQL()` and `::getForUpdateSQL()` have been removed
// Use `QueryBuilder::forUpdate()` as a replacement for the latter.
$this->getSQL() . ' FOR UPDATE',
$this->getParameters(),
$this->getParameterTypes(),
);
Expand All @@ -480,6 +483,7 @@ public function returning(?string ...$selects): self
$select = $this->schema->createQuery()
->from($this->selectTableMap[$this->fromAlias]->getName(), $this->fromAlias)
->select(...$selects);

$selectSql = $select->getSQL();

// strlen('SELECT ') === 7
Expand Down
8 changes: 5 additions & 3 deletions packages/mango/Doctrine/Type/AbstractUidType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
use Symfony\Component\Uid\AbstractUid;

use function bin2hex;
use function get_debug_type;
use function is_resource;
use function is_string;
use function sprintf;
use function stream_get_contents;

abstract class AbstractUidType extends Type
Expand Down Expand Up @@ -46,13 +48,13 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Ab
}

if (! is_string($value)) {
throw ConversionException::conversionFailedInvalidType($value, static::class, ['null', 'string', $this->getUidClass()]);
throw new ConversionException(sprintf('Expected %s, got %s', $this->getUidClass(), get_debug_type($value)));
}

try {
return $this->getUidClass()::fromString($value);
} catch (InvalidArgumentException $e) {
throw ConversionException::conversionFailed($value, static::class, $e);
throw new ConversionException($e->getMessage(), $e->getCode(), $e);
}
}

Expand Down Expand Up @@ -91,7 +93,7 @@ private function convertToAbstractUid($value): ?AbstractUid
return $this->getUidClass()::fromString($value);
}

throw ConversionException::conversionFailedInvalidType($value, static::class, ['null', 'string', $this->getUidClass()]);
throw new ConversionException(sprintf('Expected %s, got %s', $this->getUidClass(), get_debug_type($value)));
}

public function requiresSQLCommentHint(AbstractPlatform $platform): bool
Expand Down
10 changes: 6 additions & 4 deletions packages/mango/Doctrine/Type/AbstractUsDateTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Type;

use function get_debug_type;
use function is_a;
use function sprintf;

abstract class AbstractUsDateTimeType extends Type
{
Expand All @@ -23,7 +25,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st
return match (true) {
$platform instanceof AbstractMySQLPlatform => 'DATETIME(6)',
$platform instanceof PostgreSQLPlatform => 'timestamp',
default => throw Exception::notSupported(__METHOD__),
default => throw new Exception('Platform not supported'),
};
}

Expand All @@ -40,15 +42,15 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): mixe
return $value->format($this->getFormat($platform));
}

throw ConversionException::conversionFailedInvalidType($value, static::class, ['null', DateTimeInterface::class]);
throw new ConversionException(sprintf('Expected %s, got %s', DateTimeInterface::class, get_debug_type($value)));
}

private function getFormat(AbstractPlatform $platform): string
{
return match (true) {
$platform instanceof AbstractMySQLPlatform => 'Y-m-d H:i:s.u',
$platform instanceof PostgreSQLPlatform => 'Y-m-d H:i:s.u',
default => throw Exception::notSupported(__METHOD__),
default => throw new Exception('Platform not supported'),
};
}

Expand All @@ -73,7 +75,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform): mixed
}

if ($val === false) {
throw ConversionException::conversionFailedFormat($value, static::class, $format);
throw new ConversionException('Failed to convert value to ' . $this->getClassName());
}

return $val;
Expand Down
2 changes: 1 addition & 1 deletion packages/mango/Doctrine/Type/BackedEnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): int|
try {
return $this->doConvertToDatabaseValue($value, $platform);
} catch (ConversionException $e) {
throw ConversionException::conversionFailedInvalidType($value, $this::class, ['null', $className], $e);
throw new ConversionException(sprintf('Failed to convert value to %s: %s', $className, $e->getMessage()), $e->getCode(), $e);
}
}

Expand Down
15 changes: 12 additions & 3 deletions packages/mango/Doctrine/Type/PgTextArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
use Doctrine\DBAL\Types\Type;
use JsonException;

use function is_resource;
use function json_decode;
use function json_encode;
use function sprintf;
use function stream_get_contents;

use const JSON_PRESERVE_ZERO_FRACTION;
use const JSON_THROW_ON_ERROR;

class PgTextArrayType extends Type
{
public const NAME = 'pg_text_array';
Expand All @@ -18,7 +27,7 @@ public function getName(): string
return self::NAME;
}

public function getSQLDeclaration(array $column, AbstractPlatform $platform)
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return 'text[]';
}
Expand Down Expand Up @@ -51,7 +60,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
try {
return json_encode($value, JSON_THROW_ON_ERROR | JSON_PRESERVE_ZERO_FRACTION);
} catch (JsonException $e) {
throw ConversionException::conversionFailedSerialization($value, 'json', $e->getMessage(), $e);
throw new ConversionException($e->getMessage(), $e->getCode(), $e);
}
}

Expand All @@ -71,7 +80,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
try {
return json_decode($value, true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
throw ConversionException::conversionFailed($value, $this->getName(), $e);
throw new ConversionException($e->getMessage(), $e->getCode(), $e);
}
}
}
2 changes: 1 addition & 1 deletion packages/mango/Doctrine/Type/TinyIntType.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st
};
}

public function getBindingType(): int
public function getBindingType(): ParameterType
{
return ParameterType::INTEGER;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/mango/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"require": {
"php": ">=8.1",
"ext-intl": "*",
"doctrine/dbal": "^3.5.1|^4.0",
"doctrine/dbal": "^4.0",
"doctrine/doctrine-bundle": "^2.7",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/migrations": "^3.2",
Expand Down

0 comments on commit 3d434ee

Please sign in to comment.