Skip to content

Commit 45d37c1

Browse files
committed
DoctrineTypeDriverAwareDescriptor: remove interface BC break
1 parent bc29246 commit 45d37c1

32 files changed

+167
-88
lines changed

src/Type/Doctrine/Descriptors/ArrayType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PHPStan\Type\Doctrine\Descriptors;
44

5-
use Doctrine\DBAL\Driver;
65
use PHPStan\Type\MixedType;
76
use PHPStan\Type\StringType;
87
use PHPStan\Type\Type;
@@ -25,7 +24,7 @@ public function getWritableToDatabaseType(): Type
2524
return new \PHPStan\Type\ArrayType(new MixedType(), new MixedType());
2625
}
2726

28-
public function getDatabaseInternalType(Driver $driver): Type
27+
public function getDatabaseInternalType(): Type
2928
{
3029
return new StringType();
3130
}

src/Type/Doctrine/Descriptors/AsciiStringType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PHPStan\Type\Doctrine\Descriptors;
44

5-
use Doctrine\DBAL\Driver;
65
use PHPStan\Type\StringType;
76
use PHPStan\Type\Type;
87

@@ -24,7 +23,7 @@ public function getWritableToDatabaseType(): Type
2423
return new StringType();
2524
}
2625

27-
public function getDatabaseInternalType(Driver $driver): Type
26+
public function getDatabaseInternalType(): Type
2827
{
2928
return new StringType();
3029
}

src/Type/Doctrine/Descriptors/BigIntType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace PHPStan\Type\Doctrine\Descriptors;
44

55
use Composer\InstalledVersions;
6-
use Doctrine\DBAL\Driver;
76
use PHPStan\Type\Accessory\AccessoryNumericStringType;
87
use PHPStan\Type\IntegerType;
98
use PHPStan\Type\StringType;
@@ -34,7 +33,7 @@ public function getWritableToDatabaseType(): Type
3433
return TypeCombinator::union(new StringType(), new IntegerType());
3534
}
3635

37-
public function getDatabaseInternalType(Driver $driver): Type
36+
public function getDatabaseInternalType(): Type
3837
{
3938
return new IntegerType();
4039
}

src/Type/Doctrine/Descriptors/BinaryType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PHPStan\Type\Doctrine\Descriptors;
44

5-
use Doctrine\DBAL\Driver;
65
use PHPStan\Type\MixedType;
76
use PHPStan\Type\ResourceType;
87
use PHPStan\Type\StringType;
@@ -26,7 +25,7 @@ public function getWritableToDatabaseType(): Type
2625
return new MixedType();
2726
}
2827

29-
public function getDatabaseInternalType(Driver $driver): Type
28+
public function getDatabaseInternalType(): Type
3029
{
3130
return new StringType();
3231
}

src/Type/Doctrine/Descriptors/BlobType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PHPStan\Type\Doctrine\Descriptors;
44

5-
use Doctrine\DBAL\Driver;
65
use PHPStan\Type\MixedType;
76
use PHPStan\Type\ResourceType;
87
use PHPStan\Type\Type;
@@ -25,7 +24,7 @@ public function getWritableToDatabaseType(): Type
2524
return new MixedType();
2625
}
2726

28-
public function getDatabaseInternalType(Driver $driver): Type
27+
public function getDatabaseInternalType(): Type
2928
{
3029
return new MixedType();
3130
}

src/Type/Doctrine/Descriptors/BooleanType.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
namespace PHPStan\Type\Doctrine\Descriptors;
44

55
use Doctrine\DBAL\Driver;
6+
use Doctrine\DBAL\Driver\Mysqli\Driver as MysqliDriver;
7+
use Doctrine\DBAL\Driver\PDO\MySQL\Driver as PdoMysqlDriver;
68
use Doctrine\DBAL\Driver\PDO\PgSQL\Driver as PdoPgSQLDriver;
9+
use Doctrine\DBAL\Driver\PDO\SQLite\Driver as PdoSQLiteDriver;
710
use Doctrine\DBAL\Driver\PgSQL\Driver as PgSQLDriver;
11+
use Doctrine\DBAL\Driver\SQLite3\Driver as SQLite3Driver;
812
use PHPStan\Type\Constant\ConstantIntegerType;
913
use PHPStan\Type\Type;
1014
use PHPStan\Type\TypeCombinator;
1115

12-
class BooleanType implements DoctrineTypeDescriptor
16+
class BooleanType implements DoctrineTypeDescriptor, DoctrineTypeDriverAwareDescriptor
1317
{
1418

1519
public function getType(): string
@@ -27,16 +31,35 @@ public function getWritableToDatabaseType(): Type
2731
return new \PHPStan\Type\BooleanType();
2832
}
2933

30-
public function getDatabaseInternalType(Driver $driver): Type
34+
public function getDatabaseInternalType(): Type
35+
{
36+
return TypeCombinator::union(
37+
new ConstantIntegerType(0),
38+
new ConstantIntegerType(1),
39+
new \PHPStan\Type\BooleanType()
40+
);
41+
}
42+
43+
public function getDatabaseInternalTypeForDriver(Driver $driver): Type
3144
{
3245
if ($driver instanceof PgSQLDriver || $driver instanceof PdoPgSQLDriver) {
3346
return new \PHPStan\Type\BooleanType();
3447
}
3548

36-
return TypeCombinator::union(
37-
new ConstantIntegerType(0),
38-
new ConstantIntegerType(1)
39-
);
49+
if (
50+
$driver instanceof SQLite3Driver
51+
|| $driver instanceof PdoSQLiteDriver
52+
|| $driver instanceof MysqliDriver
53+
|| $driver instanceof PdoMysqlDriver
54+
) {
55+
return TypeCombinator::union(
56+
new ConstantIntegerType(0),
57+
new ConstantIntegerType(1)
58+
);
59+
}
60+
61+
// not yet supported driver, return the old implementation guess
62+
return $this->getDatabaseInternalType();
4063
}
4164

4265
}

src/Type/Doctrine/Descriptors/DateImmutableType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace PHPStan\Type\Doctrine\Descriptors;
44

55
use DateTimeImmutable;
6-
use Doctrine\DBAL\Driver;
76
use PHPStan\Type\ObjectType;
87
use PHPStan\Type\StringType;
98
use PHPStan\Type\Type;
@@ -26,7 +25,7 @@ public function getWritableToDatabaseType(): Type
2625
return new ObjectType(DateTimeImmutable::class);
2726
}
2827

29-
public function getDatabaseInternalType(Driver $driver): Type
28+
public function getDatabaseInternalType(): Type
3029
{
3130
return new StringType();
3231
}

src/Type/Doctrine/Descriptors/DateIntervalType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace PHPStan\Type\Doctrine\Descriptors;
44

55
use DateInterval;
6-
use Doctrine\DBAL\Driver;
76
use PHPStan\Type\ObjectType;
87
use PHPStan\Type\StringType;
98
use PHPStan\Type\Type;
@@ -26,7 +25,7 @@ public function getWritableToDatabaseType(): Type
2625
return new ObjectType(DateInterval::class);
2726
}
2827

29-
public function getDatabaseInternalType(Driver $driver): Type
28+
public function getDatabaseInternalType(): Type
3029
{
3130
return new StringType();
3231
}

src/Type/Doctrine/Descriptors/DateTimeImmutableType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace PHPStan\Type\Doctrine\Descriptors;
44

55
use DateTimeImmutable;
6-
use Doctrine\DBAL\Driver;
76
use PHPStan\Type\ObjectType;
87
use PHPStan\Type\StringType;
98
use PHPStan\Type\Type;
@@ -26,7 +25,7 @@ public function getWritableToDatabaseType(): Type
2625
return new ObjectType(DateTimeImmutable::class);
2726
}
2827

29-
public function getDatabaseInternalType(Driver $driver): Type
28+
public function getDatabaseInternalType(): Type
3029
{
3130
return new StringType();
3231
}

src/Type/Doctrine/Descriptors/DateTimeType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use DateTime;
66
use DateTimeInterface;
7-
use Doctrine\DBAL\Driver;
87
use PHPStan\Type\ObjectType;
98
use PHPStan\Type\StringType;
109
use PHPStan\Type\Type;
@@ -27,7 +26,7 @@ public function getWritableToDatabaseType(): Type
2726
return new ObjectType(DateTimeInterface::class);
2827
}
2928

30-
public function getDatabaseInternalType(Driver $driver): Type
29+
public function getDatabaseInternalType(): Type
3130
{
3231
return new StringType();
3332
}

0 commit comments

Comments
 (0)