3
3
namespace PHPStan \Type \Doctrine \Query ;
4
4
5
5
use Composer \InstalledVersions ;
6
+ use Composer \Semver \VersionParser ;
6
7
use DateTime ;
7
8
use DateTimeImmutable ;
8
9
use Doctrine \Common \Collections \ArrayCollection ;
9
- use Doctrine \DBAL \Platforms \SqlitePlatform ;
10
10
use Doctrine \ORM \EntityManagerInterface ;
11
11
use Doctrine \ORM \Mapping \Column ;
12
12
use Doctrine \ORM \Query \AST \TypedExpression ;
49
49
use function count ;
50
50
use function property_exists ;
51
51
use function sprintf ;
52
- use function strpos ;
53
52
use function version_compare ;
54
53
use const PHP_VERSION_ID ;
55
54
@@ -188,7 +187,7 @@ public function setUp(): void
188
187
}
189
188
190
189
/** @dataProvider getTestData */
191
- public function test (Type $ expectedType , string $ dql , ?string $ expectedExceptionMessage = null ): void
190
+ public function test (Type $ expectedType , string $ dql , ?string $ expectedExceptionMessage = null , ? string $ expectedDeprecationMessage = null ): void
192
191
{
193
192
$ em = self ::$ em ;
194
193
@@ -199,6 +198,9 @@ public function test(Type $expectedType, string $dql, ?string $expectedException
199
198
if ($ expectedExceptionMessage !== null ) {
200
199
$ this ->expectException (Throwable::class);
201
200
$ this ->expectExceptionMessage ($ expectedExceptionMessage );
201
+ } elseif ($ expectedDeprecationMessage !== null ) {
202
+ $ this ->expectDeprecation ();
203
+ $ this ->expectDeprecationMessage ($ expectedDeprecationMessage );
202
204
}
203
205
204
206
QueryResultTypeWalker::walk ($ query , $ typeBuilder , $ this ->descriptorRegistry );
@@ -1233,6 +1235,12 @@ public function getTestData(): iterable
1233
1235
SQRT(1)
1234
1236
FROM QueryResult\Entities\Many m
1235
1237
' ,
1238
+ InstalledVersions::satisfies (new VersionParser (), 'doctrine/dbal ' , '<3 ' ) && PHP_VERSION_ID >= 80100
1239
+ ? 'sqrt(): Passing null to parameter #1 ($num) of type float is deprecated '
1240
+ : null ,
1241
+ InstalledVersions::satisfies (new VersionParser (), 'doctrine/dbal ' , '>=3 ' ) && PHP_VERSION_ID >= 80100
1242
+ ? 'sqrt(): Passing null to parameter #1 ($num) of type float is deprecated '
1243
+ : null ,
1236
1244
];
1237
1245
1238
1246
yield 'length function ' => [
@@ -1280,6 +1288,18 @@ public function getTestData(): iterable
1280
1288
LOCATE( \'f \', \'foo \', 0)
1281
1289
FROM QueryResult\Entities\Many m
1282
1290
' ,
1291
+ null ,
1292
+ InstalledVersions::satisfies (new VersionParser (), 'doctrine/dbal ' , '>=3.4 ' )
1293
+ ? null
1294
+ : (
1295
+ PHP_VERSION_ID >= 80100
1296
+ ? 'strpos(): Passing null to parameter #2 ($needle) of type string is deprecated '
1297
+ : (
1298
+ PHP_VERSION_ID >= 70300 && PHP_VERSION_ID < 80000
1299
+ ? 'strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior '
1300
+ : null
1301
+ )
1302
+ ),
1283
1303
];
1284
1304
1285
1305
yield 'lower function ' => [
@@ -1312,8 +1332,6 @@ public function getTestData(): iterable
1312
1332
' ,
1313
1333
];
1314
1334
1315
- // There is no error after the merge of https://github.com/doctrine/dbal/pull/5755
1316
- $ moduloError = strpos ((new SqlitePlatform ())->getModExpression ('' , '' ), '% ' ) === false ;
1317
1335
yield 'mod function error ' => [
1318
1336
$ this ->constantArray ([
1319
1337
[new ConstantIntegerType (1 ), TypeCombinator::addNull ($ this ->uintStringified ())],
@@ -1322,7 +1340,9 @@ public function getTestData(): iterable
1322
1340
SELECT MOD(10, NULLIF(m.intColumn, m.intColumn))
1323
1341
FROM QueryResult\Entities\Many m
1324
1342
' ,
1325
- $ moduloError ? 'Modulo by zero ' : null ,
1343
+ InstalledVersions::satisfies (new VersionParser (), 'doctrine/dbal ' , '<3.5 ' )
1344
+ ? 'Modulo by zero '
1345
+ : null ,
1326
1346
];
1327
1347
1328
1348
yield 'substring function ' => [
0 commit comments