From 26d358715019d55f2980fd92ccffc98e4c0d85a5 Mon Sep 17 00:00:00 2001 From: Ahmed Abdou Date: Sun, 17 Mar 2019 13:16:26 +0100 Subject: [PATCH 1/2] Upgrade doctrine cs to 6.0 --- composer.json | 2 +- composer.lock | 77 +++++++++---------- lib/Doctrine/DBAL/Configuration.php | 4 +- lib/Doctrine/DBAL/Connection.php | 1 + .../DBAL/Driver/AbstractMySQLDriver.php | 8 -- .../DBAL/Driver/AbstractOracleDriver.php | 8 -- .../DBAL/Driver/AbstractPostgreSQLDriver.php | 8 -- .../DBAL/Driver/IBMDB2/DB2Statement.php | 6 -- .../DBAL/Driver/Mysqli/MysqliConnection.php | 4 +- .../DBAL/Driver/Mysqli/MysqliStatement.php | 7 +- .../DBAL/Driver/OCI8/OCI8Statement.php | 3 +- .../SQLAnywhere/SQLAnywhereStatement.php | 6 -- .../DBAL/Driver/SQLSrv/SQLSrvConnection.php | 4 +- lib/Doctrine/DBAL/DriverManager.php | 4 +- .../DBAL/Platforms/AbstractPlatform.php | 1 - lib/Doctrine/DBAL/Platforms/DB2Platform.php | 1 + lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 12 +-- .../DBAL/Platforms/OraclePlatform.php | 11 +-- .../DBAL/Platforms/PostgreSqlPlatform.php | 2 +- .../DBAL/Platforms/SQLAnywherePlatform.php | 6 +- .../DBAL/Platforms/SQLServerPlatform.php | 4 +- .../DBAL/Platforms/SqlitePlatform.php | 25 +++--- lib/Doctrine/DBAL/Query/QueryBuilder.php | 3 +- .../DBAL/Schema/AbstractSchemaManager.php | 2 +- lib/Doctrine/DBAL/Schema/DB2SchemaManager.php | 4 +- lib/Doctrine/DBAL/Schema/Index.php | 4 +- .../DBAL/Schema/MySqlSchemaManager.php | 1 + .../DBAL/Schema/SqliteSchemaManager.php | 2 +- .../SingleDatabaseSynchronizer.php | 1 - lib/Doctrine/DBAL/Schema/Table.php | 1 + .../Schema/Visitor/RemoveNamespacedAssets.php | 1 + lib/Doctrine/DBAL/Statement.php | 4 +- .../Tools/Console/Command/ImportCommand.php | 4 +- lib/Doctrine/DBAL/Tools/Dumper.php | 1 + phpcs.xml.dist | 2 +- .../Tests/DBAL/Functional/DataAccessTest.php | 2 +- .../Tests/DBAL/Functional/ResultCacheTest.php | 2 + .../Schema/PostgreSqlSchemaManagerTest.php | 1 + .../SchemaManagerFunctionalTestCase.php | 6 +- .../DBAL/Functional/TypeConversionTest.php | 2 +- .../TypeConversionPerformanceTest.php | 2 - .../AbstractMySQLPlatformTestCase.php | 1 - .../Platforms/AbstractPlatformTestCase.php | 3 + .../Platforms/SQLServer2012PlatformTest.php | 2 - .../Doctrine/Tests/DBAL/Schema/ColumnTest.php | 1 + .../Tests/DBAL/Schema/ComparatorTest.php | 4 +- .../Tests/DBAL/Schema/SchemaDiffTest.php | 1 + .../DBAL/Sharding/PoolingShardManagerTest.php | 2 + .../SQLAzure/SQLAzureShardManagerTest.php | 1 + .../DBAL/Types/ConversionExceptionTest.php | 1 + .../Doctrine/Tests/DbalFunctionalTestCase.php | 4 +- .../Tests/Mocks/DriverConnectionMock.php | 7 ++ 52 files changed, 135 insertions(+), 141 deletions(-) diff --git a/composer.json b/composer.json index ac4efe884a4..e5ff569c2d6 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "doctrine/event-manager": "^1.0" }, "require-dev": { - "doctrine/coding-standard": "^5.0", + "doctrine/coding-standard": "^6.0", "jetbrains/phpstorm-stubs": "^2018.1.2", "phpstan/phpstan": "^0.11.3", "phpunit/phpunit": "^8.0", diff --git a/composer.lock b/composer.lock index 596f3097636..7ba548e3d11 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "dc19a584f29861609d085123b65f3961", + "content-hash": "ddba260b7dfb84d2591b0a71a885166a", "packages": [ { "name": "doctrine/cache", @@ -202,29 +202,27 @@ }, { "name": "dealerdirect/phpcodesniffer-composer-installer", - "version": "v0.4.4", + "version": "v0.5.0", "source": { "type": "git", "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", - "reference": "2e41850d5f7797cbb1af7b030d245b3b24e63a08" + "reference": "e749410375ff6fb7a040a68878c656c2e610b132" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/2e41850d5f7797cbb1af7b030d245b3b24e63a08", - "reference": "2e41850d5f7797cbb1af7b030d245b3b24e63a08", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/e749410375ff6fb7a040a68878c656c2e610b132", + "reference": "e749410375ff6fb7a040a68878c656c2e610b132", "shasum": "" }, "require": { "composer-plugin-api": "^1.0", "php": "^5.3|^7", - "squizlabs/php_codesniffer": "*" + "squizlabs/php_codesniffer": "^2|^3" }, "require-dev": { "composer/composer": "*", - "wimg/php-compatibility": "^8.0" - }, - "suggest": { - "dealerdirect/qa-tools": "All the PHP QA tools you'll need" + "phpcompatibility/php-compatibility": "^9.0", + "sensiolabs/security-checker": "^4.1.0" }, "type": "composer-plugin", "extra": { @@ -242,13 +240,13 @@ "authors": [ { "name": "Franck Nijhof", - "email": "f.nijhof@dealerdirect.nl", - "homepage": "http://workingatdealerdirect.eu", - "role": "Developer" + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" } ], "description": "PHP_CodeSniffer Standards Composer Installer Plugin", - "homepage": "http://workingatdealerdirect.eu", + "homepage": "http://www.dealerdirect.com", "keywords": [ "PHPCodeSniffer", "PHP_CodeSniffer", @@ -266,32 +264,32 @@ "stylecheck", "tests" ], - "time": "2017-12-06T16:27:17+00:00" + "time": "2018-10-26T13:21:45+00:00" }, { "name": "doctrine/coding-standard", - "version": "5.0.0", + "version": "6.0.0", "source": { "type": "git", "url": "https://github.com/doctrine/coding-standard.git", - "reference": "bb8de042a25c4fb59a2c55c350dc55cc00227a8c" + "reference": "d33f69eb98b25aa51ffe3a909f0ec77000af4701" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/coding-standard/zipball/bb8de042a25c4fb59a2c55c350dc55cc00227a8c", - "reference": "bb8de042a25c4fb59a2c55c350dc55cc00227a8c", + "url": "https://api.github.com/repos/doctrine/coding-standard/zipball/d33f69eb98b25aa51ffe3a909f0ec77000af4701", + "reference": "d33f69eb98b25aa51ffe3a909f0ec77000af4701", "shasum": "" }, "require": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", + "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0", "php": "^7.1", - "slevomat/coding-standard": "^4.8.0", - "squizlabs/php_codesniffer": "^3.3.2" + "slevomat/coding-standard": "^5.0", + "squizlabs/php_codesniffer": "^3.4.0" }, "type": "phpcodesniffer-standard", "extra": { "branch-alias": { - "dev-master": "5.0.x-dev" + "dev-master": "6.0.x-dev" } }, "autoload": { @@ -327,7 +325,7 @@ "standard", "style" ], - "time": "2018-09-24T19:08:56+00:00" + "time": "2019-03-15T12:45:47+00:00" }, { "name": "doctrine/instantiator", @@ -2486,29 +2484,30 @@ }, { "name": "slevomat/coding-standard", - "version": "4.8.3", + "version": "5.0.2", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "32e1ca205fc34920f323582ed29c0602e3897ae3" + "reference": "223f02b6193fe47b7b483bfa5bf75693535482dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/32e1ca205fc34920f323582ed29c0602e3897ae3", - "reference": "32e1ca205fc34920f323582ed29c0602e3897ae3", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/223f02b6193fe47b7b483bfa5bf75693535482dd", + "reference": "223f02b6193fe47b7b483bfa5bf75693535482dd", "shasum": "" }, "require": { "php": "^7.1", - "squizlabs/php_codesniffer": "^3.3.0" + "phpstan/phpdoc-parser": "^0.3.1", + "squizlabs/php_codesniffer": "^3.4.0" }, "require-dev": { "jakub-onderka/php-parallel-lint": "1.0.0", "phing/phing": "2.16.1", - "phpstan/phpstan": "0.9.2", - "phpstan/phpstan-phpunit": "0.9.4", - "phpstan/phpstan-strict-rules": "0.9", - "phpunit/phpunit": "7.3.5" + "phpstan/phpstan": "0.11.1", + "phpstan/phpstan-phpunit": "0.11", + "phpstan/phpstan-strict-rules": "0.11", + "phpunit/phpunit": "8.0.0" }, "type": "phpcodesniffer-standard", "autoload": { @@ -2521,20 +2520,20 @@ "MIT" ], "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", - "time": "2018-09-25T21:21:11+00:00" + "time": "2019-03-12T20:26:36+00:00" }, { "name": "squizlabs/php_codesniffer", - "version": "3.3.2", + "version": "3.4.0", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e" + "reference": "379deb987e26c7cd103a7b387aea178baec96e48" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/6ad28354c04b364c3c71a34e4a18b629cc3b231e", - "reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/379deb987e26c7cd103a7b387aea178baec96e48", + "reference": "379deb987e26c7cd103a7b387aea178baec96e48", "shasum": "" }, "require": { @@ -2572,7 +2571,7 @@ "phpcs", "standards" ], - "time": "2018-09-23T23:08:17+00:00" + "time": "2018-12-19T23:57:18+00:00" }, { "name": "symfony/console", diff --git a/lib/Doctrine/DBAL/Configuration.php b/lib/Doctrine/DBAL/Configuration.php index 9b7b21fb21e..2cc0070d0cb 100644 --- a/lib/Doctrine/DBAL/Configuration.php +++ b/lib/Doctrine/DBAL/Configuration.php @@ -107,6 +107,7 @@ private function buildSchemaAssetsFilterFromExpression($filterExpression) : call if ($assetName instanceof AbstractAsset) { $assetName = $assetName->getName(); } + return preg_match($filterExpression, $assetName); }; } @@ -116,7 +117,8 @@ private function buildSchemaAssetsFilterFromExpression($filterExpression) : call */ public function setSchemaAssetsFilter(?callable $callable = null) : ?callable { - $this->_attributes['filterSchemaAssetsExpression'] = null; + $this->_attributes['filterSchemaAssetsExpression'] = null; + return $this->_attributes['filterSchemaAssetsExpressionCallable'] = $callable; } diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 8016b7da6a1..75b862bf74f 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -1161,6 +1161,7 @@ public function transactional(Closure $func) try { $res = $func($this); $this->commit(); + return $res; } catch (Exception $e) { $this->rollBack(); diff --git a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php index c46ddc63dd7..8ae86e5c72a 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php @@ -36,34 +36,28 @@ public function convertException($message, DriverException $exception) return new Exception\LockWaitTimeoutException($message, $exception); case '1050': return new Exception\TableExistsException($message, $exception); - case '1051': case '1146': return new Exception\TableNotFoundException($message, $exception); - case '1216': case '1217': case '1451': case '1452': case '1701': return new Exception\ForeignKeyConstraintViolationException($message, $exception); - case '1062': case '1557': case '1569': case '1586': return new Exception\UniqueConstraintViolationException($message, $exception); - case '1054': case '1166': case '1611': return new Exception\InvalidFieldNameException($message, $exception); - case '1052': case '1060': case '1110': return new Exception\NonUniqueFieldNameException($message, $exception); - case '1064': case '1149': case '1287': @@ -77,7 +71,6 @@ public function convertException($message, DriverException $exception) case '1554': case '1626': return new Exception\SyntaxErrorException($message, $exception); - case '1044': case '1045': case '1046': @@ -91,7 +84,6 @@ public function convertException($message, DriverException $exception) case '2002': case '2005': return new Exception\ConnectionException($message, $exception); - case '1048': case '1121': case '1138': diff --git a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php index dcbaaf097f7..f1ba8843a77 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php @@ -24,30 +24,22 @@ public function convertException($message, DriverException $exception) case '2299': case '38911': return new Exception\UniqueConstraintViolationException($message, $exception); - case '904': return new Exception\InvalidFieldNameException($message, $exception); - case '918': case '960': return new Exception\NonUniqueFieldNameException($message, $exception); - case '923': return new Exception\SyntaxErrorException($message, $exception); - case '942': return new Exception\TableNotFoundException($message, $exception); - case '955': return new Exception\TableExistsException($message, $exception); - case '1017': case '12545': return new Exception\ConnectionException($message, $exception); - case '1400': return new Exception\NotNullConstraintViolationException($message, $exception); - case '2266': case '2291': case '2292': diff --git a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php index 916d924980c..70f2f0ca6aa 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php @@ -43,28 +43,20 @@ public function convertException($message, DriverException $exception) break; case '23502': return new Exception\NotNullConstraintViolationException($message, $exception); - case '23503': return new Exception\ForeignKeyConstraintViolationException($message, $exception); - case '23505': return new Exception\UniqueConstraintViolationException($message, $exception); - case '42601': return new Exception\SyntaxErrorException($message, $exception); - case '42702': return new Exception\NonUniqueFieldNameException($message, $exception); - case '42703': return new Exception\InvalidFieldNameException($message, $exception); - case '42P01': return new Exception\TableNotFoundException($message, $exception); - case '42P07': return new Exception\TableExistsException($message, $exception); - case '7': // In some case (mainly connection errors) the PDO exception does not provide a SQLSTATE via its code. // The exception code is always set to 7 here. diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index af6e852bc43..339c9be92d0 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -261,13 +261,10 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX switch ($fetchMode) { case FetchMode::COLUMN: return $this->fetchColumn(); - case FetchMode::MIXED: return db2_fetch_both($this->stmt); - case FetchMode::ASSOCIATIVE: return db2_fetch_assoc($this->stmt); - case FetchMode::CUSTOM_OBJECT: $className = $this->defaultFetchClass; $ctorArgs = $this->defaultFetchClassCtorArgs; @@ -285,13 +282,10 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX } return $result; - case FetchMode::NUMERIC: return db2_fetch_array($this->stmt); - case FetchMode::STANDARD_OBJECT: return db2_fetch_object($this->stmt); - default: throw new DB2Exception('Given Fetch-Style ' . $fetchMode . ' is not supported.'); } diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php index 1f1a1d218c3..54ad02d37e4 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php @@ -57,7 +57,7 @@ public function __construct(array $params, $username, $password, array $driverOp $socket = $params['unix_socket'] ?? ini_get('mysqli.default_socket'); $dbname = $params['dbname'] ?? null; - $flags = $driverOptions[static::OPTION_FLAGS] ?? null; + $flags = $driverOptions[self::OPTION_FLAGS] ?? null; $this->conn = mysqli_init(); @@ -239,7 +239,7 @@ private function setDriverOptions(array $driverOptions = []) $exceptionMsg = "%s option '%s' with value '%s'"; foreach ($driverOptions as $option => $value) { - if ($option === static::OPTION_FLAGS) { + if ($option === self::OPTION_FLAGS) { continue; } diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index 893b3be4688..f284d838486 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -225,9 +225,9 @@ private function bindTypedParameters() $streams[$parameter] = $value; $values[$parameter] = null; continue; - } else { - $types[$parameter - 1] = static::$_paramTypeMap[ParameterType::STRING]; } + + $types[$parameter - 1] = static::$_paramTypeMap[ParameterType::STRING]; } $values[$parameter] = $value; @@ -338,13 +338,10 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX switch ($fetchMode) { case FetchMode::ASSOCIATIVE: return $assoc; - case FetchMode::MIXED: return $assoc + $values; - case FetchMode::STANDARD_OBJECT: return (object) $assoc; - default: throw new MysqliException(sprintf("Unknown fetch type '%s'", $fetchMode)); } diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index f5a141c1732..b2d9476501f 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -254,6 +254,7 @@ private static function findToken($statement, &$offset, $regex) { if (preg_match($regex, $statement, $matches, PREG_OFFSET_CAPTURE, $offset)) { $offset = $matches[0][1]; + return $matches[0][0]; } @@ -305,10 +306,8 @@ private function convertParameterType(int $type) : int switch ($type) { case ParameterType::BINARY: return OCI_B_BIN; - case ParameterType::LARGE_OBJECT: return OCI_B_BLOB; - default: return SQLT_CHR; } diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index 886bb245873..0f65d66f205 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -210,13 +210,10 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX switch ($fetchMode) { case FetchMode::COLUMN: return $this->fetchColumn(); - case FetchMode::ASSOCIATIVE: return sasql_fetch_assoc($this->result); - case FetchMode::MIXED: return sasql_fetch_array($this->result, SASQL_BOTH); - case FetchMode::CUSTOM_OBJECT: $className = $this->defaultFetchClass; $ctorArgs = $this->defaultFetchClassCtorArgs; @@ -234,13 +231,10 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX } return $result; - case FetchMode::NUMERIC: return sasql_fetch_row($this->result); - case FetchMode::STANDARD_OBJECT: return sasql_fetch_object($this->result); - default: throw new SQLAnywhereException('Fetch mode is not supported: ' . $fetchMode); } diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php index e36bc9051cf..35ad913ff5b 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php @@ -100,7 +100,9 @@ public function quote($value, $type = ParameterType::STRING) { if (is_int($value)) { return $value; - } elseif (is_float($value)) { + } + + if (is_float($value)) { return sprintf('%F', $value); } diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index cb9db2c0221..6888d73b0c4 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -174,7 +174,9 @@ public static function getConnection( // check for existing pdo object if (isset($params['pdo']) && ! $params['pdo'] instanceof PDO) { throw DBALException::invalidPdoInstance(); - } elseif (isset($params['pdo'])) { + } + + if (isset($params['pdo'])) { $params['pdo']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $params['driver'] = 'pdo_' . $params['pdo']->getAttribute(PDO::ATTR_DRIVER_NAME); } else { diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 6a6c65a4092..abb7333ac1d 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -2968,7 +2968,6 @@ public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration) return $this->getDateTimeTypeDeclarationSQL($fieldDeclaration); } - /** * Obtains DBMS specific SQL to be used to create date fields in statements * like CREATE TABLE. diff --git a/lib/Doctrine/DBAL/Platforms/DB2Platform.php b/lib/Doctrine/DBAL/Platforms/DB2Platform.php index 88c9b187f9d..60457146fd0 100644 --- a/lib/Doctrine/DBAL/Platforms/DB2Platform.php +++ b/lib/Doctrine/DBAL/Platforms/DB2Platform.php @@ -501,6 +501,7 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options foreach ($indexes as $definition) { $sqls[] = $this->getCreateIndexSQL($definition, $tableName); } + return $sqls; } diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 9679a8447e7..ae1f9cd33c8 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -247,15 +247,15 @@ public function getClobTypeDeclarationSQL(array $field) if (! empty($field['length']) && is_numeric($field['length'])) { $length = $field['length']; - if ($length <= static::LENGTH_LIMIT_TINYTEXT) { + if ($length <= self::LENGTH_LIMIT_TINYTEXT) { return 'TINYTEXT'; } - if ($length <= static::LENGTH_LIMIT_TEXT) { + if ($length <= self::LENGTH_LIMIT_TEXT) { return 'TEXT'; } - if ($length <= static::LENGTH_LIMIT_MEDIUMTEXT) { + if ($length <= self::LENGTH_LIMIT_MEDIUMTEXT) { return 'MEDIUMTEXT'; } } @@ -1137,15 +1137,15 @@ public function getBlobTypeDeclarationSQL(array $field) if (! empty($field['length']) && is_numeric($field['length'])) { $length = $field['length']; - if ($length <= static::LENGTH_LIMIT_TINYBLOB) { + if ($length <= self::LENGTH_LIMIT_TINYBLOB) { return 'TINYBLOB'; } - if ($length <= static::LENGTH_LIMIT_BLOB) { + if ($length <= self::LENGTH_LIMIT_BLOB) { return 'BLOB'; } - if ($length <= static::LENGTH_LIMIT_MEDIUMBLOB) { + if ($length <= self::LENGTH_LIMIT_MEDIUMBLOB) { return 'MEDIUMBLOB'; } } diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index 711fbccbd53..c091d483064 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -114,7 +114,6 @@ protected function getDateArithmeticIntervalExpression($date, $operator, $interv } return 'ADD_MONTHS(' . $date . ', ' . $operator . $interval . ')'; - default: $calculationClause = ''; @@ -201,9 +200,13 @@ private function getSequenceCacheSQL(Sequence $sequence) { if ($sequence->getCache() === 0) { return ' NOCACHE'; - } elseif ($sequence->getCache() === 1) { + } + + if ($sequence->getCache() === 1) { return ' NOCACHE'; - } elseif ($sequence->getCache() > 1) { + } + + if ($sequence->getCache() > 1) { return ' CACHE ' . $sequence->getCache(); } @@ -739,11 +742,9 @@ public function getForeignKeyReferentialActionSQL($action) // NO ACTION cannot be declared explicitly, // therefore returning empty string to indicate to OMIT the referential clause. return ''; - case 'CASCADE': case 'SET NULL': return $action; - default: // SET DEFAULT is not supported, throw exception instead. throw new InvalidArgumentException('Invalid foreign key action: ' . $action); diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 806d59e6c97..4458ae27750 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -821,7 +821,7 @@ private function convertSingleBooleanValue($value, $callback) } if (is_bool($value) || is_numeric($value)) { - return $callback($value ? true : false); + return $callback((bool) $value); } if (! is_string($value)) { diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index 510c153e65f..f01905e7b74 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -49,13 +49,10 @@ public function appendLockHint($fromClause, $lockMode) switch (true) { case $lockMode === LockMode::NONE: return $fromClause . ' WITH (NOLOCK)'; - case $lockMode === LockMode::PESSIMISTIC_READ: return $fromClause . ' WITH (UPDLOCK)'; - case $lockMode === LockMode::PESSIMISTIC_WRITE: return $fromClause . ' WITH (XLOCK)'; - default: return $fromClause; } @@ -627,12 +624,15 @@ public function getForeignKeyMatchClauseSQL($type) switch ((int) $type) { case self::FOREIGN_KEY_MATCH_SIMPLE: return 'SIMPLE'; + break; case self::FOREIGN_KEY_MATCH_FULL: return 'FULL'; + break; case self::FOREIGN_KEY_MATCH_SIMPLE_UNIQUE: return 'UNIQUE SIMPLE'; + break; case self::FOREIGN_KEY_MATCH_FULL_UNIQUE: return 'UNIQUE FULL'; diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 01417d7e292..2722137ab66 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -1349,6 +1349,7 @@ private function scrubInnerOrderBy($query) $query = substr($query, 0, $orderByPos) . substr($query, $currentPosition - 1); $offset = $orderByPos; } + return $query; } @@ -1547,13 +1548,10 @@ public function appendLockHint($fromClause, $lockMode) switch (true) { case $lockMode === LockMode::NONE: return $fromClause . ' WITH (NOLOCK)'; - case $lockMode === LockMode::PESSIMISTIC_READ: return $fromClause . ' WITH (HOLDLOCK, ROWLOCK)'; - case $lockMode === LockMode::PESSIMISTIC_WRITE: return $fromClause . ' WITH (UPDLOCK, ROWLOCK)'; - default: return $fromClause; } diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index 009a8f23df4..4fc8c72bb87 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -128,7 +128,6 @@ protected function getDateArithmeticIntervalExpression($date, $operator, $interv case DateIntervalUnit::MINUTE: case DateIntervalUnit::HOUR: return 'DATETIME(' . $date . ",'" . $operator . $interval . ' ' . $unit . "')"; - default: switch ($unit) { case DateIntervalUnit::WEEK: @@ -1070,12 +1069,14 @@ private function getIndexesInAlteredTable(TableDiff $diff) if (! isset($columnNames[$normalizedColumnName])) { unset($indexes[$key]); continue 2; - } else { - $indexColumns[] = $columnNames[$normalizedColumnName]; - if ($columnName !== $columnNames[$normalizedColumnName]) { - $changed = true; - } } + + $indexColumns[] = $columnNames[$normalizedColumnName]; + if ($columnName === $columnNames[$normalizedColumnName]) { + continue; + } + + $changed = true; } if (! $changed) { @@ -1122,12 +1123,14 @@ private function getForeignKeysInAlteredTable(TableDiff $diff) if (! isset($columnNames[$normalizedColumnName])) { unset($foreignKeys[$key]); continue 2; - } else { - $localColumns[] = $columnNames[$normalizedColumnName]; - if ($columnName !== $columnNames[$normalizedColumnName]) { - $changed = true; - } } + + $localColumns[] = $columnNames[$normalizedColumnName]; + if ($columnName === $columnNames[$normalizedColumnName]) { + continue; + } + + $changed = true; } if (! $changed) { diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index 773afa23d87..1c08db193dd 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -866,7 +866,6 @@ public function groupBy($groupBy) return $this->add('groupBy', $groupBy, false); } - /** * Adds a grouping expression to the query. * @@ -1188,6 +1187,7 @@ private function getSQLForInsert() private function getSQLForUpdate() { $table = $this->sqlParts['from']['table'] . ($this->sqlParts['from']['alias'] ? ' ' . $this->sqlParts['from']['alias'] : ''); + return 'UPDATE ' . $table . ' SET ' . implode(', ', $this->sqlParts['set']) . ($this->sqlParts['where'] !== null ? ' WHERE ' . ((string) $this->sqlParts['where']) : ''); @@ -1201,6 +1201,7 @@ private function getSQLForUpdate() private function getSQLForDelete() { $table = $this->sqlParts['from']['table'] . ($this->sqlParts['from']['alias'] ? ' ' . $this->sqlParts['from']['alias'] : ''); + return 'DELETE FROM ' . $table . ($this->sqlParts['where'] !== null ? ' WHERE ' . ((string) $this->sqlParts['where']) : ''); } diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index 8c055921c7c..5c92c2e3f7b 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -854,7 +854,7 @@ protected function _getPortableTableIndexesList($tableIndexRows, $tableName = nu $result[$keyName] = [ 'name' => $indexName, 'columns' => [], - 'unique' => $tableIndex['non_unique'] ? false : true, + 'unique' => ! $tableIndex['non_unique'], 'primary' => $tableIndex['primary'], 'flags' => $tableIndex['flags'] ?? [], 'options' => $options, diff --git a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php index 0307a0d537d..0ae7aba2cf4 100644 --- a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php @@ -178,7 +178,9 @@ protected function _getPortableForeignKeyRuleDef($def) { if ($def === 'C') { return 'CASCADE'; - } elseif ($def === 'N') { + } + + if ($def === 'N') { return 'SET NULL'; } diff --git a/lib/Doctrine/DBAL/Schema/Index.php b/lib/Doctrine/DBAL/Schema/Index.php index 91ffd472465..7a31c7824bf 100644 --- a/lib/Doctrine/DBAL/Schema/Index.php +++ b/lib/Doctrine/DBAL/Schema/Index.php @@ -243,7 +243,9 @@ public function overrules(Index $other) { if ($other->isPrimary()) { return false; - } elseif ($this->isSimpleIndex() && $other->isUnique()) { + } + + if ($this->isSimpleIndex() && $other->isUnique()) { return false; } diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index 4cc31a9258a..fb957f247ff 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -230,6 +230,7 @@ private function getMariaDb1027ColumnDefault(MariaDb1027Platform $platform, ?str case 'curtime()': return $platform->getCurrentTimeSQL(); } + return $columnDefault; } diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index 9d03552b667..e819d963f03 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -205,7 +205,7 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null $idx = []; $idx['key_name'] = $keyName; $idx['primary'] = false; - $idx['non_unique'] = $tableIndex['unique']?false:true; + $idx['non_unique'] = ! $tableIndex['unique']; $stmt = $this->_conn->executeQuery(sprintf( 'PRAGMA INDEX_INFO (%s)', diff --git a/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php b/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php index 0925b7743c8..dd4b1ca5f40 100644 --- a/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php +++ b/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php @@ -31,7 +31,6 @@ public function getCreateSchema(Schema $createSchema) return $createSchema->toSql($this->platform); } - /** * {@inheritdoc} */ diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 6030f25cffa..af853c277d5 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -610,6 +610,7 @@ private function getForeignKeyColumns() foreach ($this->getForeignKeys() as $foreignKey) { $foreignKeyColumns = array_merge($foreignKeyColumns, $foreignKey->getColumns()); } + return $this->filterColumns($foreignKeyColumns); } diff --git a/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php b/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php index 9b23b395885..001ea2a0d70 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php @@ -65,6 +65,7 @@ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkCons // point to nowhere. if (! $this->schema->hasTable($fkConstraint->getForeignTableName())) { $localTable->removeForeignKey($fkConstraint->getName()); + return; } diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index b65fa95e33a..09913bb56ae 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -217,7 +217,9 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) { if ($arg2 === null) { return $this->stmt->setFetchMode($fetchMode); - } elseif ($arg3 === null) { + } + + if ($arg3 === null) { return $this->stmt->setFetchMode($fetchMode, $arg2); } diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php index 22bce134061..a45a60c6085 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php @@ -73,7 +73,9 @@ protected function execute(InputInterface $input, OutputInterface $output) throw new InvalidArgumentException( sprintf("SQL file '%s' does not exist.", $filePath) ); - } elseif (! is_readable($filePath)) { + } + + if (! is_readable($filePath)) { throw new InvalidArgumentException( sprintf("SQL file '%s' does not have read permissions.", $filePath) ); diff --git a/lib/Doctrine/DBAL/Tools/Dumper.php b/lib/Doctrine/DBAL/Tools/Dumper.php index 6174b7ad865..3668efbe4d1 100644 --- a/lib/Doctrine/DBAL/Tools/Dumper.php +++ b/lib/Doctrine/DBAL/Tools/Dumper.php @@ -73,6 +73,7 @@ public static function dump($var, int $maxDepth = 2) : string try { $output = ob_get_clean(); assert(is_string($output)); + return strip_tags(html_entity_decode($output)); } finally { ini_set('html_errors', $html); diff --git a/phpcs.xml.dist b/phpcs.xml.dist index c38da21aa70..6567098ebf3 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -60,7 +60,7 @@ - + lib/Doctrine/DBAL/Schema/Comparator.php diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index fdb0ace7078..205f3fd6a75 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -36,7 +36,7 @@ class DataAccessTest extends DbalFunctionalTestCase { /** @var bool */ - static private $generated = false; + private static $generated = false; protected function setUp() : void { diff --git a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php index 82f9e6541ed..06f6c18bbe3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php @@ -223,6 +223,7 @@ private function hydrateStmt($stmt, $fetchMode = FetchMode::ASSOCIATIVE) $data[] = is_array($row) ? array_change_key_case($row, CASE_LOWER) : $row; } $stmt->closeCursor(); + return $data; } @@ -234,6 +235,7 @@ private function hydrateStmtIterator($stmt, $fetchMode = FetchMode::ASSOCIATIVE) $data[] = is_array($row) ? array_change_key_case($row, CASE_LOWER) : $row; } $stmt->closeCursor(); + return $data; } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index b30c861f704..597947d4575 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -390,6 +390,7 @@ public function testJsonbColumn(string $type) : void { if (! $this->schemaManager->getDatabasePlatform() instanceof PostgreSQL94Platform) { $this->markTestSkipped('Requires PostgresSQL 9.4+'); + return; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index c9826f14243..aeb9f4c90dd 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -56,6 +56,7 @@ protected function getPlatformName() $class = static::class; $e = explode('\\', $class); $testClass = end($e); + return strtolower(str_replace('SchemaManagerTest', null, $testClass)); } @@ -72,7 +73,6 @@ protected function setUp() : void $this->schemaManager = $this->connection->getSchemaManager(); } - protected function tearDown() : void { parent::tearDown(); @@ -88,7 +88,6 @@ protected function tearDown() : void } } - /** * @group DBAL-1220 */ @@ -632,7 +631,6 @@ public function testAlterTableScenario() self::assertEquals(['id'], array_map('strtolower', $foreignKey->getForeignColumns())); } - public function testTableInNamespace() { if (! $this->schemaManager->getDatabasePlatform()->supportsSchemas()) { @@ -982,6 +980,7 @@ protected function getTestTable($name, $options = []) $table->setPrimaryKey(['id']); $table->addColumn('test', 'string', ['length' => 255]); $table->addColumn('foreign_key_test', 'integer'); + return $table; } @@ -993,6 +992,7 @@ protected function getTestCompositeTable($name) $table->addColumn('other_id', 'integer', ['notnull' => true]); $table->setPrimaryKey(['id', 'other_id']); $table->addColumn('test', 'string', ['length' => 255]); + return $table; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php b/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php index 768b65275f7..d5d917474ce 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php @@ -13,7 +13,7 @@ class TypeConversionTest extends DbalFunctionalTestCase { /** @var int */ - static private $typeCounter = 0; + private static $typeCounter = 0; protected function setUp() : void { diff --git a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php index c4efa1b8377..a0bf8936f50 100644 --- a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php +++ b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php @@ -8,8 +8,6 @@ use Doctrine\Tests\DbalPerformanceTestCase; /** - * Class TypeConversionPerformanceTest - * * @group performance */ class TypeConversionPerformanceTest extends DbalPerformanceTestCase diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php index 79dbc0040b1..ea6a6ffe59e 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php @@ -75,7 +75,6 @@ public function testGeneratesTransactionsCommands() ); } - public function testGeneratesDDLSnippets() { self::assertEquals('SHOW DATABASES', $this->platform->getListDatabasesSQL()); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index 5feba5f96f6..910f2daa2c1 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -628,8 +628,11 @@ public function testQuotedColumnInPrimaryKeyPropagation() } abstract protected function getQuotedColumnInPrimaryKeySQL(); + abstract protected function getQuotedColumnInIndexSQL(); + abstract protected function getQuotedNameInIndexSQL(); + abstract protected function getQuotedColumnInForeignKeySQL(); /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php index b908c427c28..91f8cfe2dc2 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php @@ -44,7 +44,6 @@ public function testGeneratesSequenceSqlCommands() ); } - public function testModifyLimitQuery() { $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0); @@ -270,7 +269,6 @@ public function testModifyLimitQueryWithComplexOrderByExpression() self::assertEquals($sql, $expected); } - /** * @throws DBALException */ diff --git a/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php b/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php index 51fe749e28e..caf93439244 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php @@ -99,6 +99,7 @@ public function createColumn() ]; $string = Type::getType('string'); + return new Column('foo', $string, $options); } diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index 4376448072d..5222a1ee548 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -795,7 +795,6 @@ public function testDetectChangeIdentifierType() self::assertArrayHasKey('id', $tableDiff->changedColumns); } - /** * @group DBAL-105 */ @@ -823,7 +822,6 @@ public function testDiff() self::assertCount(0, $tableDiff->removedColumns); } - /** * @group DBAL-112 */ @@ -963,7 +961,6 @@ public function testAutoIncrementSequences() self::assertCount(0, $diff->removedSequences); } - /** * Check that added autoincrement sequence is not populated in newSequences * @@ -987,6 +984,7 @@ public function testAutoIncrementNoSequences() self::assertCount(0, $diff->newSequences); } + /** * You can get multiple drops for a FK when a table referenced by a foreign * key is deleted, as this FK is referenced twice, once on the orphanedForeignKeys diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php index 78d4582d880..8400e952ef6 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php @@ -118,6 +118,7 @@ public function createSchemaDiff() $fk = new ForeignKeyConstraint(['id'], 'foreign_table', ['id']); $fk->setLocalTable(new Table('local_table')); $diff->orphanedForeignKeys[] = $fk; + return $diff; } } diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php index 78fd894de05..f1f6cc0e2e7 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php @@ -25,6 +25,7 @@ private function createPassthroughShardChoser() ->will($this->returnCallback(static function ($value) { return $value; })); + return $mock; } @@ -34,6 +35,7 @@ private function createStaticShardChooser() $mock->expects($this->any()) ->method('pickShard') ->willReturn(1); + return $mock; } diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php index b96a9eaa173..3a0d37ab4ce 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php @@ -89,6 +89,7 @@ private function createConnection(array $params) ->disableOriginalConstructor() ->getMock(); $conn->expects($this->at(0))->method('getParams')->will($this->returnValue($params)); + return $conn; } } diff --git a/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php index f0183ef854c..3030899cd51 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php @@ -26,6 +26,7 @@ public function testConversionFailedInvalidTypeWithScalar($scalarValue) $exception->getMessage() ); } + /** * @param mixed $nonScalar * diff --git a/tests/Doctrine/Tests/DbalFunctionalTestCase.php b/tests/Doctrine/Tests/DbalFunctionalTestCase.php index 1e37c3060e8..2ae17cf9165 100644 --- a/tests/Doctrine/Tests/DbalFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DbalFunctionalTestCase.php @@ -74,7 +74,9 @@ protected function onNotSuccessfulTest(Throwable $t) : void $params = array_map(static function ($p) { if (is_object($p)) { return get_class($p); - } elseif (is_scalar($p)) { + } + + if (is_scalar($p)) { return "'" . $p . "'"; } diff --git a/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php b/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php index 7b8872f2ea8..fa22cc5f91b 100644 --- a/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php @@ -10,6 +10,7 @@ class DriverConnectionMock implements Connection public function prepare($prepareString) { } + public function query() { } @@ -21,21 +22,27 @@ public function quote($input, $type = ParameterType::STRING) public function exec($statement) { } + public function lastInsertId($name = null) { } + public function beginTransaction() { } + public function commit() { } + public function rollBack() { } + public function errorCode() { } + public function errorInfo() { } From bf0684430e2c27bec1aa245e35ec4fcc50a4427e Mon Sep 17 00:00:00 2001 From: Ahmed Abdou Date: Sun, 17 Mar 2019 22:38:13 +0100 Subject: [PATCH 2/2] disable two rules for phpcs --- lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php | 8 ++++++++ lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php | 8 ++++++++ .../DBAL/Driver/AbstractPostgreSQLDriver.php | 8 ++++++++ lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php | 6 ++++++ lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php | 4 ++-- lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php | 3 +++ lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php | 2 ++ .../DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php | 6 ++++++ lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 12 ++++++------ lib/Doctrine/DBAL/Platforms/OraclePlatform.php | 3 +++ lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php | 3 +++ lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php | 3 +++ lib/Doctrine/DBAL/Platforms/SqlitePlatform.php | 1 + phpcs.xml.dist | 2 ++ 14 files changed, 61 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php index 8ae86e5c72a..c46ddc63dd7 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php @@ -36,28 +36,34 @@ public function convertException($message, DriverException $exception) return new Exception\LockWaitTimeoutException($message, $exception); case '1050': return new Exception\TableExistsException($message, $exception); + case '1051': case '1146': return new Exception\TableNotFoundException($message, $exception); + case '1216': case '1217': case '1451': case '1452': case '1701': return new Exception\ForeignKeyConstraintViolationException($message, $exception); + case '1062': case '1557': case '1569': case '1586': return new Exception\UniqueConstraintViolationException($message, $exception); + case '1054': case '1166': case '1611': return new Exception\InvalidFieldNameException($message, $exception); + case '1052': case '1060': case '1110': return new Exception\NonUniqueFieldNameException($message, $exception); + case '1064': case '1149': case '1287': @@ -71,6 +77,7 @@ public function convertException($message, DriverException $exception) case '1554': case '1626': return new Exception\SyntaxErrorException($message, $exception); + case '1044': case '1045': case '1046': @@ -84,6 +91,7 @@ public function convertException($message, DriverException $exception) case '2002': case '2005': return new Exception\ConnectionException($message, $exception); + case '1048': case '1121': case '1138': diff --git a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php index f1ba8843a77..dcbaaf097f7 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php @@ -24,22 +24,30 @@ public function convertException($message, DriverException $exception) case '2299': case '38911': return new Exception\UniqueConstraintViolationException($message, $exception); + case '904': return new Exception\InvalidFieldNameException($message, $exception); + case '918': case '960': return new Exception\NonUniqueFieldNameException($message, $exception); + case '923': return new Exception\SyntaxErrorException($message, $exception); + case '942': return new Exception\TableNotFoundException($message, $exception); + case '955': return new Exception\TableExistsException($message, $exception); + case '1017': case '12545': return new Exception\ConnectionException($message, $exception); + case '1400': return new Exception\NotNullConstraintViolationException($message, $exception); + case '2266': case '2291': case '2292': diff --git a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php index 70f2f0ca6aa..916d924980c 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php @@ -43,20 +43,28 @@ public function convertException($message, DriverException $exception) break; case '23502': return new Exception\NotNullConstraintViolationException($message, $exception); + case '23503': return new Exception\ForeignKeyConstraintViolationException($message, $exception); + case '23505': return new Exception\UniqueConstraintViolationException($message, $exception); + case '42601': return new Exception\SyntaxErrorException($message, $exception); + case '42702': return new Exception\NonUniqueFieldNameException($message, $exception); + case '42703': return new Exception\InvalidFieldNameException($message, $exception); + case '42P01': return new Exception\TableNotFoundException($message, $exception); + case '42P07': return new Exception\TableExistsException($message, $exception); + case '7': // In some case (mainly connection errors) the PDO exception does not provide a SQLSTATE via its code. // The exception code is always set to 7 here. diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 339c9be92d0..af6e852bc43 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -261,10 +261,13 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX switch ($fetchMode) { case FetchMode::COLUMN: return $this->fetchColumn(); + case FetchMode::MIXED: return db2_fetch_both($this->stmt); + case FetchMode::ASSOCIATIVE: return db2_fetch_assoc($this->stmt); + case FetchMode::CUSTOM_OBJECT: $className = $this->defaultFetchClass; $ctorArgs = $this->defaultFetchClassCtorArgs; @@ -282,10 +285,13 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX } return $result; + case FetchMode::NUMERIC: return db2_fetch_array($this->stmt); + case FetchMode::STANDARD_OBJECT: return db2_fetch_object($this->stmt); + default: throw new DB2Exception('Given Fetch-Style ' . $fetchMode . ' is not supported.'); } diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php index 54ad02d37e4..1f1a1d218c3 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php @@ -57,7 +57,7 @@ public function __construct(array $params, $username, $password, array $driverOp $socket = $params['unix_socket'] ?? ini_get('mysqli.default_socket'); $dbname = $params['dbname'] ?? null; - $flags = $driverOptions[self::OPTION_FLAGS] ?? null; + $flags = $driverOptions[static::OPTION_FLAGS] ?? null; $this->conn = mysqli_init(); @@ -239,7 +239,7 @@ private function setDriverOptions(array $driverOptions = []) $exceptionMsg = "%s option '%s' with value '%s'"; foreach ($driverOptions as $option => $value) { - if ($option === self::OPTION_FLAGS) { + if ($option === static::OPTION_FLAGS) { continue; } diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index f284d838486..43d70853ef5 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -338,10 +338,13 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX switch ($fetchMode) { case FetchMode::ASSOCIATIVE: return $assoc; + case FetchMode::MIXED: return $assoc + $values; + case FetchMode::STANDARD_OBJECT: return (object) $assoc; + default: throw new MysqliException(sprintf("Unknown fetch type '%s'", $fetchMode)); } diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index b2d9476501f..f9540110263 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -306,8 +306,10 @@ private function convertParameterType(int $type) : int switch ($type) { case ParameterType::BINARY: return OCI_B_BIN; + case ParameterType::LARGE_OBJECT: return OCI_B_BLOB; + default: return SQLT_CHR; } diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index 0f65d66f205..886bb245873 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -210,10 +210,13 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX switch ($fetchMode) { case FetchMode::COLUMN: return $this->fetchColumn(); + case FetchMode::ASSOCIATIVE: return sasql_fetch_assoc($this->result); + case FetchMode::MIXED: return sasql_fetch_array($this->result, SASQL_BOTH); + case FetchMode::CUSTOM_OBJECT: $className = $this->defaultFetchClass; $ctorArgs = $this->defaultFetchClassCtorArgs; @@ -231,10 +234,13 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX } return $result; + case FetchMode::NUMERIC: return sasql_fetch_row($this->result); + case FetchMode::STANDARD_OBJECT: return sasql_fetch_object($this->result); + default: throw new SQLAnywhereException('Fetch mode is not supported: ' . $fetchMode); } diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index ae1f9cd33c8..9679a8447e7 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -247,15 +247,15 @@ public function getClobTypeDeclarationSQL(array $field) if (! empty($field['length']) && is_numeric($field['length'])) { $length = $field['length']; - if ($length <= self::LENGTH_LIMIT_TINYTEXT) { + if ($length <= static::LENGTH_LIMIT_TINYTEXT) { return 'TINYTEXT'; } - if ($length <= self::LENGTH_LIMIT_TEXT) { + if ($length <= static::LENGTH_LIMIT_TEXT) { return 'TEXT'; } - if ($length <= self::LENGTH_LIMIT_MEDIUMTEXT) { + if ($length <= static::LENGTH_LIMIT_MEDIUMTEXT) { return 'MEDIUMTEXT'; } } @@ -1137,15 +1137,15 @@ public function getBlobTypeDeclarationSQL(array $field) if (! empty($field['length']) && is_numeric($field['length'])) { $length = $field['length']; - if ($length <= self::LENGTH_LIMIT_TINYBLOB) { + if ($length <= static::LENGTH_LIMIT_TINYBLOB) { return 'TINYBLOB'; } - if ($length <= self::LENGTH_LIMIT_BLOB) { + if ($length <= static::LENGTH_LIMIT_BLOB) { return 'BLOB'; } - if ($length <= self::LENGTH_LIMIT_MEDIUMBLOB) { + if ($length <= static::LENGTH_LIMIT_MEDIUMBLOB) { return 'MEDIUMBLOB'; } } diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index c091d483064..ced7fbf9bdc 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -114,6 +114,7 @@ protected function getDateArithmeticIntervalExpression($date, $operator, $interv } return 'ADD_MONTHS(' . $date . ', ' . $operator . $interval . ')'; + default: $calculationClause = ''; @@ -742,9 +743,11 @@ public function getForeignKeyReferentialActionSQL($action) // NO ACTION cannot be declared explicitly, // therefore returning empty string to indicate to OMIT the referential clause. return ''; + case 'CASCADE': case 'SET NULL': return $action; + default: // SET DEFAULT is not supported, throw exception instead. throw new InvalidArgumentException('Invalid foreign key action: ' . $action); diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index f01905e7b74..6e3b2fcb958 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -49,10 +49,13 @@ public function appendLockHint($fromClause, $lockMode) switch (true) { case $lockMode === LockMode::NONE: return $fromClause . ' WITH (NOLOCK)'; + case $lockMode === LockMode::PESSIMISTIC_READ: return $fromClause . ' WITH (UPDLOCK)'; + case $lockMode === LockMode::PESSIMISTIC_WRITE: return $fromClause . ' WITH (XLOCK)'; + default: return $fromClause; } diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 2722137ab66..a2e68049d68 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -1548,10 +1548,13 @@ public function appendLockHint($fromClause, $lockMode) switch (true) { case $lockMode === LockMode::NONE: return $fromClause . ' WITH (NOLOCK)'; + case $lockMode === LockMode::PESSIMISTIC_READ: return $fromClause . ' WITH (HOLDLOCK, ROWLOCK)'; + case $lockMode === LockMode::PESSIMISTIC_WRITE: return $fromClause . ' WITH (UPDLOCK, ROWLOCK)'; + default: return $fromClause; } diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index 4fc8c72bb87..b7382ec08b0 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -128,6 +128,7 @@ protected function getDateArithmeticIntervalExpression($date, $operator, $interv case DateIntervalUnit::MINUTE: case DateIntervalUnit::HOUR: return 'DATETIME(' . $date . ",'" . $operator . $interval . ' ' . $unit . "')"; + default: switch ($unit) { case DateIntervalUnit::WEEK: diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 6567098ebf3..6fdaaf512c4 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -19,6 +19,8 @@ + +