Skip to content

Commit

Permalink
Merge pull request #5905 from phansys/pr_5879
Browse files Browse the repository at this point in the history
Use "numeric-string" return type for methods that return integers as strings
  • Loading branch information
derrabus authored Feb 8, 2023
2 parents a759917 + a7dbdeb commit 5921ac0
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 4 deletions.
16 changes: 16 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ parameters:
- '~^Parameter #1 \$row of method Doctrine\\DBAL\\Driver\\PgSQL\\Result\:\:mapAssociativeRow\(\) expects array<string, string\|null>, array<int\|string, string\|null> given\.$~'
- '~^Parameter #1 \$row of method Doctrine\\DBAL\\Driver\\PgSQL\\Result\:\:mapNumericRow\(\) expects array<int, string\|null>, array<int\|string, string\|null> given\.$~'

# https://github.com/phpstan/phpstan-src/pull/2224
-
message: '~^Method Doctrine\\DBAL\\Driver\\Mysqli\\Connection\:\:exec\(\) should return int\|numeric\-string but returns int\|string\.$~'
count: 1
path: src/Driver/Mysqli/Connection.php

-
message: '~^Method Doctrine\\DBAL\\Driver\\Mysqli\\Result\:\:rowCount\(\) should return int\|numeric\-string but returns int\<0, max\>\|string\.$~'
count: 1
path: src/Driver/Mysqli/Result.php

-
message: '~^Method Doctrine\\DBAL\\Driver\\Mysqli\\Result\:\:rowCount\(\) should return int\|numeric\-string but returns int\|string\.$~'
count: 1
path: src/Driver/Mysqli/Result.php

includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
Expand Down
12 changes: 9 additions & 3 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ private function addCriteriaCondition(
* @param array<string, mixed> $criteria
* @param array<int, string|ParameterType|Type>|array<string, string|ParameterType|Type> $types
*
* @return int|string The number of affected rows.
* @return int|numeric-string The number of affected rows.
*
* @throws Exception
*/
Expand Down Expand Up @@ -445,7 +445,7 @@ public function getTransactionIsolation(): TransactionIsolationLevel
* @param array<string, mixed> $criteria
* @param array<int, string|ParameterType|Type>|array<string, string|ParameterType|Type> $types
*
* @return int|string The number of affected rows.
* @return int|numeric-string The number of affected rows.
*
* @throws Exception
*/
Expand Down Expand Up @@ -482,7 +482,7 @@ public function update(string $table, array $data, array $criteria = [], array $
* @param array<string, mixed> $data
* @param array<int, string|ParameterType|Type>|array<string, string|ParameterType|Type> $types
*
* @return int|string The number of affected rows.
* @return int|numeric-string The number of affected rows.
*
* @throws Exception
*/
Expand Down Expand Up @@ -839,6 +839,8 @@ public function executeCacheQuery(string $sql, array $params, array $types, Quer
* @param list<mixed>|array<string, mixed> $params
* @psalm-param WrapperParameterTypeArray $types
*
* @return int|numeric-string
*
* @throws Exception
*/
public function executeStatement(string $sql, array $params = [], array $types = []): int|string
Expand Down Expand Up @@ -1369,6 +1371,8 @@ private function handleDriverException(
* @param array<int, mixed>|array<string, mixed> $params
* @psalm-param WrapperParameterTypeArray $types
*
* @return int|numeric-string
*
* @throws Exception
*/
public function executeUpdate(string $sql, array $params = [], array $types = []): int|string
Expand All @@ -1390,6 +1394,8 @@ public function query(string $sql): Result
* BC layer for a wide-spread use-case of old DBAL APIs
*
* @deprecated This API is deprecated and will be removed after 2022
*
* @return int|numeric-string
*/
public function exec(string $sql): int|string
{
Expand Down
2 changes: 2 additions & 0 deletions src/Driver/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public function quote(string $value): string;
* If the number of affected rows is greater than the maximum int value (PHP_INT_MAX),
* the number of affected rows may be returned as a string.
*
* @return int|numeric-string
*
* @throws Exception
*/
public function exec(string $sql): int|string;
Expand Down
2 changes: 2 additions & 0 deletions src/Driver/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public function fetchFirstColumn(): array;
*
* If the number of rows exceeds {@see PHP_INT_MAX}, it might be returned as string if the driver supports it.
*
* @return int|numeric-string
*
* @throws Exception
*/
public function rowCount(): int|string;
Expand Down
2 changes: 1 addition & 1 deletion src/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public function executeQuery(): Result
*
* Should be used for INSERT, UPDATE and DELETE
*
* @return int|string The number of affected rows.
* @return int|numeric-string The number of affected rows.
*
* @throws Exception
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ public function iterateColumn(): Traversable
*
* If the number of rows exceeds {@see PHP_INT_MAX}, it might be returned as string if the driver supports it.
*
* @return int|numeric-string
*
* @throws Exception
*/
public function rowCount(): int|string
Expand Down
2 changes: 2 additions & 0 deletions src/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public function executeQuery(): Result
*
* If the number of rows exceeds {@see PHP_INT_MAX}, it might be returned as string if the driver supports it.
*
* @return int|numeric-string
*
* @throws Exception
*/
public function executeStatement(): int|string
Expand Down

0 comments on commit 5921ac0

Please sign in to comment.