Skip to content

Commit

Permalink
Fixed Yii2 Coding Standards;
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Nov 9, 2016
1 parent 5886177 commit 8893a3f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 43 deletions.
8 changes: 4 additions & 4 deletions src/PdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
25 changes: 12 additions & 13 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -343,26 +343,26 @@ public function renameTable($oldName, $newName)
*/
public function truncateTable($table)
{
return "DELETE FROM " . $this->db->quoteTableName($table);
return 'DELETE FROM ' . $this->db->quoteTableName($table);
}

/**
* @inheritdoc
*/
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);
}

/**
* @inheritdoc
*/
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);
}

/**
Expand All @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -515,7 +515,6 @@ public function dropTable($table)
END;
SQL;
return $sqlBlock;

}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -266,7 +266,7 @@ protected function loadColumnSchema($column)
if ($defaultValue === null) {
$defaultValue = $column['fdefault_value'];
}
$dbType = "";
$dbType = '';
$baseTypes = [
7 => 'SMALLINT',
8 => 'INTEGER',
Expand Down Expand Up @@ -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']] = [
Expand Down
5 changes: 3 additions & 2 deletions tests/ActiveRecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
3 changes: 2 additions & 1 deletion tests/ColumnSchemaBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();

Expand Down
30 changes: 15 additions & 15 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -380,25 +380,25 @@ 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);
}

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]]'));
}
}

0 comments on commit 8893a3f

Please sign in to comment.