Skip to content

Commit 9fc8536

Browse files
staabmclxmstaab
andauthored
support phpstan 1.4.x (#121)
Co-authored-by: Markus Staab <[email protected]>
1 parent 82c72cc commit 9fc8536

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

composer.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"require": {
66
"php": "^8.0",
77
"ext-mysqli": "*",
8-
"phpstan/phpstan": "1.3.*"
8+
"phpstan/phpstan": "^1.2"
99
},
1010
"require-dev": {
1111
"ext-pdo": "*",
@@ -17,6 +17,9 @@
1717
"phpunit/phpunit": "^9",
1818
"symplify/phpstan-extensions": "^10.0"
1919
},
20+
"conflicts": {
21+
"phpstan/phpstan": "1.4.0"
22+
},
2023
"autoload": {
2124
"psr-4": {
2225
"staabm\\PHPStanDba\\": "src/"
@@ -32,9 +35,10 @@
3235
"csfix": [
3336
"php-cs-fixer fix"
3437
],
35-
"phpstan-dba-baseline": [
36-
"phpunit",
37-
"phpstan analyse -c phpstan.neon.dist"
38+
"test": [
39+
"@phpunit",
40+
"@phpstan",
41+
"@csfix"
3842
],
3943
"phpstan": [
4044
"phpstan analyse -c phpstan.neon.dist"

src/QueryReflection/MysqliQueryReflector.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,18 @@ public function __construct(mysqli $mysqli)
6161

6262
$constants = get_defined_constants(true);
6363
foreach ($constants['mysqli'] as $c => $n) {
64+
if (!\is_int($n)) {
65+
throw new ShouldNotHappenException();
66+
}
6467
if (preg_match('/^MYSQLI_TYPE_(.*)/', $c, $m)) {
68+
if (!\is_string($m[1])) {
69+
throw new ShouldNotHappenException();
70+
}
6571
$this->nativeTypes[$n] = $m[1];
6672
} elseif (preg_match('/MYSQLI_(.*)_FLAG$/', $c, $m)) {
73+
if (!\is_string($m[1])) {
74+
throw new ShouldNotHappenException();
75+
}
6776
if (!\array_key_exists($n, $this->nativeFlags)) {
6877
$this->nativeFlags[$n] = $m[1];
6978
}

tests/data/pdo-prepare.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Foo
1010
public function prepareSelected(PDO $pdo)
1111
{
1212
$stmt = $pdo->prepare('SELECT email, adaid FROM ada');
13+
assertType('PDOStatement<array{email: string, 0: string, adaid: int<0, 4294967295>, 1: int<0, 4294967295>}>', $stmt);
1314
$stmt->execute();
1415
assertType('PDOStatement<array{email: string, 0: string, adaid: int<0, 4294967295>, 1: int<0, 4294967295>}>', $stmt);
1516

0 commit comments

Comments
 (0)