Skip to content

Commit 6439355

Browse files
committed
WIP
1 parent f6a34b3 commit 6439355

33 files changed

+425
-55
lines changed

src/Type/Doctrine/DescriptorRegistry.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public function __construct(array $descriptors)
2121
}
2222
}
2323

24+
/**
25+
* @throws DescriptorNotRegisteredException
26+
*/
2427
public function get(string $type): DoctrineTypeDescriptor
2528
{
2629
$typesMap = Type::getTypesMap();
@@ -36,4 +39,12 @@ public function get(string $type): DoctrineTypeDescriptor
3639
return $this->descriptors[$typeClass];
3740
}
3841

42+
public function getByClassName(string $className): DoctrineTypeDescriptor
43+
{
44+
if (!isset($this->descriptors[$className])) {
45+
throw new DescriptorNotRegisteredException();
46+
}
47+
return $this->descriptors[$className];
48+
}
49+
3950
}

src/Type/Doctrine/Descriptors/ArrayType.php

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

33
namespace PHPStan\Type\Doctrine\Descriptors;
44

5+
use Doctrine\DBAL\Driver;
56
use PHPStan\Type\MixedType;
67
use PHPStan\Type\StringType;
78
use PHPStan\Type\Type;
@@ -24,7 +25,7 @@ public function getWritableToDatabaseType(): Type
2425
return new \PHPStan\Type\ArrayType(new MixedType(), new MixedType());
2526
}
2627

27-
public function getDatabaseInternalType(): Type
28+
public function getDatabaseInternalType(Driver $driver): Type
2829
{
2930
return new StringType();
3031
}

src/Type/Doctrine/Descriptors/AsciiStringType.php

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

33
namespace PHPStan\Type\Doctrine\Descriptors;
44

5+
use Doctrine\DBAL\Driver;
56
use PHPStan\Type\StringType;
67
use PHPStan\Type\Type;
78

@@ -23,7 +24,7 @@ public function getWritableToDatabaseType(): Type
2324
return new StringType();
2425
}
2526

26-
public function getDatabaseInternalType(): Type
27+
public function getDatabaseInternalType(Driver $driver): Type
2728
{
2829
return new StringType();
2930
}

src/Type/Doctrine/Descriptors/BigIntType.php

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

33
namespace PHPStan\Type\Doctrine\Descriptors;
44

5+
use Doctrine\DBAL\Driver;
56
use PHPStan\Type\Accessory\AccessoryNumericStringType;
67
use PHPStan\Type\IntegerType;
78
use PHPStan\Type\StringType;
@@ -23,10 +24,10 @@ public function getWritableToPropertyType(): Type
2324

2425
public function getWritableToDatabaseType(): Type
2526
{
26-
return TypeCombinator::union(new StringType(), new IntegerType());
27+
return TypeCombinator::union(new StringType());
2728
}
2829

29-
public function getDatabaseInternalType(): Type
30+
public function getDatabaseInternalType(Driver $driver): Type
3031
{
3132
return new IntegerType();
3233
}

src/Type/Doctrine/Descriptors/BinaryType.php

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

33
namespace PHPStan\Type\Doctrine\Descriptors;
44

5+
use Doctrine\DBAL\Driver;
56
use PHPStan\Type\MixedType;
67
use PHPStan\Type\ResourceType;
78
use PHPStan\Type\StringType;
@@ -25,7 +26,7 @@ public function getWritableToDatabaseType(): Type
2526
return new MixedType();
2627
}
2728

28-
public function getDatabaseInternalType(): Type
29+
public function getDatabaseInternalType(Driver $driver): Type
2930
{
3031
return new StringType();
3132
}

src/Type/Doctrine/Descriptors/BlobType.php

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

33
namespace PHPStan\Type\Doctrine\Descriptors;
44

5+
use Doctrine\DBAL\Driver;
56
use PHPStan\Type\MixedType;
67
use PHPStan\Type\ResourceType;
78
use PHPStan\Type\Type;
@@ -24,7 +25,7 @@ public function getWritableToDatabaseType(): Type
2425
return new MixedType();
2526
}
2627

27-
public function getDatabaseInternalType(): Type
28+
public function getDatabaseInternalType(Driver $driver): Type
2829
{
2930
return new MixedType();
3031
}

src/Type/Doctrine/Descriptors/BooleanType.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace PHPStan\Type\Doctrine\Descriptors;
44

5+
use Doctrine\DBAL\Driver;
6+
use Doctrine\DBAL\Driver\PDO\PgSQL\Driver as PdoPgSQLDriver;
7+
use Doctrine\DBAL\Driver\PgSQL\Driver as PgSQLDriver;
58
use PHPStan\Type\Constant\ConstantIntegerType;
69
use PHPStan\Type\Type;
710
use PHPStan\Type\TypeCombinator;
@@ -24,8 +27,12 @@ public function getWritableToDatabaseType(): Type
2427
return new \PHPStan\Type\BooleanType();
2528
}
2629

27-
public function getDatabaseInternalType(): Type
30+
public function getDatabaseInternalType(Driver $driver): Type
2831
{
32+
if ($driver instanceof PgSQLDriver || $driver instanceof PdoPgSQLDriver) {
33+
return new \PHPStan\Type\BooleanType();
34+
}
35+
2936
return TypeCombinator::union(
3037
new ConstantIntegerType(0),
3138
new ConstantIntegerType(1)

src/Type/Doctrine/Descriptors/DateImmutableType.php

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

55
use DateTimeImmutable;
6+
use Doctrine\DBAL\Driver;
67
use PHPStan\Type\ObjectType;
78
use PHPStan\Type\StringType;
89
use PHPStan\Type\Type;
@@ -25,7 +26,7 @@ public function getWritableToDatabaseType(): Type
2526
return new ObjectType(DateTimeImmutable::class);
2627
}
2728

28-
public function getDatabaseInternalType(): Type
29+
public function getDatabaseInternalType(Driver $driver): Type
2930
{
3031
return new StringType();
3132
}

src/Type/Doctrine/Descriptors/DateIntervalType.php

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

55
use DateInterval;
6+
use Doctrine\DBAL\Driver;
67
use PHPStan\Type\ObjectType;
78
use PHPStan\Type\StringType;
89
use PHPStan\Type\Type;
@@ -25,7 +26,7 @@ public function getWritableToDatabaseType(): Type
2526
return new ObjectType(DateInterval::class);
2627
}
2728

28-
public function getDatabaseInternalType(): Type
29+
public function getDatabaseInternalType(Driver $driver): Type
2930
{
3031
return new StringType();
3132
}

src/Type/Doctrine/Descriptors/DateTimeImmutableType.php

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

55
use DateTimeImmutable;
6+
use Doctrine\DBAL\Driver;
67
use PHPStan\Type\ObjectType;
78
use PHPStan\Type\StringType;
89
use PHPStan\Type\Type;
@@ -25,7 +26,7 @@ public function getWritableToDatabaseType(): Type
2526
return new ObjectType(DateTimeImmutable::class);
2627
}
2728

28-
public function getDatabaseInternalType(): Type
29+
public function getDatabaseInternalType(Driver $driver): Type
2930
{
3031
return new StringType();
3132
}

0 commit comments

Comments
 (0)