Skip to content

Commit 2eaf50b

Browse files
staabmclxmstaab
andauthored
Support \Doctrine\DBAL\Connection->query() syntax error checking (#66)
Co-authored-by: Markus Staab <[email protected]>
1 parent 2e86ed1 commit 2eaf50b

File tree

5 files changed

+16
-86
lines changed

5 files changed

+16
-86
lines changed

.phpstan-dba.cache

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@
213213
'result' =>
214214
array (
215215
1 => NULL,
216-
2 => NULL,
217216
3 => NULL,
218217
),
219218
),
@@ -1076,90 +1075,6 @@
10761075
array (
10771076
),
10781077
)),
1079-
2 =>
1080-
PHPStan\Type\Constant\ConstantArrayType::__set_state(array(
1081-
'keyType' =>
1082-
PHPStan\Type\UnionType::__set_state(array(
1083-
'types' =>
1084-
array (
1085-
0 =>
1086-
PHPStan\Type\Constant\ConstantIntegerType::__set_state(array(
1087-
'value' => 0,
1088-
)),
1089-
1 =>
1090-
PHPStan\Type\Constant\ConstantIntegerType::__set_state(array(
1091-
'value' => 1,
1092-
)),
1093-
2 =>
1094-
PHPStan\Type\Constant\ConstantIntegerType::__set_state(array(
1095-
'value' => 2,
1096-
)),
1097-
3 =>
1098-
PHPStan\Type\Constant\ConstantIntegerType::__set_state(array(
1099-
'value' => 3,
1100-
)),
1101-
),
1102-
)),
1103-
'itemType' =>
1104-
PHPStan\Type\UnionType::__set_state(array(
1105-
'types' =>
1106-
array (
1107-
0 =>
1108-
PHPStan\Type\IntegerRangeType::__set_state(array(
1109-
'min' => -128,
1110-
'max' => 4294967295,
1111-
)),
1112-
1 =>
1113-
PHPStan\Type\StringType::__set_state(array(
1114-
)),
1115-
),
1116-
)),
1117-
'allArrays' => NULL,
1118-
'keyTypes' =>
1119-
array (
1120-
0 =>
1121-
PHPStan\Type\Constant\ConstantIntegerType::__set_state(array(
1122-
'value' => 0,
1123-
)),
1124-
1 =>
1125-
PHPStan\Type\Constant\ConstantIntegerType::__set_state(array(
1126-
'value' => 1,
1127-
)),
1128-
2 =>
1129-
PHPStan\Type\Constant\ConstantIntegerType::__set_state(array(
1130-
'value' => 2,
1131-
)),
1132-
3 =>
1133-
PHPStan\Type\Constant\ConstantIntegerType::__set_state(array(
1134-
'value' => 3,
1135-
)),
1136-
),
1137-
'valueTypes' =>
1138-
array (
1139-
0 =>
1140-
PHPStan\Type\StringType::__set_state(array(
1141-
)),
1142-
1 =>
1143-
PHPStan\Type\IntegerRangeType::__set_state(array(
1144-
'min' => 0,
1145-
'max' => 4294967295,
1146-
)),
1147-
2 =>
1148-
PHPStan\Type\IntegerRangeType::__set_state(array(
1149-
'min' => -128,
1150-
'max' => 127,
1151-
)),
1152-
3 =>
1153-
PHPStan\Type\IntegerRangeType::__set_state(array(
1154-
'min' => -128,
1155-
'max' => 127,
1156-
)),
1157-
),
1158-
'nextAutoIndex' => 4,
1159-
'optionalKeys' =>
1160-
array (
1161-
),
1162-
)),
11631078
),
11641079
),
11651080
'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada LIMIT 1' =>

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"require-dev": {
1111
"ext-pdo": "*",
12+
"doctrine/dbal": "^3.2",
1213
"friendsofphp/php-cs-fixer": "3.4.0",
1314
"phpstan/phpstan-php-parser": "^1.1",
1415
"phpstan/phpstan-phpunit": "^1.0",
@@ -43,7 +44,10 @@
4344
]
4445
},
4546
"config": {
46-
"sort-packages": true
47+
"sort-packages": true,
48+
"allow-plugins": {
49+
"composer/package-versions-deprecated": true
50+
}
4751
},
4852
"extra": {
4953
"phpstan": {

config/dba.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ services:
1515
- 'PDO::query#0'
1616
- 'PDO::prepare#0'
1717
- 'mysqli::query#0'
18+
- 'Doctrine\DBAL\Connection::query#0'
1819

1920
-
2021
class: staabm\PHPStanDba\Rules\SyntaxErrorInQueryFunctionRule

tests/SyntaxErrorInQueryMethodRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public function testSyntaxErrorInQueryRule(): void
5353
"Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (1064).",
5454
67,
5555
],
56+
[
57+
"Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (1064).",
58+
73,
59+
],
5660
]);
5761
}
5862
}

tests/data/syntax-error-in-query.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,10 @@ public function syntaxErrorPdoPrepare(PDO $pdo)
6666
{
6767
$pdo->prepare('SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada');
6868
}
69+
70+
public function syntaxErrorDoctrineDbal(\Doctrine\DBAL\Connection $conn)
71+
{
72+
$sql = 'SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada';
73+
$stmt = $conn->query($sql);
74+
}
6975
}

0 commit comments

Comments
 (0)