mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
Use (array) cast instead of !is_array check for both readability and performance
This commit is contained in:
@ -575,7 +575,7 @@ class ActiveRecord extends BaseActiveRecord
|
||||
{
|
||||
$pkName = static::primaryKey()[0];
|
||||
if (count($condition) == 1 && isset($condition[$pkName])) {
|
||||
$primaryKeys = is_array($condition[$pkName]) ? $condition[$pkName] : [$condition[$pkName]];
|
||||
$primaryKeys = (array)$condition[$pkName];
|
||||
} else {
|
||||
$primaryKeys = static::find()->where($condition)->column($pkName); // TODO check whether this works with default pk _id
|
||||
}
|
||||
@ -635,7 +635,7 @@ class ActiveRecord extends BaseActiveRecord
|
||||
{
|
||||
$pkName = static::primaryKey()[0];
|
||||
if (count($condition) == 1 && isset($condition[$pkName])) {
|
||||
$primaryKeys = is_array($condition[$pkName]) ? $condition[$pkName] : [$condition[$pkName]];
|
||||
$primaryKeys = (array)$condition[$pkName];
|
||||
} else {
|
||||
$primaryKeys = static::find()->where($condition)->column($pkName); // TODO check whether this works with default pk _id
|
||||
}
|
||||
@ -771,7 +771,7 @@ class ActiveRecord extends BaseActiveRecord
|
||||
{
|
||||
$pkName = static::primaryKey()[0];
|
||||
if (count($condition) == 1 && isset($condition[$pkName])) {
|
||||
$primaryKeys = is_array($condition[$pkName]) ? $condition[$pkName] : [$condition[$pkName]];
|
||||
$primaryKeys = (array)$condition[$pkName];
|
||||
} else {
|
||||
$primaryKeys = static::find()->where($condition)->column($pkName); // TODO check whether this works with default pk _id
|
||||
}
|
||||
|
@ -213,9 +213,7 @@ class Collection extends Object
|
||||
*/
|
||||
public function createIndex($columns, $options = [])
|
||||
{
|
||||
if (!is_array($columns)) {
|
||||
$columns = [$columns];
|
||||
}
|
||||
$columns = (array)$columns;
|
||||
$keys = $this->normalizeIndexKeys($columns);
|
||||
$token = $this->composeLogToken('createIndex', [$keys, $options]);
|
||||
$options = array_merge(['w' => 1], $options);
|
||||
@ -258,9 +256,7 @@ class Collection extends Object
|
||||
*/
|
||||
public function dropIndex($columns)
|
||||
{
|
||||
if (!is_array($columns)) {
|
||||
$columns = [$columns];
|
||||
}
|
||||
$columns = (array)$columns;
|
||||
$keys = $this->normalizeIndexKeys($columns);
|
||||
$token = $this->composeLogToken('dropIndex', [$keys]);
|
||||
Yii::info($token, __METHOD__);
|
||||
|
@ -248,10 +248,7 @@ class MessageController extends Controller
|
||||
$this->stdout("Extracting messages from $coloredFileName...\n");
|
||||
$subject = file_get_contents($fileName);
|
||||
$messages = [];
|
||||
if (!is_array($translator)) {
|
||||
$translator = [$translator];
|
||||
}
|
||||
foreach ($translator as $currentTranslator) {
|
||||
foreach ((array)$translator as $currentTranslator) {
|
||||
$translatorTokens = token_get_all('<?php ' . $currentTranslator);
|
||||
array_shift($translatorTokens);
|
||||
|
||||
|
@ -87,9 +87,7 @@ class TableSchema extends Object
|
||||
*/
|
||||
public function fixPrimaryKey($keys)
|
||||
{
|
||||
if (!is_array($keys)) {
|
||||
$keys = [$keys];
|
||||
}
|
||||
$keys = (array)$keys;
|
||||
$this->primaryKey = $keys;
|
||||
foreach ($this->columns as $column) {
|
||||
$column->isPrimaryKey = false;
|
||||
|
@ -73,7 +73,7 @@ class Controller extends \yii\base\Controller
|
||||
$name = $param->getName();
|
||||
if (array_key_exists($name, $params)) {
|
||||
if ($param->isArray()) {
|
||||
$args[] = $actionParams[$name] = is_array($params[$name]) ? $params[$name] : [$params[$name]];
|
||||
$args[] = $actionParams[$name] = (array)$params[$name];
|
||||
} elseif (!is_array($params[$name])) {
|
||||
$args[] = $actionParams[$name] = $params[$name];
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user