Skip to content

Commit 818da3e

Browse files
Update PDOStatement stub (#5132)
Co-authored-by: phpstan-bot <79867460+phpstan-bot@users.noreply.github.com>
1 parent 1bf2ad3 commit 818da3e

File tree

6 files changed

+68
-4
lines changed

6 files changed

+68
-4
lines changed

stubs/PDOStatement.stub

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

33
/**
4-
* @implements Traversable<array<int|string, mixed>>
5-
* @implements IteratorAggregate<array<int|string, mixed>>
4+
* @implements Traversable<mixed>
5+
* @implements IteratorAggregate<mixed>
66
* @link https://php.net/manual/en/class.pdostatement.php
77
*/
88
class PDOStatement implements Traversable, IteratorAggregate
@@ -21,7 +21,7 @@ class PDOStatement implements Traversable, IteratorAggregate
2121
public function getColumnMeta(int $column) {}
2222

2323
/**
24-
* @return Iterator<mixed, array<int|string, mixed>>
24+
* @return Iterator<mixed, mixed>
2525
*/
2626
public function getIterator() {}
2727
}

tests/PHPStan/Analyser/nsrt/bug-8886.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ function testPDOStatementGetIterator(): void {
99
$pdo = new PDO('sqlite::memory:');
1010
$stmt = $pdo->query('SELECT 1');
1111

12-
assertType('Iterator<mixed, array<int|string, mixed>>', $stmt->getIterator());
12+
assertType('Iterator<mixed, mixed>', $stmt->getIterator());
1313
}

tests/PHPStan/Rules/PhpDoc/InvalidPhpDocVarTagTypeRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ public function testBug6348(): void
170170
$this->analyse([__DIR__ . '/data/bug-6348.php'], []);
171171
}
172172

173+
public function testBug14206(): void
174+
{
175+
$this->analyse([__DIR__ . '/data/bug-14206.php'], []);
176+
}
177+
173178
public function testBug9055(): void
174179
{
175180
$this->analyse([__DIR__ . '/data/bug-9055.php'], [
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug14206;
4+
5+
use PDO;
6+
use PDOStatement;
7+
8+
class Test
9+
{
10+
public function test(PDO $db): void
11+
{
12+
/** @var PDOStatement<int,string> */
13+
$statement = $db->prepare('SELECT foo FROM bar');
14+
$statement->setFetchMode(PDO::FETCH_COLUMN, 0);
15+
$statement->execute();
16+
}
17+
18+
public function test2(PDO $db): void
19+
{
20+
/** @var PDOStatement<int,array<string>> */
21+
$statement = $db->prepare('SELECT foo FROM bar');
22+
$statement->execute();
23+
}
24+
25+
public function test3(PDO $db): void
26+
{
27+
/** @var PDOStatement<int,object> */
28+
$statement = $db->prepare('SELECT foo FROM bar');
29+
$statement->setFetchMode(PDO::FETCH_OBJ, 0);
30+
$statement->execute();
31+
}
32+
}

tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,14 @@ public function testBug11289(): void
11831183
$this->analyse([__DIR__ . '/data/bug-11289.php'], []);
11841184
}
11851185

1186+
public function testBug9120(): void
1187+
{
1188+
$this->checkThisOnly = false;
1189+
$this->checkUnionTypes = true;
1190+
$this->checkDynamicProperties = false;
1191+
$this->analyse([__DIR__ . '/data/bug-9120.php'], []);
1192+
}
1193+
11861194
public function testBug8668(): void
11871195
{
11881196
$this->checkThisOnly = false;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug9120;
4+
5+
function do_something(): void
6+
{
7+
$db = new \PDO('connection-string');
8+
9+
$statement = $db->query('sql-query');
10+
if ($statement !== false)
11+
{
12+
$statement->setFetchMode(\PDO::FETCH_OBJ);
13+
14+
foreach ($statement as $tmpObject)
15+
{
16+
echo $tmpObject->mycolumn;
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)