diff --git a/composer.json b/composer.json index 90f9819..ad9cff5 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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", @@ -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", diff --git a/packages/mango/Doctrine/Query.php b/packages/mango/Doctrine/Query.php index 9009a74..74762f1 100644 --- a/packages/mango/Doctrine/Query.php +++ b/packages/mango/Doctrine/Query.php @@ -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(), ); @@ -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 diff --git a/packages/mango/Doctrine/Type/AbstractUidType.php b/packages/mango/Doctrine/Type/AbstractUidType.php index aa27ddf..9f15de7 100644 --- a/packages/mango/Doctrine/Type/AbstractUidType.php +++ b/packages/mango/Doctrine/Type/AbstractUidType.php @@ -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 @@ -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); } } @@ -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 diff --git a/packages/mango/Doctrine/Type/AbstractUsDateTimeType.php b/packages/mango/Doctrine/Type/AbstractUsDateTimeType.php index b69203c..7d6968b 100644 --- a/packages/mango/Doctrine/Type/AbstractUsDateTimeType.php +++ b/packages/mango/Doctrine/Type/AbstractUsDateTimeType.php @@ -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 { @@ -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'), }; } @@ -40,7 +42,7 @@ 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 @@ -48,7 +50,7 @@ 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'), }; } @@ -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; diff --git a/packages/mango/Doctrine/Type/BackedEnumType.php b/packages/mango/Doctrine/Type/BackedEnumType.php index c5b26ed..85c1781 100644 --- a/packages/mango/Doctrine/Type/BackedEnumType.php +++ b/packages/mango/Doctrine/Type/BackedEnumType.php @@ -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); } } diff --git a/packages/mango/Doctrine/Type/PgTextArrayType.php b/packages/mango/Doctrine/Type/PgTextArrayType.php index d545e27..ae00451 100644 --- a/packages/mango/Doctrine/Type/PgTextArrayType.php +++ b/packages/mango/Doctrine/Type/PgTextArrayType.php @@ -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'; @@ -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[]'; } @@ -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); } } @@ -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); } } } diff --git a/packages/mango/Doctrine/Type/TinyIntType.php b/packages/mango/Doctrine/Type/TinyIntType.php index aeaa29e..62fab5f 100644 --- a/packages/mango/Doctrine/Type/TinyIntType.php +++ b/packages/mango/Doctrine/Type/TinyIntType.php @@ -30,7 +30,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st }; } - public function getBindingType(): int + public function getBindingType(): ParameterType { return ParameterType::INTEGER; } diff --git a/packages/mango/composer.json b/packages/mango/composer.json index 6df0171..a9d4ffe 100644 --- a/packages/mango/composer.json +++ b/packages/mango/composer.json @@ -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",