Skip to content

Commit

Permalink
Merge branch '3.0.x' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Apr 12, 2020
2 parents 93e8979 + 4c25831 commit 24dbc4e
Show file tree
Hide file tree
Showing 159 changed files with 972 additions and 816 deletions.
8 changes: 8 additions & 0 deletions UPGRADE.md
Expand Up @@ -269,6 +269,10 @@ The Doctrine\DBAL\Version class is no longer available: please refrain from chec

# Upgrade to 3.0

## BC BREAK: Removed `EchoSQLLogger`

`EchoSQLLogger` is no longer available as part of the package.

## BC BREAK: Removed support for SQL Anywhere 12 and older

DBAL now requires SQL Anywhere 16 or newer, support for unmaintained versions has been dropped.
Expand Down Expand Up @@ -395,6 +399,10 @@ Please use other database client applications for import, e.g.:

# Upgrade to 2.11

## Deprecated `EchoSQLLogger`

The `EchoSQLLogger` is has been deprecated. Implement your logger with the desired logic.

## Deprecated database platforms:

1. PostgreSQL 9.3 and older
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -40,8 +40,9 @@
"require-dev": {
"doctrine/coding-standard": "^7.0",
"jetbrains/phpstorm-stubs": "^2019.1",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan": "^0.12.18",
"phpstan/phpstan-phpunit": "^0.12",
"phpstan/phpstan-strict-rules": "^0.12.2",
"phpunit/phpunit": "^9.0",
"symfony/console": "^2.0.5|^3.0|^4.0|^5.0"
},
Expand Down
56 changes: 54 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions phpstan.neon.dist
Expand Up @@ -5,6 +5,7 @@ parameters:
- %currentWorkingDirectory%/tests
autoload_files:
- %currentWorkingDirectory%/tests/phpstan-polyfill.php
treatPhpDocTypesAsCertain: false
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
Expand Down Expand Up @@ -46,6 +47,48 @@ parameters:
message: '~^Cannot cast array<string>\|bool\|string\|null to int\.$~'
path: %currentWorkingDirectory%/src/Tools/Console/Command/RunSqlCommand.php

# https://github.com/phpstan/phpstan/issues/3134
-
message: '~^Call to static method PHPUnit\\Framework\\Assert::assertSame\(\) with Doctrine\\DBAL\\Types\\Type and Doctrine\\DBAL\\Types\\Type will always evaluate to true\.$~'
path: %currentWorkingDirectory%/tests/Types/TypeRegistryTest.php

# https://github.com/phpstan/phpstan-strict-rules/issues/103
-
message: '~^Construct empty\(\) is not allowed. Use more strict comparison\.~'
paths:
- %currentWorkingDirectory%/src/Driver/*/*Connection.php
- %currentWorkingDirectory%/src/Driver/*/Driver.php
- %currentWorkingDirectory%/src/Driver/AbstractOracleDriver/EasyConnectString.php
- %currentWorkingDirectory%/src/Platforms/*Platform.php
- %currentWorkingDirectory%/src/Schema/*SchemaManager.php

# In some namespaces, we use array<string,mixed>, some elements of which are actually boolean
-
message: '~^Only booleans are allowed in .*, mixed given~'
paths:
- %currentWorkingDirectory%/src/Driver/*/Driver.php
- %currentWorkingDirectory%/src/Platforms/*Platform.php
- %currentWorkingDirectory%/src/Schema/*SchemaManager.php

# FetchMode::CUSTOM_OBJECT requires variable property access
-
message: '~^Variable property access on object\.~'
paths:
- %currentWorkingDirectory%/src/Driver/*/*Statement.php

# Some APIs use variable method calls internally
-
message: '~^Variable method call on .*~'
paths:
- %currentWorkingDirectory%/src/Schema/AbstractSchemaManager.php
- %currentWorkingDirectory%/src/Schema/Column.php

# https://github.com/phpstan/phpstan/issues/3146
-
message: '~^Only numeric types are allowed in -, int<1, max>\|false given on the left side\.~'
paths:
- %currentWorkingDirectory%/src/Platforms/SQLServer2012Platform.php

# Temporaily suppressed during up-merging an upgrade PHPStan 0.12
- '~^Unable to resolve the template type ExpectedType in call to method static method PHPUnit\\Framework\\Assert::assertInstanceOf\(\)$~'
- '~^Unable to resolve the template type RealInstanceType in call to method PHPUnit\\Framework\\TestCase::getMockClass\(\)$~'
Expand All @@ -62,3 +105,4 @@ parameters:
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon
4 changes: 2 additions & 2 deletions src/Cache/ArrayStatement.php
Expand Up @@ -37,7 +37,7 @@ final class ArrayStatement implements IteratorAggregate, ResultStatement
public function __construct(array $data)
{
$this->data = $data;
if (! count($data)) {
if (count($data) === 0) {
return;
}

Expand Down Expand Up @@ -91,7 +91,7 @@ public function fetch(?int $fetchMode = null, ...$args)
}

$row = $this->data[$this->num++];
$fetchMode = $fetchMode ?: $this->defaultFetchMode;
$fetchMode = $fetchMode ?? $this->defaultFetchMode;

if ($fetchMode === FetchMode::ASSOCIATIVE) {
return $row;
Expand Down
6 changes: 3 additions & 3 deletions src/Cache/ResultCacheStatement.php
Expand Up @@ -78,7 +78,7 @@ public function closeCursor() : void
}

$data = $this->resultCache->fetch($this->cacheKey);
if (! $data) {
if ($data === false) {
$data = [];
}

Expand Down Expand Up @@ -122,10 +122,10 @@ public function fetch(?int $fetchMode = null, ...$args)

$row = $this->statement->fetch(FetchMode::ASSOCIATIVE);

if ($row) {
if ($row !== false) {
$this->data[] = $row;

$fetchMode = $fetchMode ?: $this->defaultFetchMode;
$fetchMode = $fetchMode ?? $this->defaultFetchMode;

if ($fetchMode === FetchMode::ASSOCIATIVE) {
return $row;
Expand Down
19 changes: 10 additions & 9 deletions src/Connection.php
Expand Up @@ -33,6 +33,7 @@
use Throwable;
use function array_key_exists;
use function assert;
use function count;
use function implode;
use function is_int;
use function is_string;
Expand Down Expand Up @@ -178,11 +179,11 @@ public function __construct(
}

// Create default config and event manager if none given
if (! $config) {
if ($config === null) {
$config = new Configuration();
}

if (! $eventManager) {
if ($eventManager === null) {
$eventManager = new EventManager();
}

Expand Down Expand Up @@ -351,7 +352,7 @@ private function getDatabasePlatformVersion() : ?string
try {
$this->connect();
} catch (Throwable $originalException) {
if (empty($this->params['dbname'])) {
if (! isset($this->params['dbname'])) {
throw $originalException;
}

Expand Down Expand Up @@ -569,7 +570,7 @@ private function addIdentifierCondition(
*/
public function delete(string $table, array $identifier, array $types = []) : int
{
if (empty($identifier)) {
if (count($identifier) === 0) {
throw EmptyCriteriaNotAllowed::new();
}

Expand Down Expand Up @@ -671,7 +672,7 @@ public function update(string $table, array $data, array $identifier, array $typ
*/
public function insert(string $table, array $data, array $types = []) : int
{
if (empty($data)) {
if (count($data) === 0) {
return $this->executeUpdate('INSERT INTO ' . $table . ' () VALUES ()');
}

Expand Down Expand Up @@ -801,11 +802,11 @@ public function executeQuery(
$logger->startQuery($query, $params, $types);

try {
if ($params) {
if (count($params) > 0) {
[$query, $params, $types] = SQLParserUtils::expandListParameters($query, $params, $types);

$stmt = $connection->prepare($query);
if ($types) {
if (count($types) > 0) {
$this->_bindTypedValues($stmt, $params, $types);
$stmt->execute();
} else {
Expand Down Expand Up @@ -909,12 +910,12 @@ public function executeUpdate(string $query, array $params = [], array $types =
$logger->startQuery($query, $params, $types);

try {
if ($params) {
if (count($params) > 0) {
[$query, $params, $types] = SQLParserUtils::expandListParameters($query, $params, $types);

$stmt = $connection->prepare($query);

if ($types) {
if (count($types) > 0) {
$this->_bindTypedValues($stmt, $params, $types);
$stmt->execute();
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Connections/MasterSlaveConnection.php
Expand Up @@ -129,7 +129,7 @@ public function isConnectedToMaster() : bool
public function connect(?string $connectionName = null) : void
{
$requestedConnectionChange = ($connectionName !== null);
$connectionName = $connectionName ?: 'slave';
$connectionName = $connectionName ?? 'slave';

if ($connectionName !== 'slave' && $connectionName !== 'master') {
throw new InvalidArgumentException('Invalid option to connect(), only master or slave allowed.');
Expand Down
8 changes: 4 additions & 4 deletions src/Driver/AbstractMySQLDriver.php
Expand Up @@ -210,11 +210,11 @@ public function createDatabasePlatformForVersion(string $version) : AbstractPlat
*/
private function getOracleMysqlVersionNumber(string $versionString) : string
{
if (! preg_match(
if (preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/',
$versionString,
$versionParts
)) {
) === 0) {
throw InvalidPlatformVersion::new(
$versionString,
'<major_version>.<minor_version>.<patch_version>'
Expand Down Expand Up @@ -242,11 +242,11 @@ private function getOracleMysqlVersionNumber(string $versionString) : string
*/
private function getMariaDbMysqlVersionNumber(string $versionString) : string
{
if (! preg_match(
if (preg_match(
'/^(?:5\.5\.5-)?(mariadb-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/i',
$versionString,
$versionParts
)) {
) === 0) {
throw InvalidPlatformVersion::new(
$versionString,
'^(?:5\.5\.5-)?(mariadb-)?<major_version>.<minor_version>.<patch_version>'
Expand Down
8 changes: 4 additions & 4 deletions src/Driver/AbstractOracleDriver/EasyConnectString.php
Expand Up @@ -45,11 +45,11 @@ public static function fromArray(array $params) : self
*/
public static function fromConnectionParameters(array $params) : self
{
if (! empty($params['connectstring'])) {
if (isset($params['connectstring'])) {
return new self($params['connectstring']);
}

if (empty($params['host'])) {
if (! isset($params['host'])) {
return new self($params['dbname'] ?? '');
}

Expand All @@ -58,7 +58,7 @@ public static function fromConnectionParameters(array $params) : self
if (isset($params['servicename']) || isset($params['dbname'])) {
$serviceKey = 'SID';

if (! empty($params['service'])) {
if (isset($params['service'])) {
$serviceKey = 'SERVICE_NAME';
}

Expand All @@ -67,7 +67,7 @@ public static function fromConnectionParameters(array $params) : self
$connectData[$serviceKey] = $serviceName;
}

if (! empty($params['instancename'])) {
if (isset($params['instancename'])) {
$connectData['INSTANCE_NAME'] = $params['instancename'];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Driver/AbstractPostgreSQLDriver.php
Expand Up @@ -82,7 +82,7 @@ public function convertException(string $message, DriverExceptionInterface $exce

public function createDatabasePlatformForVersion(string $version) : AbstractPlatform
{
if (! preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts)) {
if (preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts) === 0) {
throw InvalidPlatformVersion::new(
$version,
'<major_version>.<minor_version>.<patch_version>'
Expand Down
4 changes: 2 additions & 2 deletions src/Driver/AbstractSQLAnywhereDriver.php
Expand Up @@ -78,11 +78,11 @@ public function convertException(string $message, DriverExceptionInterface $exce

public function createDatabasePlatformForVersion(string $version) : AbstractPlatform
{
if (! preg_match(
if (preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/',
$version,
$versionParts
)) {
) === 0) {
throw InvalidPlatformVersion::new(
$version,
'<major_version>.<minor_version>.<patch_version>.<build_version>'
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/IBMDB2/DB2Connection.php
Expand Up @@ -60,7 +60,7 @@ public function getServerVersion() : string
public function prepare(string $sql) : DriverStatement
{
$stmt = @db2_prepare($this->conn, $sql);
if (! $stmt) {
if ($stmt === false) {
throw DB2Exception::fromStatementError();
}

Expand Down

0 comments on commit 24dbc4e

Please sign in to comment.