Skip to content

Commit 8893a3f

Browse files
committed
Fixed Yii2 Coding Standards;
1 parent 5886177 commit 8893a3f

File tree

7 files changed

+44
-43
lines changed

7 files changed

+44
-43
lines changed

src/PdoAdapter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class PdoAdapter extends PDO
3434
public function __construct($dsn, $username, $password, $driver_options = [])
3535
{
3636
// Windows OS paths with backslashes should be changed
37-
$dsn = str_replace("\\", "/", $dsn);
37+
$dsn = str_replace('\\', '/', $dsn);
3838
// apply error mode
3939
$driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
4040
// lower case column names in results are necessary for Yii ActiveRecord proper functioning
@@ -58,7 +58,7 @@ public function beginTransaction($isolationLevel = null)
5858
}
5959

6060
if ($isolationLevel === null) {
61-
$r = $this->exec("SET TRANSACTION");
61+
$r = $this->exec('SET TRANSACTION');
6262
$success = ($r !== false);
6363
if ($success) {
6464
$this->_inTransaction = true;
@@ -80,7 +80,7 @@ public function beginTransaction($isolationLevel = null)
8080
*/
8181
public function commit()
8282
{
83-
$r = $this->exec("COMMIT");
83+
$r = $this->exec('COMMIT');
8484
$this->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
8585
$success = ($r !== false);
8686
if ($success) {
@@ -95,7 +95,7 @@ public function commit()
9595
*/
9696
public function rollBack()
9797
{
98-
$r = $this->exec("ROLLBACK");
98+
$r = $this->exec('ROLLBACK');
9999
$this->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
100100
$success = ($r !== false);
101101
if ($success) {

src/QueryBuilder.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function buildSelect($columns, &$params, $distinct = false, $selectOption
107107
continue;
108108
}
109109
$matches = [];
110-
if (preg_match("/^(COUNT|SUM|AVG|MIN|MAX)\([\{\[]{0,2}(\w+|\*)[\}\]]{0,2}\)$/i", $column, $matches)) {
110+
if (preg_match('/^(COUNT|SUM|AVG|MIN|MAX)\([\{\[]{0,2}(\w+|\*)[\}\]]{0,2}\)$/i', $column, $matches)) {
111111
$function = $matches[1];
112112
$alias = $matches[2] != '*' ? $matches[2] : 'ALL';
113113

@@ -246,10 +246,10 @@ public function insert($table, $columns, &$params)
246246
}
247247

248248
//Empty insert
249-
if(empty($columns) && !empty($columnSchemas)){
249+
if (empty($columns) && !empty($columnSchemas)) {
250250
$columns = [];
251251
foreach ($columnSchemas as $columnSchema) {
252-
if(!$columnSchema->autoIncrement){
252+
if (!$columnSchema->autoIncrement) {
253253
$columns[$columnSchema->name] = $columnSchema->defaultValue;
254254
}
255255
}
@@ -343,26 +343,26 @@ public function renameTable($oldName, $newName)
343343
*/
344344
public function truncateTable($table)
345345
{
346-
return "DELETE FROM " . $this->db->quoteTableName($table);
346+
return 'DELETE FROM ' . $this->db->quoteTableName($table);
347347
}
348348

349349
/**
350350
* @inheritdoc
351351
*/
352352
public function dropColumn($table, $column)
353353
{
354-
return "ALTER TABLE " . $this->db->quoteTableName($table)
355-
. " DROP " . $this->db->quoteColumnName($column);
354+
return 'ALTER TABLE ' . $this->db->quoteTableName($table)
355+
. ' DROP ' . $this->db->quoteColumnName($column);
356356
}
357357

358358
/**
359359
* @inheritdoc
360360
*/
361361
public function renameColumn($table, $oldName, $newName)
362362
{
363-
return "ALTER TABLE " . $this->db->quoteTableName($table)
364-
. " ALTER " . $this->db->quoteColumnName($oldName)
365-
. " TO " . $this->db->quoteColumnName($newName);
363+
return 'ALTER TABLE ' . $this->db->quoteTableName($table)
364+
. ' ALTER ' . $this->db->quoteColumnName($oldName)
365+
. ' TO ' . $this->db->quoteColumnName($newName);
366366
}
367367

368368
/**
@@ -374,9 +374,9 @@ public function alterColumn($table, $column, $type)
374374
$tableSchema = $schema->getTableSchema($table);
375375
$columnSchema = $tableSchema->getColumn($column);
376376

377-
$allowNullNewType = !preg_match("/not +null/i", $type);
377+
$allowNullNewType = !preg_match('/not +null/i', $type);
378378

379-
$type = preg_replace("/ +(not)? *null/i", "", $type);
379+
$type = preg_replace('/ +(not)? *null/i', '', $type);
380380

381381
$hasType = false;
382382

@@ -439,7 +439,7 @@ public function resetSequence($table, $value = null)
439439
$value = (int) $value;
440440
} else {
441441
// use master connection to get the biggest PK value
442-
$value = $this->db->useMaster(function(Connection $db) use ($tableSchema) {
442+
$value = $this->db->useMaster(function (Connection $db) use ($tableSchema) {
443443
$key = false;
444444
foreach ($tableSchema->primaryKey as $name) {
445445
if ($tableSchema->columns[$name]->autoIncrement) {
@@ -515,7 +515,6 @@ public function dropTable($table)
515515
END;
516516
SQL;
517517
return $sqlBlock;
518-
519518
}
520519

521520
/**

src/Schema.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ protected function findColumns($table)
204204
} catch (Exception $e) {
205205
return false;
206206
}
207-
$pkeys = array_map("rtrim", $pkeys);
208-
$pkeys = array_map("strtolower", $pkeys);
207+
$pkeys = array_map('rtrim', $pkeys);
208+
$pkeys = array_map('strtolower', $pkeys);
209209
foreach ($columns as $key => $column) {
210-
$column = array_map("strtolower", $column);
210+
$column = array_map('strtolower', $column);
211211
$columns[$key]['fprimary'] = in_array(rtrim($column['fname']), $pkeys);
212212
}
213213
foreach ($columns as $column) {
@@ -266,7 +266,7 @@ protected function loadColumnSchema($column)
266266
if ($defaultValue === null) {
267267
$defaultValue = $column['fdefault_value'];
268268
}
269-
$dbType = "";
269+
$dbType = '';
270270
$baseTypes = [
271271
7 => 'SMALLINT',
272272
8 => 'INTEGER',
@@ -399,8 +399,8 @@ protected function findConstraints($table)
399399
foreach ($fkeys as $fkey) {
400400
// Zoggo - Added strtolower here to guarantee that values are
401401
// returned lower case. Otherwise gii generates wrong code.
402-
$fkey = array_map("rtrim", $fkey);
403-
$fkey = array_map("strtolower", $fkey);
402+
$fkey = array_map('rtrim', $fkey);
403+
$fkey = array_map('strtolower', $fkey);
404404

405405
if (!isset($constraints[$fkey['fconstraint']])) {
406406
$constraints[$fkey['fconstraint']] = [

tests/ActiveRecordTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ public function testPopulateWithoutPk()
2828
$this->markTestSkipped();
2929
}
3030

31-
public function testCastValues() {
31+
public function testCastValues()
32+
{
3233
if (version_compare(phpversion('pdo_firebird'), '7.0.13', '<=')) {
3334
$this->markTestSkipped('BLOB bug for PHP <= 7.0.13, see https://bugs.php.net/bug.php?id=61183');
34-
}
35+
}
3536
parent::testCastValues();
3637
}
3738
}

tests/ColumnSchemaBuilderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public function getColumnSchemaBuilder($type, $length = null)
2727
/**
2828
* @return array
2929
*/
30-
public function typesProvider() {
30+
public function typesProvider()
31+
{
3132
$parent = parent::typesProvider();
3233

3334
$parent[0][0] = 'integer DEFAULT NULL NULL';

tests/CommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testAutoQuoting()
2121

2222
$sql = 'SELECT [[id]], [[t.name]] FROM {{customer}} t';
2323
$command = $db->createCommand($sql);
24-
$this->assertEquals("SELECT id, t.name FROM customer t", $command->sql);
24+
$this->assertEquals('SELECT id, t.name FROM customer t', $command->sql);
2525
}
2626

2727
public function testColumnCase()
@@ -57,7 +57,7 @@ public function testBindParamValue()
5757
{
5858
if (version_compare(phpversion('pdo_firebird'), '7.0.13', '<=')) {
5959
$this->markTestSkipped('BLOB bug for PHP <= 7.0.13, see https://bugs.php.net/bug.php?id=61183');
60-
}
60+
}
6161

6262
$db = $this->getConnection();
6363

tests/QueryBuilderTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function testAddDropPrimaryKey()
159159
public function testBuildUnion()
160160
{
161161
$expectedQuerySql = $this->replaceQuotes(
162-
"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"
162+
'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'
163163
);
164164
$query = new Query();
165165
$secondQuery = new Query();
@@ -174,7 +174,7 @@ public function testBuildUnion()
174174
->from('TotalExample t1')
175175
->where(['and', 'w > 0', 'x < 2'])
176176
->union($secondQuery)
177-
->union($thirdQuery, TRUE);
177+
->union($thirdQuery, true);
178178
list($actualQuerySql, $queryParams) = $this->getQueryBuilder()->build($query);
179179
$this->assertEquals($expectedQuerySql, $actualQuerySql);
180180
$this->assertEquals([], $queryParams);
@@ -245,13 +245,13 @@ public function testRenameColumn()
245245
$columns = $connection->getTableSchema('type', true)->columnNames;
246246

247247
foreach ($columns as $column) {
248-
$connection->createCommand($qb->renameColumn('type', $column, $column.'_new'))->execute();
248+
$connection->createCommand($qb->renameColumn('type', $column, $column . '_new'))->execute();
249249
}
250250

251251
$schema = $connection->getTableSchema('type', true);
252252
foreach ($columns as $column) {
253253
$this->assertNotContains($column, $schema->columnNames);
254-
$this->assertContains($column.'_new', $schema->columnNames);
254+
$this->assertContains($column . '_new', $schema->columnNames);
255255
}
256256
}
257257

@@ -262,7 +262,7 @@ public function testAlterColumn()
262262

263263
$connection->createCommand($qb->alterColumn('customer', 'email', Schema::TYPE_STRING . '(128) NULL'))->execute();
264264
$connection->createCommand($qb->alterColumn('customer', 'name', "SET DEFAULT 'NO NAME'"))->execute();
265-
$connection->createCommand($qb->alterColumn('customer', 'name', Schema::TYPE_STRING . "(128) NOT NULL"))->execute();
265+
$connection->createCommand($qb->alterColumn('customer', 'name', Schema::TYPE_STRING . '(128) NOT NULL'))->execute();
266266
$connection->createCommand($qb->alterColumn('customer', 'profile_id', Schema::TYPE_INTEGER . ' NOT NULL'))->execute();
267267

268268
$newColumns = $connection->getTableSchema('customer', true)->columns;
@@ -367,7 +367,7 @@ public function testCommentColumn()
367367
$sql = $qb->addCommentOnColumn('comment', 'replace_comment', 'This is my column.');
368368
$this->assertEquals($expected, $sql);
369369

370-
$expected = $this->replaceQuotes("COMMENT ON COLUMN [[comment]].[[delete_comment]] IS NULL");
370+
$expected = $this->replaceQuotes('COMMENT ON COLUMN [[comment]].[[delete_comment]] IS NULL');
371371
$sql = $qb->dropCommentFromColumn('comment', 'delete_comment');
372372
$this->assertEquals($expected, $sql);
373373
}
@@ -380,25 +380,25 @@ public function testCommentTable()
380380
$sql = $qb->addCommentOnTable('comment', 'This is my table.');
381381
$this->assertEquals($expected, $sql);
382382

383-
$expected = $this->replaceQuotes("COMMENT ON TABLE [[comment]] IS NULL");
383+
$expected = $this->replaceQuotes('COMMENT ON TABLE [[comment]] IS NULL');
384384
$sql = $qb->dropCommentFromTable('comment');
385385
$this->assertEquals($expected, $sql);
386386
}
387387

388388
public function testReplaceQuotes()
389389
{
390390
//Normal words
391-
$this->assertEquals('comment', $this->replaceQuotes("[[comment]]"));
392-
$this->assertEquals('test', $this->replaceQuotes("[[test]]"));
391+
$this->assertEquals('comment', $this->replaceQuotes('[[comment]]'));
392+
$this->assertEquals('test', $this->replaceQuotes('[[test]]'));
393393

394394
//Reserved Words lower case
395-
$this->assertEquals('"order"', $this->replaceQuotes("[[order]]"));
396-
$this->assertEquals('"time"', $this->replaceQuotes("[[time]]"));
395+
$this->assertEquals('"order"', $this->replaceQuotes('[[order]]'));
396+
$this->assertEquals('"time"', $this->replaceQuotes('[[time]]'));
397397
//Reserved Words UPPER CASE
398-
$this->assertEquals('"ORDER"', $this->replaceQuotes("[[ORDER]]"));
399-
$this->assertEquals('"TIME"', $this->replaceQuotes("[[TIME]]"));
398+
$this->assertEquals('"ORDER"', $this->replaceQuotes('[[ORDER]]'));
399+
$this->assertEquals('"TIME"', $this->replaceQuotes('[[TIME]]'));
400400
//Reserved Words Multiple
401-
$this->assertEquals('"order".comment', $this->replaceQuotes("[[order]].[[comment]]"));
402-
$this->assertEquals('"order"."time"', $this->replaceQuotes("[[order]].[[time]]"));
401+
$this->assertEquals('"order".comment', $this->replaceQuotes('[[order]].[[comment]]'));
402+
$this->assertEquals('"order"."time"', $this->replaceQuotes('[[order]].[[time]]'));
403403
}
404404
}

0 commit comments

Comments
 (0)