Skip to content

Commit 3d434ee

Browse files
author
Bohan Yang
committed
Fix deprecations
1 parent aee7580 commit 3d434ee

8 files changed

+34
-17
lines changed

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
],
1111
"require": {
1212
"chubbyphp/chubbyphp-workerman-request-handler": "^2.0",
13-
"doctrine/dbal": "^3.5.1|^4.0",
13+
"doctrine/dbal": "^4.0",
1414
"doctrine/doctrine-bundle": "^2.7",
1515
"doctrine/doctrine-migrations-bundle": "^3.2",
1616
"doctrine/migrations": "^3.2",
@@ -62,6 +62,7 @@
6262
}
6363
},
6464
"require-dev": {
65+
"doctrine/coding-standard": "^12.0",
6566
"lcobucci/jwt": "^4.0|^5.0",
6667
"moneyphp/money": "^4.1",
6768
"monolog/monolog": "^3.0",
@@ -70,8 +71,7 @@
7071
"symfony/process": "^6.4|^7.0",
7172
"symfony/validator": "^6.4|^7.0",
7273
"symfony/yaml": "^6.4|^7.0",
73-
"twig/twig": "^3.0",
74-
"doctrine/coding-standard": "^12.0"
74+
"twig/twig": "^3.0"
7575
},
7676
"replace": {
7777
"manyou/aria2": "self.version",

packages/mango/Doctrine/Query.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,10 @@ public function getQueryResult(): Result
467467
public function queryWithWriteLock(): self
468468
{
469469
$this->result = $this->connection->executeQuery(
470-
$this->getSQL() . ' ' . $this->connection->getDatabasePlatform()->getWriteLockSQL(),
470+
// TODO: Find replacement for the deprecation:
471+
// The methods `AbstractPlatform::getReadLockSQL()`, `::getWriteLockSQL()` and `::getForUpdateSQL()` have been removed
472+
// Use `QueryBuilder::forUpdate()` as a replacement for the latter.
473+
$this->getSQL() . ' FOR UPDATE',
471474
$this->getParameters(),
472475
$this->getParameterTypes(),
473476
);
@@ -480,6 +483,7 @@ public function returning(?string ...$selects): self
480483
$select = $this->schema->createQuery()
481484
->from($this->selectTableMap[$this->fromAlias]->getName(), $this->fromAlias)
482485
->select(...$selects);
486+
483487
$selectSql = $select->getSQL();
484488

485489
// strlen('SELECT ') === 7

packages/mango/Doctrine/Type/AbstractUidType.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
use Symfony\Component\Uid\AbstractUid;
1515

1616
use function bin2hex;
17+
use function get_debug_type;
1718
use function is_resource;
1819
use function is_string;
20+
use function sprintf;
1921
use function stream_get_contents;
2022

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

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

5254
try {
5355
return $this->getUidClass()::fromString($value);
5456
} catch (InvalidArgumentException $e) {
55-
throw ConversionException::conversionFailed($value, static::class, $e);
57+
throw new ConversionException($e->getMessage(), $e->getCode(), $e);
5658
}
5759
}
5860

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

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

9799
public function requiresSQLCommentHint(AbstractPlatform $platform): bool

packages/mango/Doctrine/Type/AbstractUsDateTimeType.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
use Doctrine\DBAL\Types\ConversionException;
1515
use Doctrine\DBAL\Types\Type;
1616

17+
use function get_debug_type;
1718
use function is_a;
19+
use function sprintf;
1820

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

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

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

4648
private function getFormat(AbstractPlatform $platform): string
4749
{
4850
return match (true) {
4951
$platform instanceof AbstractMySQLPlatform => 'Y-m-d H:i:s.u',
5052
$platform instanceof PostgreSQLPlatform => 'Y-m-d H:i:s.u',
51-
default => throw Exception::notSupported(__METHOD__),
53+
default => throw new Exception('Platform not supported'),
5254
};
5355
}
5456

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

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

7981
return $val;

packages/mango/Doctrine/Type/BackedEnumType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): int|
4747
try {
4848
return $this->doConvertToDatabaseValue($value, $platform);
4949
} catch (ConversionException $e) {
50-
throw ConversionException::conversionFailedInvalidType($value, $this::class, ['null', $className], $e);
50+
throw new ConversionException(sprintf('Failed to convert value to %s: %s', $className, $e->getMessage()), $e->getCode(), $e);
5151
}
5252
}
5353

packages/mango/Doctrine/Type/PgTextArrayType.php

+12-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
use Doctrine\DBAL\Types\Type;
1010
use JsonException;
1111

12+
use function is_resource;
13+
use function json_decode;
14+
use function json_encode;
15+
use function sprintf;
16+
use function stream_get_contents;
17+
18+
use const JSON_PRESERVE_ZERO_FRACTION;
19+
use const JSON_THROW_ON_ERROR;
20+
1221
class PgTextArrayType extends Type
1322
{
1423
public const NAME = 'pg_text_array';
@@ -18,7 +27,7 @@ public function getName(): string
1827
return self::NAME;
1928
}
2029

21-
public function getSQLDeclaration(array $column, AbstractPlatform $platform)
30+
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
2231
{
2332
return 'text[]';
2433
}
@@ -51,7 +60,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
5160
try {
5261
return json_encode($value, JSON_THROW_ON_ERROR | JSON_PRESERVE_ZERO_FRACTION);
5362
} catch (JsonException $e) {
54-
throw ConversionException::conversionFailedSerialization($value, 'json', $e->getMessage(), $e);
63+
throw new ConversionException($e->getMessage(), $e->getCode(), $e);
5564
}
5665
}
5766

@@ -71,7 +80,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
7180
try {
7281
return json_decode($value, true, 512, JSON_THROW_ON_ERROR);
7382
} catch (JsonException $e) {
74-
throw ConversionException::conversionFailed($value, $this->getName(), $e);
83+
throw new ConversionException($e->getMessage(), $e->getCode(), $e);
7584
}
7685
}
7786
}

packages/mango/Doctrine/Type/TinyIntType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st
3030
};
3131
}
3232

33-
public function getBindingType(): int
33+
public function getBindingType(): ParameterType
3434
{
3535
return ParameterType::INTEGER;
3636
}

packages/mango/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"require": {
66
"php": ">=8.1",
77
"ext-intl": "*",
8-
"doctrine/dbal": "^3.5.1|^4.0",
8+
"doctrine/dbal": "^4.0",
99
"doctrine/doctrine-bundle": "^2.7",
1010
"doctrine/doctrine-migrations-bundle": "^3.2",
1111
"doctrine/migrations": "^3.2",

0 commit comments

Comments
 (0)