Commit 4c2aaee4 by Qiang Xue

Merge pull request #2061 from lucianobaraglia/some-codestyle-fixes

Some codestyle fixes
parents ab882a3c fe3ff6dd
...@@ -16,7 +16,7 @@ $frameworkPath = dirname(__FILE__) . '/vendor/yiisoft/yii2'; ...@@ -16,7 +16,7 @@ $frameworkPath = dirname(__FILE__) . '/vendor/yiisoft/yii2';
if (!is_dir($frameworkPath)) { if (!is_dir($frameworkPath)) {
echo '<h1>Error</h1>'; echo '<h1>Error</h1>';
echo '<p><strong>The path to yii framework seems to be incorrect.</strong></p>'; echo '<p><strong>The path to yii framework seems to be incorrect.</strong></p>';
echo '<p>You need to install Yii framework via composer or adjust the framework path in file <abbr title="' . __FILE__ . '">' . basename(__FILE__) .'</abbr>.</p>'; echo '<p>You need to install Yii framework via composer or adjust the framework path in file <abbr title="' . __FILE__ . '">' . basename(__FILE__) . '</abbr>.</p>';
echo '<p>Please refer to the <abbr title="' . dirname(__FILE__) . '/README.md">README</abbr> on how to install Yii.</p>'; echo '<p>Please refer to the <abbr title="' . dirname(__FILE__) . '/README.md">README</abbr> on how to install Yii.</p>';
} }
......
...@@ -16,7 +16,7 @@ $frameworkPath = dirname(__FILE__) . '/vendor/yiisoft/yii2'; ...@@ -16,7 +16,7 @@ $frameworkPath = dirname(__FILE__) . '/vendor/yiisoft/yii2';
if (!is_dir($frameworkPath)) { if (!is_dir($frameworkPath)) {
echo '<h1>Error</h1>'; echo '<h1>Error</h1>';
echo '<p><strong>The path to yii framework seems to be incorrect.</strong></p>'; echo '<p><strong>The path to yii framework seems to be incorrect.</strong></p>';
echo '<p>You need to install Yii framework via composer or adjust the framework path in file <abbr title="' . __FILE__ . '">' . basename(__FILE__) .'</abbr>.</p>'; echo '<p>You need to install Yii framework via composer or adjust the framework path in file <abbr title="' . __FILE__ . '">' . basename(__FILE__) . '</abbr>.</p>';
echo '<p>Please refer to the <abbr title="' . dirname(__FILE__) . '/README.md">README</abbr> on how to install Yii.</p>'; echo '<p>Please refer to the <abbr title="' . dirname(__FILE__) . '/README.md">README</abbr> on how to install Yii.</p>';
} }
......
...@@ -33,8 +33,8 @@ class LoginFormTest extends TestCase ...@@ -33,8 +33,8 @@ class LoginFormTest extends TestCase
$this->specify('user should not be able to login with wrong password', function () use ($model) { $this->specify('user should not be able to login with wrong password', function () use ($model) {
$this->assertFalse($model->login()); $this->assertFalse($model->login());
$this->assertArrayHasKey('password',$model->errors); $this->assertArrayHasKey('password', $model->errors);
$this->assertTrue(Yii::$app->user->isGuest,'user should not be logged in'); $this->assertTrue(Yii::$app->user->isGuest, 'user should not be logged in');
}); });
} }
...@@ -47,7 +47,7 @@ class LoginFormTest extends TestCase ...@@ -47,7 +47,7 @@ class LoginFormTest extends TestCase
$this->specify('user should be able to login with correct credentials', function() use ($model) { $this->specify('user should be able to login with correct credentials', function() use ($model) {
$this->assertTrue($model->login()); $this->assertTrue($model->login());
$this->assertArrayNotHasKey('password',$model->errors); $this->assertArrayNotHasKey('password', $model->errors);
$this->assertFalse(Yii::$app->user->isGuest,'user should be logged in'); $this->assertFalse(Yii::$app->user->isGuest,'user should be logged in');
}); });
} }
...@@ -59,4 +59,4 @@ class LoginFormTest extends TestCase ...@@ -59,4 +59,4 @@ class LoginFormTest extends TestCase
return $loginForm; return $loginForm;
} }
} }
\ No newline at end of file
...@@ -298,7 +298,7 @@ class PhpDocController extends Controller ...@@ -298,7 +298,7 @@ class PhpDocController extends Controller
if (isset($prop['get']) && isset($prop['set'])) { if (isset($prop['get']) && isset($prop['set'])) {
if ($prop['get']['type'] != $prop['set']['type']) { if ($prop['get']['type'] != $prop['set']['type']) {
$note = ' Note that the type of this property differs in getter and setter.' $note = ' Note that the type of this property differs in getter and setter.'
. ' See [[get'.ucfirst($propName).'()]] and [[set'.ucfirst($propName).'()]] for details.'; . ' See [[get' . ucfirst($propName) . '()]] and [[set' . ucfirst($propName) . '()]] for details.';
} }
} elseif (isset($prop['get'])) { } elseif (isset($prop['get'])) {
// check if parent class has setter defined // check if parent class has setter defined
......
...@@ -84,22 +84,22 @@ class BaseDoc extends Object ...@@ -84,22 +84,22 @@ class BaseDoc extends Object
// TODO // TODO
public function loadSource($reflection) public function loadSource($reflection)
{ {
$this->sourcePath=str_replace('\\','/',str_replace(YII_PATH,'',$reflection->getFileName())); $this->sourcePath = str_replace('\\', '/', str_replace(YII_PATH, '', $reflection->getFileName()));
$this->startLine=$reflection->getStartLine(); $this->startLine = $reflection->getStartLine();
$this->endLine=$reflection->getEndLine(); $this->endLine = $reflection->getEndLine();
} }
public function getSourceUrl($baseUrl,$line=null) public function getSourceUrl($baseUrl, $line=null)
{ {
if($line===null) if($line === null)
return $baseUrl.$this->sourcePath; return $baseUrl . $this->sourcePath;
else else
return $baseUrl.$this->sourcePath.'#'.$line; return $baseUrl . $this->sourcePath . '#' . $line;
} }
public function getSourceCode() public function getSourceCode()
{ {
$lines=file(YII_PATH.$this->sourcePath); $lines = file(YII_PATH . $this->sourcePath);
return implode("",array_slice($lines,$this->startLine-1,$this->endLine-$this->startLine+1)); return implode("", array_slice($lines, $this->startLine - 1, $this->endLine - $this->startLine + 1));
} }
} }
\ No newline at end of file
...@@ -239,7 +239,7 @@ abstract class Renderer extends BaseRenderer implements ViewContextInterface ...@@ -239,7 +239,7 @@ abstract class Renderer extends BaseRenderer implements ViewContextInterface
break; break;
} }
} }
return implode(" &raquo;\n",$parents); return implode(" &raquo;\n", $parents);
} }
/** /**
...@@ -257,7 +257,7 @@ abstract class Renderer extends BaseRenderer implements ViewContextInterface ...@@ -257,7 +257,7 @@ abstract class Renderer extends BaseRenderer implements ViewContextInterface
$interfaces[] = $interface; // TODO link to php.net $interfaces[] = $interface; // TODO link to php.net
} }
} }
return implode(', ',$interfaces); return implode(', ', $interfaces);
} }
/** /**
...@@ -275,7 +275,7 @@ abstract class Renderer extends BaseRenderer implements ViewContextInterface ...@@ -275,7 +275,7 @@ abstract class Renderer extends BaseRenderer implements ViewContextInterface
$traits[] = $trait; // TODO link to php.net $traits[] = $trait; // TODO link to php.net
} }
} }
return implode(', ',$traits); return implode(', ', $traits);
} }
/** /**
...@@ -293,7 +293,7 @@ abstract class Renderer extends BaseRenderer implements ViewContextInterface ...@@ -293,7 +293,7 @@ abstract class Renderer extends BaseRenderer implements ViewContextInterface
$classes[] = $class; // TODO link to php.net $classes[] = $class; // TODO link to php.net
} }
} }
return implode(', ',$classes); return implode(', ', $classes);
} }
/** /**
...@@ -350,4 +350,4 @@ abstract class Renderer extends BaseRenderer implements ViewContextInterface ...@@ -350,4 +350,4 @@ abstract class Renderer extends BaseRenderer implements ViewContextInterface
{ {
return Yii::getAlias('@yii/apidoc/templates/html/views/' . $view); return Yii::getAlias('@yii/apidoc/templates/html/views/' . $view);
} }
} }
\ No newline at end of file
...@@ -173,10 +173,10 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface ...@@ -173,10 +173,10 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface
$curlOptions = $this->mergeCurlOptions( $curlOptions = $this->mergeCurlOptions(
$this->defaultCurlOptions(), $this->defaultCurlOptions(),
$this->getCurlOptions(), $this->getCurlOptions(),
array( [
CURLOPT_RETURNTRANSFER => true, CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $url, CURLOPT_URL => $url,
), ],
$this->composeRequestCurlOptions(strtoupper($method), $url, $params) $this->composeRequestCurlOptions(strtoupper($method), $url, $params)
); );
$curlResource = curl_init(); $curlResource = curl_init();
...@@ -217,7 +217,7 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface ...@@ -217,7 +217,7 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface
while (!empty($args)) { while (!empty($args)) {
$next = array_shift($args); $next = array_shift($args);
foreach ($next as $k => $v) { foreach ($next as $k => $v) {
$res[$k]=$v; $res[$k] = $v;
} }
} }
return $res; return $res;
...@@ -507,4 +507,4 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface ...@@ -507,4 +507,4 @@ abstract class BaseOAuth extends BaseClient implements ClientInterface
* @throws Exception on failure. * @throws Exception on failure.
*/ */
abstract protected function apiInternal($accessToken, $url, $method, array $params); abstract protected function apiInternal($accessToken, $url, $method, array $params);
} }
\ No newline at end of file
...@@ -28,7 +28,7 @@ echo GridView::widget([ ...@@ -28,7 +28,7 @@ echo GridView::widget([
'value' => function ($data) { 'value' => function ($data) {
$timeInSeconds = $data['time'] / 1000; $timeInSeconds = $data['time'] / 1000;
$millisecondsDiff = (int)(($timeInSeconds - (int)$timeInSeconds) * 1000); $millisecondsDiff = (int)(($timeInSeconds - (int)$timeInSeconds) * 1000);
return date('H:i:s.',$timeInSeconds) . sprintf('%03d',$millisecondsDiff); return date('H:i:s.', $timeInSeconds) . sprintf('%03d', $millisecondsDiff);
}, },
'headerOptions' => [ 'headerOptions' => [
'class' => 'sort-numerical' 'class' => 'sort-numerical'
...@@ -70,4 +70,4 @@ echo GridView::widget([ ...@@ -70,4 +70,4 @@ echo GridView::widget([
], ],
], ],
]); ]);
?> ?>
\ No newline at end of file
...@@ -28,7 +28,7 @@ echo GridView::widget([ ...@@ -28,7 +28,7 @@ echo GridView::widget([
[ [
'attribute' => 'duration', 'attribute' => 'duration',
'value' => function ($data) { 'value' => function ($data) {
return sprintf('%.1f ms',$data['duration']); return sprintf('%.1f ms', $data['duration']);
}, },
'options' => [ 'options' => [
'width' => '10%', 'width' => '10%',
......
...@@ -367,7 +367,7 @@ class ActiveRecord extends BaseActiveRecord ...@@ -367,7 +367,7 @@ class ActiveRecord extends BaseActiveRecord
* For example, to change the status to be 1 for all customers whose status is 2: * For example, to change the status to be 1 for all customers whose status is 2:
* *
* ~~~ * ~~~
* Customer::updateAll(array('status' => 1), array(2, 3, 4)); * Customer::updateAll(['status' => 1], [2, 3, 4]);
* ~~~ * ~~~
* *
* @param array $attributes attribute values (name-value pairs) to be saved into the table * @param array $attributes attribute values (name-value pairs) to be saved into the table
......
...@@ -138,7 +138,7 @@ class QueryBuilder extends \yii\base\Object ...@@ -138,7 +138,7 @@ class QueryBuilder extends \yii\base\Object
*/ */
public function buildCondition($condition) public function buildCondition($condition)
{ {
static $builders = array( static $builders = [
'not' => 'buildNotCondition', 'not' => 'buildNotCondition',
'and' => 'buildAndCondition', 'and' => 'buildAndCondition',
'or' => 'buildAndCondition', 'or' => 'buildAndCondition',
...@@ -150,7 +150,7 @@ class QueryBuilder extends \yii\base\Object ...@@ -150,7 +150,7 @@ class QueryBuilder extends \yii\base\Object
'not like' => 'buildLikeCondition', 'not like' => 'buildLikeCondition',
'or like' => 'buildLikeCondition', 'or like' => 'buildLikeCondition',
'or not like' => 'buildLikeCondition', 'or not like' => 'buildLikeCondition',
); ];
if (empty($condition)) { if (empty($condition)) {
return []; return [];
......
...@@ -89,7 +89,7 @@ class Customer extends \yii\elasticsearch\ActiveRecord ...@@ -89,7 +89,7 @@ class Customer extends \yii\elasticsearch\ActiveRecord
*/ */
public static function active($query) public static function active($query)
{ {
$query->andWhere(array('status' => 1)); $query->andWhere(['status' => 1]);
} }
} }
``` ```
......
...@@ -335,4 +335,4 @@ $.fn.extend({ ...@@ -335,4 +335,4 @@ $.fn.extend({
}); });
})(jQuery); })(jQuery);
\ No newline at end of file
...@@ -289,7 +289,7 @@ class ErrorHandler extends Component ...@@ -289,7 +289,7 @@ class ErrorHandler extends Component
*/ */
public function createHttpStatusLink($statusCode, $statusDescription) public function createHttpStatusLink($statusCode, $statusDescription)
{ {
return '<a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#' . (int)$statusCode .'" target="_blank">HTTP ' . (int)$statusCode . ' &ndash; ' . $statusDescription . '</a>'; return '<a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#' . (int)$statusCode . '" target="_blank">HTTP ' . (int)$statusCode . ' &ndash; ' . $statusDescription . '</a>';
} }
/** /**
......
...@@ -333,7 +333,7 @@ class Migration extends \yii\base\Component ...@@ -333,7 +333,7 @@ class Migration extends \yii\base\Component
*/ */
public function addPrimaryKey($name, $table, $columns) public function addPrimaryKey($name, $table, $columns)
{ {
echo " > add primary key $name on $table (".(is_array($columns) ? implode(',', $columns) : $columns).") ..."; echo " > add primary key $name on $table (" . (is_array($columns) ? implode(',', $columns) : $columns).") ...";
$time = microtime(true); $time = microtime(true);
$this->db->createCommand()->addPrimaryKey($name, $table, $columns)->execute(); $this->db->createCommand()->addPrimaryKey($name, $table, $columns)->execute();
echo " done (time: " . sprintf('%.3f', microtime(true) - $time) . "s)\n"; echo " done (time: " . sprintf('%.3f', microtime(true) - $time) . "s)\n";
......
...@@ -93,8 +93,8 @@ class QueryBuilder extends \yii\db\QueryBuilder ...@@ -93,8 +93,8 @@ class QueryBuilder extends \yii\db\QueryBuilder
*/ */
public function alterColumn($table, $column, $type) public function alterColumn($table, $column, $type)
{ {
$type=$this->getColumnType($type); $type = $this->getColumnType($type);
$sql='ALTER TABLE ' . $this->db->quoteTableName($table) . ' ALTER COLUMN ' $sql = 'ALTER TABLE ' . $this->db->quoteTableName($table) . ' ALTER COLUMN '
. $this->db->quoteColumnName($column) . ' ' . $this->db->quoteColumnName($column) . ' '
. $this->getColumnType($type); . $this->getColumnType($type);
return $sql; return $sql;
......
...@@ -146,7 +146,7 @@ class DbManager extends Manager ...@@ -146,7 +146,7 @@ class DbManager extends Manager
} }
$query = new Query; $query = new Query;
$rows = $query->from($this->itemTable) $rows = $query->from($this->itemTable)
->where(['or', 'name=:name1', 'name=:name2'], [':name1' => $itemName, ':name2' => $childName]) ->where(['or', 'name=:name1', 'name=:name2'], [':name1' => $itemName, ':name2' => $childName])
->createCommand($this->db) ->createCommand($this->db)
->queryAll(); ->queryAll();
if (count($rows) == 2) { if (count($rows) == 2) {
...@@ -299,7 +299,7 @@ class DbManager extends Manager ...@@ -299,7 +299,7 @@ class DbManager extends Manager
$query = new Query; $query = new Query;
return $query->select(['item_name']) return $query->select(['item_name'])
->from($this->assignmentTable) ->from($this->assignmentTable)
->where(['user_id' => $userId, 'item_name' => $itemName]) ->where(['user_id' => $userId, 'item_name' => $itemName])
->createCommand($this->db) ->createCommand($this->db)
->queryScalar() !== false; ->queryScalar() !== false;
} }
...@@ -315,7 +315,7 @@ class DbManager extends Manager ...@@ -315,7 +315,7 @@ class DbManager extends Manager
{ {
$query = new Query; $query = new Query;
$row = $query->from($this->assignmentTable) $row = $query->from($this->assignmentTable)
->where(['user_id' => $userId, 'item_name' => $itemName]) ->where(['user_id' => $userId, 'item_name' => $itemName])
->createCommand($this->db) ->createCommand($this->db)
->queryOne(); ->queryOne();
if ($row !== false) { if ($row !== false) {
......
...@@ -39,9 +39,9 @@ class MaskedInput extends InputWidget ...@@ -39,9 +39,9 @@ class MaskedInput extends InputWidget
/** /**
* @var string the input mask (e.g. '99/99/9999' for date input). The following characters are predefined: * @var string the input mask (e.g. '99/99/9999' for date input). The following characters are predefined:
* *
* - `a`: represents an alpha character (A-Z,a-z) * - `a`: represents an alpha character (A-Z, a-z)
* - `9`: represents a numeric character (0-9) * - `9`: represents a numeric character (0-9)
* - `*`: represents an alphanumeric character (A-Z,a-z,0-9) * - `*`: represents an alphanumeric character (A-Z, a-z, 0-9)
* - `?`: anything listed after '?' within the mask is considered optional user input * - `?`: anything listed after '?' within the mask is considered optional user input
* *
* Additional characters can be defined by specifying the [[charMap]] property. * Additional characters can be defined by specifying the [[charMap]] property.
......
...@@ -32,12 +32,12 @@ class Customer extends ActiveRecord ...@@ -32,12 +32,12 @@ class Customer extends ActiveRecord
public function getOrders() public function getOrders()
{ {
return $this->hasMany(Order::className(), array('customer_id' => 'id'))->orderBy('created_at'); return $this->hasMany(Order::className(), ['customer_id' => 'id'])->orderBy('created_at');
} }
public static function active($query) public static function active($query)
{ {
$query->andWhere(array('status' => 1)); $query->andWhere(['status' => 1]);
} }
public function afterSave($insert) public function afterSave($insert)
......
...@@ -180,13 +180,13 @@ class BaseOAuthTest extends TestCase ...@@ -180,13 +180,13 @@ class BaseOAuthTest extends TestCase
*/ */
public function determineContentTypeByRawDataProvider() public function determineContentTypeByRawDataProvider()
{ {
return array( return [
['{name: value}', 'json'], ['{name: value}', 'json'],
['name=value', 'urlencoded'], ['name=value', 'urlencoded'],
['name1=value1&name2=value2', 'urlencoded'], ['name1=value1&name2=value2', 'urlencoded'],
['<?xml version="1.0" encoding="UTF-8"?><tag>Value</tag>', 'xml'], ['<?xml version="1.0" encoding="UTF-8"?><tag>Value</tag>', 'xml'],
['<tag>Value</tag>', 'xml'], ['<tag>Value</tag>', 'xml'],
); ];
} }
/** /**
...@@ -248,4 +248,4 @@ class BaseOAuthTest extends TestCase ...@@ -248,4 +248,4 @@ class BaseOAuthTest extends TestCase
$this->assertEquals($expectedApiFullUrl, $oauthClient->api($apiSubUrl)); $this->assertEquals($expectedApiFullUrl, $oauthClient->api($apiSubUrl));
} }
} }
\ No newline at end of file
...@@ -35,14 +35,14 @@ class RedisConnectionTest extends RedisTestCase ...@@ -35,14 +35,14 @@ class RedisConnectionTest extends RedisTestCase
public function keyValueData() public function keyValueData()
{ {
return array( return [
array(123), [123],
array(-123), [-123],
array(0), [0],
array('test'), ['test'],
array("test\r\ntest"), ["test\r\ntest"],
array(''), [''],
); ];
} }
/** /**
...@@ -55,4 +55,4 @@ class RedisConnectionTest extends RedisTestCase ...@@ -55,4 +55,4 @@ class RedisConnectionTest extends RedisTestCase
$db->set('hi', $data); $db->set('hi', $data);
$this->assertEquals($data, $db->get('hi')); $this->assertEquals($data, $db->get('hi'));
} }
} }
\ No newline at end of file
...@@ -58,7 +58,7 @@ class ActiveRecordTest extends DatabaseTestCase ...@@ -58,7 +58,7 @@ class ActiveRecordTest extends DatabaseTestCase
public function testFindScalar() public function testFindScalar()
{ {
// query scalar // query scalar
$customerName = $this->callCustomerFind()->where(array('id' => 2))->select('name')->scalar(); $customerName = $this->callCustomerFind()->where(['id' => 2])->select('name')->scalar();
$this->assertEquals('user2', $customerName); $this->assertEquals('user2', $customerName);
} }
......
...@@ -84,7 +84,7 @@ class SqliteQueryBuilderTest extends QueryBuilderTest ...@@ -84,7 +84,7 @@ class SqliteQueryBuilderTest extends QueryBuilderTest
public function testBatchInsert() public function testBatchInsert()
{ {
$sql = $this->getQueryBuilder()->batchInsert('{{tbl_customer}} t', ['t.id','t.name'], array(array(1,'a'), array(2,'b'))); $sql = $this->getQueryBuilder()->batchInsert('{{tbl_customer}} t', ['t.id','t.name'], [[1,'a'], [2,'b']]);
$this->assertEquals("INSERT INTO {{tbl_customer}} t (`t`.`id`, `t`.`name`) SELECT 1, 'a' UNION ALL 2, 'b'", $sql); $this->assertEquals("INSERT INTO {{tbl_customer}} t (`t`.`id`, `t`.`name`) SELECT 1, 'a' UNION ALL 2, 'b'", $sql);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment