Skip to content

Commit

Permalink
Use "numeric-string" type for some MySQLi functions
Browse files Browse the repository at this point in the history
  • Loading branch information
phansys committed Feb 6, 2023
1 parent b58d93e commit 2bf7cc5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stubs/mysqli.stub
Expand Up @@ -4,7 +4,7 @@ class mysqli_stmt
{

/**
* @var int|string
* @var int<-1,max>|numeric-string
*/
public $affected_rows;

Expand Down Expand Up @@ -34,7 +34,7 @@ class mysqli_stmt
public $insert_id;

/**
* @var 0|positive-int
* @var int<0,max>|numeric-string
*/
public $num_rows;

Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Expand Up @@ -1198,6 +1198,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8775.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8752.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/trait-instance-of.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/mysql-stmt.php');
}

/**
Expand Down
20 changes: 20 additions & 0 deletions tests/PHPStan/Analyser/data/mysql-stmt.php
@@ -0,0 +1,20 @@
<?php

namespace MySQLiStmt;

use mysqli;
use function PHPStan\Testing\assertType;

class Foo {
public function bar()
{
$mysqli = new mysqli();
$stmt = $mysqli->prepare('SELECT x FROM z;');
$stmt->execute();
assertType('int<0,max>|numeric-string', $stmt->num_rows);

$stmt = $mysqli->prepare('DELETE FROM z;');
$stmt->execute();
assertType('int<-1,max>|numeric-string', $stmt->affected_rows);
}
}

0 comments on commit 2bf7cc5

Please sign in to comment.