33namespace PHPStan \Type \Doctrine \Descriptors ;
44
55use Doctrine \DBAL \Driver ;
6+ use Doctrine \DBAL \Driver \Mysqli \Driver as MysqliDriver ;
7+ use Doctrine \DBAL \Driver \PDO \MySQL \Driver as PdoMysqlDriver ;
68use Doctrine \DBAL \Driver \PDO \PgSQL \Driver as PdoPgSQLDriver ;
9+ use Doctrine \DBAL \Driver \PDO \SQLite \Driver as PdoSQLiteDriver ;
710use Doctrine \DBAL \Driver \PgSQL \Driver as PgSQLDriver ;
11+ use Doctrine \DBAL \Driver \SQLite3 \Driver as SQLite3Driver ;
812use PHPStan \Type \Constant \ConstantIntegerType ;
913use PHPStan \Type \Type ;
1014use 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}
0 commit comments