Skip to content

Commit

Permalink
PHPStan 1.0.0
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander M. Turek <me@derrabus.de>
  • Loading branch information
derrabus committed Nov 1, 2021
1 parent e94864e commit 2dc8ff1
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"require-dev": {
"doctrine/coding-standard": "9.0.0",
"jetbrains/phpstorm-stubs": "2021.1",
"phpstan/phpstan": "0.12.99",
"phpstan/phpstan": "1.0.0",
"phpunit/phpunit": "^7.5.20|^8.5|9.5.10",
"psalm/plugin-phpunit": "0.16.1",
"squizlabs/php_codesniffer": "3.6.1",
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/DBALException.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static function driverExceptionDuringQuery(Driver $driver, Throwable $dri

$msg .= ":\n\n" . $driverEx->getMessage();

return static::wrapException($driver, $driverEx, $msg);
return self::wrapException($driver, $driverEx, $msg);
}

/**
Expand All @@ -166,7 +166,7 @@ public static function driverExceptionDuringQuery(Driver $driver, Throwable $dri
*/
public static function driverException(Driver $driver, Throwable $driverEx)
{
return static::wrapException($driver, $driverEx, 'An exception occurred in driver: ' . $driverEx->getMessage());
return self::wrapException($driver, $driverEx, 'An exception occurred in driver: ' . $driverEx->getMessage());
}

/**
Expand Down
10 changes: 6 additions & 4 deletions lib/Doctrine/DBAL/Driver/PDOConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ public function quote($value, $type = ParameterType::STRING)
public function lastInsertId($name = null)
{
try {
if ($name === null) {
return parent::lastInsertId();
}
$lastInsertId = $name === null
? parent::lastInsertId()
: parent::lastInsertId($name);

return parent::lastInsertId($name);
assert($lastInsertId !== false);

return $lastInsertId;
} catch (PDOException $exception) {
throw Exception::new($exception);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/SQLParserUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ public static function expandListParameters($query, $params, $types)

foreach ($paramPos as $pos => $paramName) {
$paramLen = strlen($paramName) + 1;
$value = static::extractParam($paramName, $params, true);
$value = self::extractParam($paramName, $params, true);

if (! isset($arrayPositions[$paramName]) && ! isset($arrayPositions[':' . $paramName])) {
$pos += $queryOffset;
$queryOffset -= $paramLen - 1;
$paramsOrd[] = $value;
$typesOrd[] = static::extractParam($paramName, $types, false, ParameterType::STRING);
$typesOrd[] = self::extractParam($paramName, $types, false, ParameterType::STRING);
$query = substr($query, 0, $pos) . '?' . substr($query, $pos + $paramLen);

continue;
Expand All @@ -241,7 +241,7 @@ public static function expandListParameters($query, $params, $types)

foreach ($value as $val) {
$paramsOrd[] = $val;
$typesOrd[] = static::extractParam($paramName, $types, false) - Connection::ARRAY_PARAM_OFFSET;
$typesOrd[] = self::extractParam($paramName, $types, false) - Connection::ARRAY_PARAM_OFFSET;
}

$pos += $queryOffset;
Expand Down
22 changes: 18 additions & 4 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,19 @@ parameters:
paths:
- lib/Doctrine/DBAL/Connection.php

# https://github.com/phpstan/phpstan/issues/5608
# PHPStan fails to parse this type alias which is meant for Psalm only.
-
message: '~^Circular definition detected in type alias (Override)?Params\.$~'
message: '~^Invalid type definition detected in type alias (Override)?Params\.$~'
paths:
- lib/Doctrine/DBAL/DriverManager.php

-
message: '~Template type T of method Doctrine\\DBAL\\DriverManager::getConnection\(\) is not referenced in a parameter\.~'
paths:
- lib/Doctrine/DBAL/DriverManager.php

-
message: '~Method Doctrine\\DBAL\\DriverManager::createDriver\(\) should return Doctrine\\DBAL\\Driver but returns object\.~'
paths:
- lib/Doctrine/DBAL/DriverManager.php

Expand All @@ -120,8 +130,12 @@ parameters:
paths:
- lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php

# https://github.com/phpstan/phpstan-src/pull/700
-
message: '~^Parameter #2 \$count of function array_fill expects int<0, max>, int given\.$~'
message: '~Method Doctrine\\DBAL\\Driver\\Mysqli\\MysqliStatement::rowCount\(\) should return int but returns int\|string\.~'
paths:
- lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php

-
message: '~Dead catch - PDOException is never thrown in the try block\.~'
paths:
- lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php
2 changes: 2 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@
-->
<file name="lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php"/>
<file name="tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php"/>
<!-- Psalm and PHPStan disagree over the return type of PDO::lastInsertId(). -->
<file name="lib/Doctrine/DBAL/Driver/PDOConnection.php"/>
</errorLevel>
</RedundantConditionGivenDocblockType>
<ReferenceConstraintViolation>
Expand Down

0 comments on commit 2dc8ff1

Please sign in to comment.