diff --git a/src/PdoAdapter.php b/src/PdoAdapter.php index 8a5c340..62e486a 100644 --- a/src/PdoAdapter.php +++ b/src/PdoAdapter.php @@ -34,7 +34,7 @@ class PdoAdapter extends PDO public function __construct($dsn, $username, $password, $driver_options = []) { // Windows OS paths with backslashes should be changed - $dsn = str_replace("\\", "/", $dsn); + $dsn = str_replace('\\', '/', $dsn); // apply error mode $driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; // lower case column names in results are necessary for Yii ActiveRecord proper functioning @@ -58,7 +58,7 @@ public function beginTransaction($isolationLevel = null) } if ($isolationLevel === null) { - $r = $this->exec("SET TRANSACTION"); + $r = $this->exec('SET TRANSACTION'); $success = ($r !== false); if ($success) { $this->_inTransaction = true; @@ -80,7 +80,7 @@ public function beginTransaction($isolationLevel = null) */ public function commit() { - $r = $this->exec("COMMIT"); + $r = $this->exec('COMMIT'); $this->setAttribute(PDO::ATTR_AUTOCOMMIT, true); $success = ($r !== false); if ($success) { @@ -95,7 +95,7 @@ public function commit() */ public function rollBack() { - $r = $this->exec("ROLLBACK"); + $r = $this->exec('ROLLBACK'); $this->setAttribute(PDO::ATTR_AUTOCOMMIT, true); $success = ($r !== false); if ($success) { diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 8e18a6b..ba06a21 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -107,7 +107,7 @@ public function buildSelect($columns, &$params, $distinct = false, $selectOption continue; } $matches = []; - if (preg_match("/^(COUNT|SUM|AVG|MIN|MAX)\([\{\[]{0,2}(\w+|\*)[\}\]]{0,2}\)$/i", $column, $matches)) { + if (preg_match('/^(COUNT|SUM|AVG|MIN|MAX)\([\{\[]{0,2}(\w+|\*)[\}\]]{0,2}\)$/i', $column, $matches)) { $function = $matches[1]; $alias = $matches[2] != '*' ? $matches[2] : 'ALL'; @@ -246,10 +246,10 @@ public function insert($table, $columns, &$params) } //Empty insert - if(empty($columns) && !empty($columnSchemas)){ + if (empty($columns) && !empty($columnSchemas)) { $columns = []; foreach ($columnSchemas as $columnSchema) { - if(!$columnSchema->autoIncrement){ + if (!$columnSchema->autoIncrement) { $columns[$columnSchema->name] = $columnSchema->defaultValue; } } @@ -343,7 +343,7 @@ public function renameTable($oldName, $newName) */ public function truncateTable($table) { - return "DELETE FROM " . $this->db->quoteTableName($table); + return 'DELETE FROM ' . $this->db->quoteTableName($table); } /** @@ -351,8 +351,8 @@ public function truncateTable($table) */ public function dropColumn($table, $column) { - return "ALTER TABLE " . $this->db->quoteTableName($table) - . " DROP " . $this->db->quoteColumnName($column); + return 'ALTER TABLE ' . $this->db->quoteTableName($table) + . ' DROP ' . $this->db->quoteColumnName($column); } /** @@ -360,9 +360,9 @@ public function dropColumn($table, $column) */ public function renameColumn($table, $oldName, $newName) { - return "ALTER TABLE " . $this->db->quoteTableName($table) - . " ALTER " . $this->db->quoteColumnName($oldName) - . " TO " . $this->db->quoteColumnName($newName); + return 'ALTER TABLE ' . $this->db->quoteTableName($table) + . ' ALTER ' . $this->db->quoteColumnName($oldName) + . ' TO ' . $this->db->quoteColumnName($newName); } /** @@ -374,9 +374,9 @@ public function alterColumn($table, $column, $type) $tableSchema = $schema->getTableSchema($table); $columnSchema = $tableSchema->getColumn($column); - $allowNullNewType = !preg_match("/not +null/i", $type); + $allowNullNewType = !preg_match('/not +null/i', $type); - $type = preg_replace("/ +(not)? *null/i", "", $type); + $type = preg_replace('/ +(not)? *null/i', '', $type); $hasType = false; @@ -439,7 +439,7 @@ public function resetSequence($table, $value = null) $value = (int) $value; } else { // use master connection to get the biggest PK value - $value = $this->db->useMaster(function(Connection $db) use ($tableSchema) { + $value = $this->db->useMaster(function (Connection $db) use ($tableSchema) { $key = false; foreach ($tableSchema->primaryKey as $name) { if ($tableSchema->columns[$name]->autoIncrement) { @@ -515,7 +515,6 @@ public function dropTable($table) END; SQL; return $sqlBlock; - } /** diff --git a/src/Schema.php b/src/Schema.php index 9f41e20..8d0a0f7 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -204,10 +204,10 @@ protected function findColumns($table) } catch (Exception $e) { return false; } - $pkeys = array_map("rtrim", $pkeys); - $pkeys = array_map("strtolower", $pkeys); + $pkeys = array_map('rtrim', $pkeys); + $pkeys = array_map('strtolower', $pkeys); foreach ($columns as $key => $column) { - $column = array_map("strtolower", $column); + $column = array_map('strtolower', $column); $columns[$key]['fprimary'] = in_array(rtrim($column['fname']), $pkeys); } foreach ($columns as $column) { @@ -266,7 +266,7 @@ protected function loadColumnSchema($column) if ($defaultValue === null) { $defaultValue = $column['fdefault_value']; } - $dbType = ""; + $dbType = ''; $baseTypes = [ 7 => 'SMALLINT', 8 => 'INTEGER', @@ -399,8 +399,8 @@ protected function findConstraints($table) foreach ($fkeys as $fkey) { // Zoggo - Added strtolower here to guarantee that values are // returned lower case. Otherwise gii generates wrong code. - $fkey = array_map("rtrim", $fkey); - $fkey = array_map("strtolower", $fkey); + $fkey = array_map('rtrim', $fkey); + $fkey = array_map('strtolower', $fkey); if (!isset($constraints[$fkey['fconstraint']])) { $constraints[$fkey['fconstraint']] = [ diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php index a01b59e..b57bd82 100644 --- a/tests/ActiveRecordTest.php +++ b/tests/ActiveRecordTest.php @@ -28,10 +28,11 @@ public function testPopulateWithoutPk() $this->markTestSkipped(); } - public function testCastValues() { + public function testCastValues() + { if (version_compare(phpversion('pdo_firebird'), '7.0.13', '<=')) { $this->markTestSkipped('BLOB bug for PHP <= 7.0.13, see https://bugs.php.net/bug.php?id=61183'); - } + } parent::testCastValues(); } } diff --git a/tests/ColumnSchemaBuilderTest.php b/tests/ColumnSchemaBuilderTest.php index bf27bd1..56b2843 100644 --- a/tests/ColumnSchemaBuilderTest.php +++ b/tests/ColumnSchemaBuilderTest.php @@ -27,7 +27,8 @@ public function getColumnSchemaBuilder($type, $length = null) /** * @return array */ - public function typesProvider() { + public function typesProvider() + { $parent = parent::typesProvider(); $parent[0][0] = 'integer DEFAULT NULL NULL'; diff --git a/tests/CommandTest.php b/tests/CommandTest.php index c0b32b8..7acd519 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -21,7 +21,7 @@ public function testAutoQuoting() $sql = 'SELECT [[id]], [[t.name]] FROM {{customer}} t'; $command = $db->createCommand($sql); - $this->assertEquals("SELECT id, t.name FROM customer t", $command->sql); + $this->assertEquals('SELECT id, t.name FROM customer t', $command->sql); } public function testColumnCase() @@ -57,7 +57,7 @@ public function testBindParamValue() { if (version_compare(phpversion('pdo_firebird'), '7.0.13', '<=')) { $this->markTestSkipped('BLOB bug for PHP <= 7.0.13, see https://bugs.php.net/bug.php?id=61183'); - } + } $db = $this->getConnection(); diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 31d07c4..9f35c96 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -159,7 +159,7 @@ public function testAddDropPrimaryKey() public function testBuildUnion() { $expectedQuerySql = $this->replaceQuotes( - "SELECT [[id]] FROM [[TotalExample]] [[t1]] WHERE (w > 0) AND (x < 2) UNION SELECT [[id]] FROM [[TotalTotalExample]] [[t2]] WHERE w > 5 UNION ALL SELECT [[id]] FROM [[TotalTotalExample]] [[t3]] WHERE w = 3" + 'SELECT [[id]] FROM [[TotalExample]] [[t1]] WHERE (w > 0) AND (x < 2) UNION SELECT [[id]] FROM [[TotalTotalExample]] [[t2]] WHERE w > 5 UNION ALL SELECT [[id]] FROM [[TotalTotalExample]] [[t3]] WHERE w = 3' ); $query = new Query(); $secondQuery = new Query(); @@ -174,7 +174,7 @@ public function testBuildUnion() ->from('TotalExample t1') ->where(['and', 'w > 0', 'x < 2']) ->union($secondQuery) - ->union($thirdQuery, TRUE); + ->union($thirdQuery, true); list($actualQuerySql, $queryParams) = $this->getQueryBuilder()->build($query); $this->assertEquals($expectedQuerySql, $actualQuerySql); $this->assertEquals([], $queryParams); @@ -245,13 +245,13 @@ public function testRenameColumn() $columns = $connection->getTableSchema('type', true)->columnNames; foreach ($columns as $column) { - $connection->createCommand($qb->renameColumn('type', $column, $column.'_new'))->execute(); + $connection->createCommand($qb->renameColumn('type', $column, $column . '_new'))->execute(); } $schema = $connection->getTableSchema('type', true); foreach ($columns as $column) { $this->assertNotContains($column, $schema->columnNames); - $this->assertContains($column.'_new', $schema->columnNames); + $this->assertContains($column . '_new', $schema->columnNames); } } @@ -262,7 +262,7 @@ public function testAlterColumn() $connection->createCommand($qb->alterColumn('customer', 'email', Schema::TYPE_STRING . '(128) NULL'))->execute(); $connection->createCommand($qb->alterColumn('customer', 'name', "SET DEFAULT 'NO NAME'"))->execute(); - $connection->createCommand($qb->alterColumn('customer', 'name', Schema::TYPE_STRING . "(128) NOT NULL"))->execute(); + $connection->createCommand($qb->alterColumn('customer', 'name', Schema::TYPE_STRING . '(128) NOT NULL'))->execute(); $connection->createCommand($qb->alterColumn('customer', 'profile_id', Schema::TYPE_INTEGER . ' NOT NULL'))->execute(); $newColumns = $connection->getTableSchema('customer', true)->columns; @@ -367,7 +367,7 @@ public function testCommentColumn() $sql = $qb->addCommentOnColumn('comment', 'replace_comment', 'This is my column.'); $this->assertEquals($expected, $sql); - $expected = $this->replaceQuotes("COMMENT ON COLUMN [[comment]].[[delete_comment]] IS NULL"); + $expected = $this->replaceQuotes('COMMENT ON COLUMN [[comment]].[[delete_comment]] IS NULL'); $sql = $qb->dropCommentFromColumn('comment', 'delete_comment'); $this->assertEquals($expected, $sql); } @@ -380,7 +380,7 @@ public function testCommentTable() $sql = $qb->addCommentOnTable('comment', 'This is my table.'); $this->assertEquals($expected, $sql); - $expected = $this->replaceQuotes("COMMENT ON TABLE [[comment]] IS NULL"); + $expected = $this->replaceQuotes('COMMENT ON TABLE [[comment]] IS NULL'); $sql = $qb->dropCommentFromTable('comment'); $this->assertEquals($expected, $sql); } @@ -388,17 +388,17 @@ public function testCommentTable() public function testReplaceQuotes() { //Normal words - $this->assertEquals('comment', $this->replaceQuotes("[[comment]]")); - $this->assertEquals('test', $this->replaceQuotes("[[test]]")); + $this->assertEquals('comment', $this->replaceQuotes('[[comment]]')); + $this->assertEquals('test', $this->replaceQuotes('[[test]]')); //Reserved Words lower case - $this->assertEquals('"order"', $this->replaceQuotes("[[order]]")); - $this->assertEquals('"time"', $this->replaceQuotes("[[time]]")); + $this->assertEquals('"order"', $this->replaceQuotes('[[order]]')); + $this->assertEquals('"time"', $this->replaceQuotes('[[time]]')); //Reserved Words UPPER CASE - $this->assertEquals('"ORDER"', $this->replaceQuotes("[[ORDER]]")); - $this->assertEquals('"TIME"', $this->replaceQuotes("[[TIME]]")); + $this->assertEquals('"ORDER"', $this->replaceQuotes('[[ORDER]]')); + $this->assertEquals('"TIME"', $this->replaceQuotes('[[TIME]]')); //Reserved Words Multiple - $this->assertEquals('"order".comment', $this->replaceQuotes("[[order]].[[comment]]")); - $this->assertEquals('"order"."time"', $this->replaceQuotes("[[order]].[[time]]")); + $this->assertEquals('"order".comment', $this->replaceQuotes('[[order]].[[comment]]')); + $this->assertEquals('"order"."time"', $this->replaceQuotes('[[order]].[[time]]')); } }