Skip to content

Commit db068df

Browse files
authored
Merge pull request #5856 from MidnightDesign/json-type-return-type
Use narrower return types for convertTo*Value methods
2 parents 4fee1df + c709e35 commit db068df

21 files changed

+185
-2
lines changed

src/Platforms/AbstractPlatform.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3499,9 +3499,11 @@ public function convertBooleans($item)
34993499
*
35003500
* The default conversion tries to convert value into bool "(bool)$item"
35013501
*
3502-
* @param mixed $item
3502+
* @param T $item
35033503
*
3504-
* @return bool|null
3504+
* @return (T is null ? null : bool)
3505+
*
3506+
* @template T
35053507
*/
35063508
public function convertFromBoolean($item)
35073509
{

src/Platforms/PostgreSQLPlatform.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,12 @@ static function ($value): ?int {
957957

958958
/**
959959
* {@inheritDoc}
960+
*
961+
* @param T $item
962+
*
963+
* @return (T is null ? null : bool)
964+
*
965+
* @template T
960966
*/
961967
public function convertFromBoolean($item)
962968
{

src/Types/BigIntType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public function getBindingType()
3636

3737
/**
3838
* {@inheritdoc}
39+
*
40+
* @param T $value
41+
*
42+
* @return (T is null ? null : string)
43+
*
44+
* @template T
3945
*/
4046
public function convertToPHPValue($value, AbstractPlatform $platform)
4147
{

src/Types/BooleanType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
3030

3131
/**
3232
* {@inheritdoc}
33+
*
34+
* @param T $value
35+
*
36+
* @return (T is null ? null : bool)
37+
*
38+
* @template T
3339
*/
3440
public function convertToPHPValue($value, AbstractPlatform $platform)
3541
{

src/Types/DateImmutableType.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ public function getName()
2121

2222
/**
2323
* {@inheritdoc}
24+
*
25+
* @param T $value
26+
*
27+
* @return (T is null ? null : string)
28+
*
29+
* @template T
2430
*/
2531
public function convertToDatabaseValue($value, AbstractPlatform $platform)
2632
{
@@ -41,6 +47,12 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
4147

4248
/**
4349
* {@inheritdoc}
50+
*
51+
* @param T $value
52+
*
53+
* @return (T is null ? null : DateTimeImmutable)
54+
*
55+
* @template T
4456
*/
4557
public function convertToPHPValue($value, AbstractPlatform $platform)
4658
{

src/Types/DateIntervalType.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform)
3636

3737
/**
3838
* {@inheritdoc}
39+
*
40+
* @param T $value
41+
*
42+
* @return (T is null ? null : string)
43+
*
44+
* @template T
3945
*/
4046
public function convertToDatabaseValue($value, AbstractPlatform $platform)
4147
{
@@ -52,6 +58,12 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
5258

5359
/**
5460
* {@inheritdoc}
61+
*
62+
* @param T $value
63+
*
64+
* @return (T is null ? null : DateInterval)
65+
*
66+
* @template T
5567
*/
5668
public function convertToPHPValue($value, AbstractPlatform $platform)
5769
{

src/Types/DateTimeImmutableType.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ public function getName()
2323

2424
/**
2525
* {@inheritdoc}
26+
*
27+
* @param T $value
28+
*
29+
* @return (T is null ? null : string)
30+
*
31+
* @template T
2632
*/
2733
public function convertToDatabaseValue($value, AbstractPlatform $platform)
2834
{
@@ -43,6 +49,12 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
4349

4450
/**
4551
* {@inheritdoc}
52+
*
53+
* @param T $value
54+
*
55+
* @return (T is null ? null : DateTimeImmutable)
56+
*
57+
* @template T
4658
*/
4759
public function convertToPHPValue($value, AbstractPlatform $platform)
4860
{

src/Types/DateTimeType.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform)
3131

3232
/**
3333
* {@inheritdoc}
34+
*
35+
* @param T $value
36+
*
37+
* @return (T is null ? null : string)
38+
*
39+
* @template T
3440
*/
3541
public function convertToDatabaseValue($value, AbstractPlatform $platform)
3642
{
@@ -47,6 +53,12 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
4753

4854
/**
4955
* {@inheritdoc}
56+
*
57+
* @param T $value
58+
*
59+
* @return (T is null ? null : DateTimeInterface)
60+
*
61+
* @template T
5062
*/
5163
public function convertToPHPValue($value, AbstractPlatform $platform)
5264
{

src/Types/DateTimeTzImmutableType.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ public function getName()
2121

2222
/**
2323
* {@inheritdoc}
24+
*
25+
* @psalm-param T $value
26+
*
27+
* @return (T is null ? null : string)
28+
*
29+
* @template T
2430
*/
2531
public function convertToDatabaseValue($value, AbstractPlatform $platform)
2632
{
@@ -41,6 +47,12 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
4147

4248
/**
4349
* {@inheritdoc}
50+
*
51+
* @param T $value
52+
*
53+
* @return (T is null ? null : DateTimeImmutable)
54+
*
55+
* @template T
4456
*/
4557
public function convertToPHPValue($value, AbstractPlatform $platform)
4658
{

src/Types/DateTimeTzType.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform)
4242

4343
/**
4444
* {@inheritdoc}
45+
*
46+
* @param T $value
47+
*
48+
* @return (T is null ? null : string)
49+
*
50+
* @template T
4551
*/
4652
public function convertToDatabaseValue($value, AbstractPlatform $platform)
4753
{
@@ -62,6 +68,12 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
6268

6369
/**
6470
* {@inheritdoc}
71+
*
72+
* @param T $value
73+
*
74+
* @return (T is null ? null : DateTimeInterface)
75+
*
76+
* @template T
6577
*/
6678
public function convertToPHPValue($value, AbstractPlatform $platform)
6779
{

src/Types/DateType.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform)
2929

3030
/**
3131
* {@inheritdoc}
32+
*
33+
* @psalm-param T $value
34+
*
35+
* @return (T is null ? null : string)
36+
*
37+
* @template T
3238
*/
3339
public function convertToDatabaseValue($value, AbstractPlatform $platform)
3440
{
@@ -45,6 +51,12 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
4551

4652
/**
4753
* {@inheritdoc}
54+
*
55+
* @param T $value
56+
*
57+
* @return (T is null ? null : DateTimeInterface)
58+
*
59+
* @template T
4860
*/
4961
public function convertToPHPValue($value, AbstractPlatform $platform)
5062
{

src/Types/FloatType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform)
2424

2525
/**
2626
* {@inheritdoc}
27+
*
28+
* @param T $value
29+
*
30+
* @return (T is null ? null : float)
31+
*
32+
* @template T
2733
*/
2834
public function convertToPHPValue($value, AbstractPlatform $platform)
2935
{

src/Types/IntegerType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform)
2828

2929
/**
3030
* {@inheritdoc}
31+
*
32+
* @param T $value
33+
*
34+
* @return (T is null ? null : int)
35+
*
36+
* @template T
3137
*/
3238
public function convertToPHPValue($value, AbstractPlatform $platform)
3339
{

src/Types/JsonType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform)
2929

3030
/**
3131
* {@inheritdoc}
32+
*
33+
* @param T $value
34+
*
35+
* @return (T is null ? null : string)
36+
*
37+
* @template T
3238
*/
3339
public function convertToDatabaseValue($value, AbstractPlatform $platform)
3440
{

src/Types/ObjectType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform)
2929

3030
/**
3131
* {@inheritdoc}
32+
*
33+
* @param mixed $value
34+
*
35+
* @return string
3236
*/
3337
public function convertToDatabaseValue($value, AbstractPlatform $platform)
3438
{

src/Types/SimpleArrayType.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform)
2929

3030
/**
3131
* {@inheritdoc}
32+
*
33+
* @param mixed $value
34+
*
35+
* @return string|null
3236
*/
3337
public function convertToDatabaseValue($value, AbstractPlatform $platform)
3438
{
@@ -41,6 +45,10 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
4145

4246
/**
4347
* {@inheritdoc}
48+
*
49+
* @param mixed $value
50+
*
51+
* @return list<string>
4452
*/
4553
public function convertToPHPValue($value, AbstractPlatform $platform)
4654
{

src/Types/SmallIntType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform)
2828

2929
/**
3030
* {@inheritdoc}
31+
*
32+
* @param T $value
33+
*
34+
* @return (T is null ? null : int)
35+
*
36+
* @template T
3137
*/
3238
public function convertToPHPValue($value, AbstractPlatform $platform)
3339
{

src/Types/TimeImmutableType.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ public function getName()
2121

2222
/**
2323
* {@inheritdoc}
24+
*
25+
* @param T $value
26+
*
27+
* @return (T is null ? null : string)
28+
*
29+
* @template T
2430
*/
2531
public function convertToDatabaseValue($value, AbstractPlatform $platform)
2632
{
@@ -41,6 +47,12 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
4147

4248
/**
4349
* {@inheritdoc}
50+
*
51+
* @param T $value
52+
*
53+
* @return (T is null ? null : DateTimeImmutable)
54+
*
55+
* @template T
4456
*/
4557
public function convertToPHPValue($value, AbstractPlatform $platform)
4658
{

src/Types/TimeType.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform)
2929

3030
/**
3131
* {@inheritdoc}
32+
*
33+
* @param T $value
34+
*
35+
* @return (T is null ? null : string)
36+
*
37+
* @template T
3238
*/
3339
public function convertToDatabaseValue($value, AbstractPlatform $platform)
3440
{
@@ -45,6 +51,12 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
4551

4652
/**
4753
* {@inheritdoc}
54+
*
55+
* @param T $value
56+
*
57+
* @return (T is null ? null : DateTimeInterface)
58+
*
59+
* @template T
4860
*/
4961
public function convertToPHPValue($value, AbstractPlatform $platform)
5062
{

src/Types/VarDateTimeImmutableType.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ public function getName()
2323

2424
/**
2525
* {@inheritdoc}
26+
*
27+
* @param T $value
28+
*
29+
* @return (T is null ? null : string)
30+
*
31+
* @template T
2632
*/
2733
public function convertToDatabaseValue($value, AbstractPlatform $platform)
2834
{
@@ -43,6 +49,12 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
4349

4450
/**
4551
* {@inheritdoc}
52+
*
53+
* @param T $value
54+
*
55+
* @return (T is null ? null : DateTimeImmutable)
56+
*
57+
* @template T
4658
*/
4759
public function convertToPHPValue($value, AbstractPlatform $platform)
4860
{

0 commit comments

Comments
 (0)