From d2f9b7a3658144c322fcbeafcc8aa0e0e1183b4a Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 31 Jul 2021 09:16:53 -0700 Subject: [PATCH 1/2] Remove unnecessary property default values --- src/Cache/QueryCacheProfile.php | 2 +- src/Logging/LoggerChain.php | 2 +- src/Platforms/Keywords/ReservedKeywordsValidator.php | 2 +- src/Schema/Index.php | 2 +- src/Schema/UniqueConstraint.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Cache/QueryCacheProfile.php b/src/Cache/QueryCacheProfile.php index 3d5b814d2b7..44f5868cf93 100644 --- a/src/Cache/QueryCacheProfile.php +++ b/src/Cache/QueryCacheProfile.php @@ -20,7 +20,7 @@ class QueryCacheProfile private $resultCacheDriver; /** @var int */ - private $lifetime = 0; + private $lifetime; /** @var string|null */ private $cacheKey; diff --git a/src/Logging/LoggerChain.php b/src/Logging/LoggerChain.php index 27b8516e480..9b44dc0e3e8 100644 --- a/src/Logging/LoggerChain.php +++ b/src/Logging/LoggerChain.php @@ -8,7 +8,7 @@ class LoggerChain implements SQLLogger { /** @var iterable */ - private $loggers = []; + private $loggers; /** * @param iterable $loggers diff --git a/src/Platforms/Keywords/ReservedKeywordsValidator.php b/src/Platforms/Keywords/ReservedKeywordsValidator.php index ff03432e1e4..a6da77463ef 100644 --- a/src/Platforms/Keywords/ReservedKeywordsValidator.php +++ b/src/Platforms/Keywords/ReservedKeywordsValidator.php @@ -17,7 +17,7 @@ class ReservedKeywordsValidator implements Visitor { /** @var KeywordList[] */ - private $keywordLists = []; + private $keywordLists; /** @var string[] */ private $violations = []; diff --git a/src/Schema/Index.php b/src/Schema/Index.php index 947ec896af6..508aa4031e9 100644 --- a/src/Schema/Index.php +++ b/src/Schema/Index.php @@ -43,7 +43,7 @@ class Index extends AbstractAsset implements Constraint * @todo $_flags should eventually be refactored into options * @var mixed[] */ - private $options = []; + private $options; /** * @param string $name diff --git a/src/Schema/UniqueConstraint.php b/src/Schema/UniqueConstraint.php index 87a5f6e3b21..cb91becb20d 100644 --- a/src/Schema/UniqueConstraint.php +++ b/src/Schema/UniqueConstraint.php @@ -34,7 +34,7 @@ class UniqueConstraint extends AbstractAsset implements Constraint * * @var mixed[] */ - private $options = []; + private $options; /** * @param string[] $columns From ab2849f2a785b12565c2904e823597725fefa217 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 31 Jul 2021 10:21:52 -0700 Subject: [PATCH 2/2] Remove unused local variables --- src/Connection.php | 2 +- src/Driver/IBMDB2/Statement.php | 2 +- src/Schema/PostgreSQLSchemaManager.php | 7 +-- src/Tools/Dumper.php | 3 +- tests/Cache/QueryCacheProfileTest.php | 2 +- .../PrimaryReadReplicaConnectionTest.php | 4 +- tests/Functional/ResultCacheTest.php | 6 +- .../Schema/MySQLSchemaManagerTest.php | 2 +- .../Schema/PostgreSQLSchemaManagerTest.php | 6 +- tests/Platforms/AbstractPlatformTestCase.php | 16 ++--- .../AbstractPostgreSQLPlatformTestCase.php | 4 +- tests/Platforms/OraclePlatformTest.php | 2 - tests/Query/QueryBuilderTest.php | 60 +++++++------------ tests/Schema/ComparatorTest.php | 4 +- tests/Schema/SchemaTest.php | 4 +- tests/Schema/TableTest.php | 6 +- 16 files changed, 50 insertions(+), 80 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index 160cd6405f4..46648423408 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -760,7 +760,7 @@ private function extractTypeValues(array $columnList, array $types) { $typeValues = []; - foreach ($columnList as $columnIndex => $columnName) { + foreach ($columnList as $columnName) { $typeValues[] = $types[$columnName] ?? ParameterType::STRING; } diff --git a/src/Driver/IBMDB2/Statement.php b/src/Driver/IBMDB2/Statement.php index 1820a73526d..c655ea74a6f 100644 --- a/src/Driver/IBMDB2/Statement.php +++ b/src/Driver/IBMDB2/Statement.php @@ -125,7 +125,7 @@ public function execute($params = null): ResultInterface $params = []; - foreach ($this->bindParam as $column => $value) { + foreach ($this->bindParam as $value) { $params[] = $value; } } diff --git a/src/Schema/PostgreSQLSchemaManager.php b/src/Schema/PostgreSQLSchemaManager.php index 808b629a6df..e353b53e6b7 100644 --- a/src/Schema/PostgreSQLSchemaManager.php +++ b/src/Schema/PostgreSQLSchemaManager.php @@ -133,11 +133,8 @@ public function determineExistingSchemaSearchPaths() */ protected function _getPortableTableForeignKeyDefinition($tableForeignKey) { - $onUpdate = null; - $onDelete = null; - $localColumns = []; - $foreignColumns = []; - $foreignTable = null; + $onUpdate = null; + $onDelete = null; if ( preg_match( diff --git a/src/Tools/Dumper.php b/src/Tools/Dumper.php index c1e72aa3752..23dc7a059f4 100644 --- a/src/Tools/Dumper.php +++ b/src/Tools/Dumper.php @@ -86,8 +86,7 @@ public static function dump($var, int $maxDepth = 2): string */ public static function export($var, int $maxDepth) { - $return = null; - $isObj = is_object($var); + $isObj = is_object($var); if ($var instanceof Collection) { $var = $var->toArray(); diff --git a/tests/Cache/QueryCacheProfileTest.php b/tests/Cache/QueryCacheProfileTest.php index 54e0820d0b5..8ae1e142abd 100644 --- a/tests/Cache/QueryCacheProfileTest.php +++ b/tests/Cache/QueryCacheProfileTest.php @@ -98,7 +98,7 @@ public function testConnectionParamsShouldBeHashed(): void { $this->queryCacheProfile = $this->queryCacheProfile->setCacheKey(null); - [$cacheKey, $queryString] = $this->queryCacheProfile->generateCacheKeys( + [, $queryString] = $this->queryCacheProfile->generateCacheKeys( $this->query, $this->params, $this->types, diff --git a/tests/Functional/PrimaryReadReplicaConnectionTest.php b/tests/Functional/PrimaryReadReplicaConnectionTest.php index 9127c7ad97a..a7d09ffb372 100644 --- a/tests/Functional/PrimaryReadReplicaConnectionTest.php +++ b/tests/Functional/PrimaryReadReplicaConnectionTest.php @@ -140,7 +140,7 @@ public function testPrimaryOnWriteOperation(): void public function testKeepReplicaBeginTransactionStaysOnPrimary(): void { - $conn = $this->createPrimaryReadReplicaConnection($keepReplica = true); + $conn = $this->createPrimaryReadReplicaConnection(true); $conn->ensureConnectedToReplica(); $conn->beginTransaction(); @@ -158,7 +158,7 @@ public function testKeepReplicaBeginTransactionStaysOnPrimary(): void public function testKeepReplicaInsertStaysOnPrimary(): void { - $conn = $this->createPrimaryReadReplicaConnection($keepReplica = true); + $conn = $this->createPrimaryReadReplicaConnection(true); $conn->ensureConnectedToReplica(); $conn->insert('primary_replica_table', ['test_int' => 30]); diff --git a/tests/Functional/ResultCacheTest.php b/tests/Functional/ResultCacheTest.php index 67c50b6ec93..444fdf49518 100644 --- a/tests/Functional/ResultCacheTest.php +++ b/tests/Functional/ResultCacheTest.php @@ -171,8 +171,7 @@ public function testFetchAndFinishSavesCache(): void new QueryCacheProfile(0, 'testcachekey') ); - while (($row = $result->fetchAssociative()) !== false) { - } + $result->fetchAllAssociative(); $result = $this->connection->executeQuery( 'SELECT * FROM caching ORDER BY test_int ASC', @@ -181,8 +180,7 @@ public function testFetchAndFinishSavesCache(): void new QueryCacheProfile(0, 'testcachekey') ); - while (($row = $result->fetchNumeric()) !== false) { - } + $result->fetchAllNumeric(); self::assertCount(1, $this->sqlLogger->queries); } diff --git a/tests/Functional/Schema/MySQLSchemaManagerTest.php b/tests/Functional/Schema/MySQLSchemaManagerTest.php index 255823e8abd..ad149b850a0 100644 --- a/tests/Functional/Schema/MySQLSchemaManagerTest.php +++ b/tests/Functional/Schema/MySQLSchemaManagerTest.php @@ -280,7 +280,7 @@ public function testColumnCharsetChange(): void public function testColumnCollation(): void { $table = new Table('test_collation'); - $table->addOption('collate', $collation = 'latin1_swedish_ci'); + $table->addOption('collate', 'latin1_swedish_ci'); $table->addOption('charset', 'latin1'); $table->addColumn('id', 'integer'); $table->addColumn('text', 'text'); diff --git a/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php b/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php index db8aa158f28..0b9a66be430 100644 --- a/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php +++ b/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php @@ -84,7 +84,7 @@ public function testDetectsAutoIncrement(): void public function testAlterTableAutoIncrementAdd(): void { $tableFrom = new Table('autoinc_table_add'); - $column = $tableFrom->addColumn('id', 'integer'); + $tableFrom->addColumn('id', 'integer'); $this->schemaManager->createTable($tableFrom); $tableFrom = $this->schemaManager->listTableDetails('autoinc_table_add'); self::assertFalse($tableFrom->getColumn('id')->getAutoincrement()); @@ -192,10 +192,10 @@ public function testReturnQuotedAssets(): void public function testFilterSchemaExpression(): void { $testTable = new Table('dbal204_test_prefix'); - $column = $testTable->addColumn('id', 'integer'); + $testTable->addColumn('id', 'integer'); $this->schemaManager->createTable($testTable); $testTable = new Table('dbal204_without_prefix'); - $column = $testTable->addColumn('id', 'integer'); + $testTable->addColumn('id', 'integer'); $this->schemaManager->createTable($testTable); $this->connection->getConfiguration()->setSchemaAssetsFilter(static function (string $name): bool { diff --git a/tests/Platforms/AbstractPlatformTestCase.php b/tests/Platforms/AbstractPlatformTestCase.php index 520fcc7255b..b8659172295 100644 --- a/tests/Platforms/AbstractPlatformTestCase.php +++ b/tests/Platforms/AbstractPlatformTestCase.php @@ -156,7 +156,7 @@ public function testCreateWithNoColumns(): void $table = new Table('test'); $this->expectException(Exception::class); - $sql = $this->platform->getCreateTableSQL($table); + $this->platform->getCreateTableSQL($table); } public function testGeneratesTableCreationSql(): void @@ -218,22 +218,22 @@ public function testGeneratesPartialIndexesSqlOnlyWhenSupportingPartialIndexes() $expected = ' WHERE ' . $where; - $actuals = []; + $indexes = []; if ($this->supportsInlineIndexDeclaration()) { - $actuals[] = $this->platform->getIndexDeclarationSQL('name', $indexDef); + $indexes[] = $this->platform->getIndexDeclarationSQL('name', $indexDef); } $uniqueConstraintSQL = $this->platform->getUniqueConstraintDeclarationSQL('name', $uniqueConstraint); - $indexSQL = $this->platform->getCreateIndexSQL($indexDef, 'table'); - $this->assertStringEndsNotWith($expected, $uniqueConstraintSQL, 'WHERE clause should NOT be present'); - foreach ($actuals as $actual) { + $indexes[] = $this->platform->getCreateIndexSQL($indexDef, 'table'); + + foreach ($indexes as $index) { if ($this->platform->supportsPartialIndexes()) { - self::assertStringEndsWith($expected, $indexSQL, 'WHERE clause should be present'); + self::assertStringEndsWith($expected, $index, 'WHERE clause should be present'); } else { - self::assertStringEndsNotWith($expected, $indexSQL, 'WHERE clause should NOT be present'); + self::assertStringEndsNotWith($expected, $index, 'WHERE clause should NOT be present'); } } } diff --git a/tests/Platforms/AbstractPostgreSQLPlatformTestCase.php b/tests/Platforms/AbstractPostgreSQLPlatformTestCase.php index de1645c9fa3..513cebdb40a 100644 --- a/tests/Platforms/AbstractPostgreSQLPlatformTestCase.php +++ b/tests/Platforms/AbstractPostgreSQLPlatformTestCase.php @@ -442,9 +442,7 @@ protected function getQuotedColumnInForeignKeySQL(): array */ public function testConvertBooleanAsLiteralStrings( $databaseValue, - string $preparedStatementValue, - ?int $integerValue, - ?bool $booleanValue + string $preparedStatementValue ): void { $platform = $this->createPlatform(); diff --git a/tests/Platforms/OraclePlatformTest.php b/tests/Platforms/OraclePlatformTest.php index 7c9264b689a..6eb310756ac 100644 --- a/tests/Platforms/OraclePlatformTest.php +++ b/tests/Platforms/OraclePlatformTest.php @@ -575,8 +575,6 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType(): vo $table2->addColumn('column_varbinary', 'binary', ['fixed' => true]); $table2->addColumn('column_binary', 'binary'); - $comparator = new Comparator(); - // VARBINARY -> BINARY // BINARY -> VARBINARY $diff = (new Comparator())->diffTable($table1, $table2); diff --git a/tests/Query/QueryBuilderTest.php b/tests/Query/QueryBuilderTest.php index 714e43eb7b5..19bb2a61c5e 100644 --- a/tests/Query/QueryBuilderTest.php +++ b/tests/Query/QueryBuilderTest.php @@ -132,8 +132,7 @@ public function testSelectWithRightJoin(): void public function testSelectWithAndWhereConditions(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*', 'p.*') ->from('users', 'u') @@ -145,8 +144,7 @@ public function testSelectWithAndWhereConditions(): void public function testSelectWithOrWhereConditions(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*', 'p.*') ->from('users', 'u') @@ -158,8 +156,7 @@ public function testSelectWithOrWhereConditions(): void public function testSelectWithOrOrWhereConditions(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*', 'p.*') ->from('users', 'u') @@ -171,8 +168,7 @@ public function testSelectWithOrOrWhereConditions(): void public function testSelectWithAndOrWhereConditions(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*', 'p.*') ->from('users', 'u') @@ -190,8 +186,7 @@ public function testSelectWithAndOrWhereConditions(): void public function testSelectGroupBy(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*', 'p.*') ->from('users', 'u') @@ -202,8 +197,7 @@ public function testSelectGroupBy(): void public function testSelectEmptyGroupBy(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*', 'p.*') ->groupBy([]) @@ -214,8 +208,7 @@ public function testSelectEmptyGroupBy(): void public function testSelectEmptyAddGroupBy(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*', 'p.*') ->addGroupBy([]) @@ -226,8 +219,7 @@ public function testSelectEmptyAddGroupBy(): void public function testSelectAddGroupBy(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*', 'p.*') ->from('users', 'u') @@ -239,8 +231,7 @@ public function testSelectAddGroupBy(): void public function testSelectAddGroupBys(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*', 'p.*') ->from('users', 'u') @@ -252,8 +243,7 @@ public function testSelectAddGroupBys(): void public function testSelectHaving(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*', 'p.*') ->from('users', 'u') @@ -265,8 +255,7 @@ public function testSelectHaving(): void public function testSelectAndHaving(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*', 'p.*') ->from('users', 'u') @@ -278,8 +267,7 @@ public function testSelectAndHaving(): void public function testSelectHavingAndHaving(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*', 'p.*') ->from('users', 'u') @@ -295,8 +283,7 @@ public function testSelectHavingAndHaving(): void public function testSelectHavingOrHaving(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*', 'p.*') ->from('users', 'u') @@ -312,8 +299,7 @@ public function testSelectHavingOrHaving(): void public function testSelectOrHavingOrHaving(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*', 'p.*') ->from('users', 'u') @@ -329,8 +315,7 @@ public function testSelectOrHavingOrHaving(): void public function testSelectHavingAndOrHaving(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*', 'p.*') ->from('users', 'u') @@ -347,8 +332,7 @@ public function testSelectHavingAndOrHaving(): void public function testSelectOrderBy(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*', 'p.*') ->from('users', 'u') @@ -359,8 +343,7 @@ public function testSelectOrderBy(): void public function testSelectAddOrderBy(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*', 'p.*') ->from('users', 'u') @@ -372,8 +355,7 @@ public function testSelectAddOrderBy(): void public function testSelectAddAddOrderBy(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*', 'p.*') ->from('users', 'u') @@ -394,8 +376,7 @@ public function testEmptySelect(): void public function testSelectAddSelect(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*') ->addSelect('p.*') @@ -415,8 +396,7 @@ public function testEmptyAddSelect(): void public function testSelectMultipleFrom(): void { - $qb = new QueryBuilder($this->conn); - $expr = $qb->expr(); + $qb = new QueryBuilder($this->conn); $qb->select('u.*') ->addSelect('p.*') diff --git a/tests/Schema/ComparatorTest.php b/tests/Schema/ComparatorTest.php index eff00266630..5b73e2de864 100644 --- a/tests/Schema/ComparatorTest.php +++ b/tests/Schema/ComparatorTest.php @@ -845,8 +845,8 @@ public function testDiff(): void public function testChangedSequence(): void { - $schema = new Schema(); - $sequence = $schema->createSequence('baz'); + $schema = new Schema(); + $schema->createSequence('baz'); $schemaNew = clone $schema; $schemaNew->getSequence('baz')->setAllocationSize(20); diff --git a/tests/Schema/SchemaTest.php b/tests/Schema/SchemaTest.php index 5fbbd4ee096..2fdf23cb9cc 100644 --- a/tests/Schema/SchemaTest.php +++ b/tests/Schema/SchemaTest.php @@ -62,7 +62,7 @@ public function testCreateTableTwiceThrowsException(): void $table = new Table($tableName); $tables = [$table, $table]; - $schema = new Schema($tables); + new Schema($tables); } public function testRenameTable(): void @@ -171,7 +171,7 @@ public function testAddSequenceTwiceThrowsException(): void $sequence = new Sequence('a_seq', 1, 1); - $schema = new Schema([], [$sequence, $sequence]); + new Schema([], [$sequence, $sequence]); } public function testConfigMaxIdentifierLength(): void diff --git a/tests/Schema/TableTest.php b/tests/Schema/TableTest.php index 60ecafba63e..c3c5955881d 100644 --- a/tests/Schema/TableTest.php +++ b/tests/Schema/TableTest.php @@ -108,7 +108,7 @@ public function testAddColumnTwiceThrowsException(): void $columns = []; $columns[] = new Column('foo', $type); $columns[] = new Column('foo', $type); - $table = new Table('foo', $columns, [], []); + new Table('foo', $columns, [], []); } public function testCreateIndex(): void @@ -181,7 +181,7 @@ public function testAddTwoPrimaryThrowsException(): void new Index('the_primary', ['foo'], true, true), new Index('other_primary', ['bar'], true, true), ]; - $table = new Table('foo', $columns, $indexes, [], []); + new Table('foo', $columns, $indexes, [], []); } public function testAddTwoIndexesWithSameNameThrowsException(): void @@ -194,7 +194,7 @@ public function testAddTwoIndexesWithSameNameThrowsException(): void new Index('an_idx', ['foo'], false, false), new Index('an_idx', ['bar'], false, false), ]; - $table = new Table('foo', $columns, $indexes, [], []); + new Table('foo', $columns, $indexes, [], []); } public function testConstraints(): void