Commit d7df7053 by Alexander Kochetov

=== array() => empty()

parent 901dabc3
...@@ -456,7 +456,7 @@ class YiiBase ...@@ -456,7 +456,7 @@ class YiiBase
} }
return $reflection->newInstanceArgs($args); return $reflection->newInstanceArgs($args);
} else { } else {
return $config === array() ? new $class : new $class($config); return empty($config) ? new $class : new $class($config);
} }
} }
......
...@@ -144,7 +144,8 @@ class MigrateController extends Controller ...@@ -144,7 +144,8 @@ class MigrateController extends Controller
*/ */
public function actionUp($limit = 0) public function actionUp($limit = 0)
{ {
if (($migrations = $this->getNewMigrations()) === array()) { $migrations = $this->getNewMigrations();
if (empty($migrations)) {
echo "No new migration found. Your system is up-to-date.\n"; echo "No new migration found. Your system is up-to-date.\n";
Yii::$app->end(); Yii::$app->end();
} }
...@@ -198,7 +199,8 @@ class MigrateController extends Controller ...@@ -198,7 +199,8 @@ class MigrateController extends Controller
throw new Exception("The step argument must be greater than 0."); throw new Exception("The step argument must be greater than 0.");
} }
if (($migrations = $this->getMigrationHistory($limit)) === array()) { $migrations = $this->getMigrationHistory($limit);
if (empty($migrations)) {
echo "No migration has been done before.\n"; echo "No migration has been done before.\n";
return; return;
} }
...@@ -244,7 +246,8 @@ class MigrateController extends Controller ...@@ -244,7 +246,8 @@ class MigrateController extends Controller
throw new Exception("The step argument must be greater than 0."); throw new Exception("The step argument must be greater than 0.");
} }
if (($migrations = $this->getMigrationHistory($limit)) === array()) { $migrations = $this->getMigrationHistory($limit);
if (empty($migrations)) {
echo "No migration has been done before.\n"; echo "No migration has been done before.\n";
return; return;
} }
...@@ -407,7 +410,7 @@ class MigrateController extends Controller ...@@ -407,7 +410,7 @@ class MigrateController extends Controller
{ {
$limit = (int)$limit; $limit = (int)$limit;
$migrations = $this->getMigrationHistory($limit); $migrations = $this->getMigrationHistory($limit);
if ($migrations === array()) { if (empty($migrations)) {
echo "No migration has been done before.\n"; echo "No migration has been done before.\n";
} else { } else {
$n = count($migrations); $n = count($migrations);
...@@ -441,7 +444,7 @@ class MigrateController extends Controller ...@@ -441,7 +444,7 @@ class MigrateController extends Controller
{ {
$limit = (int)$limit; $limit = (int)$limit;
$migrations = $this->getNewMigrations(); $migrations = $this->getNewMigrations();
if ($migrations === array()) { if (empty($migrations)) {
echo "No new migrations found. Your system is up-to-date.\n"; echo "No new migrations found. Your system is up-to-date.\n";
} else { } else {
$n = count($migrations); $n = count($migrations);
......
...@@ -106,7 +106,7 @@ class Command extends \yii\base\Component ...@@ -106,7 +106,7 @@ class Command extends \yii\base\Component
*/ */
public function getRawSql() public function getRawSql()
{ {
if ($this->_params === array()) { if (empty($this->_params)) {
return $this->_sql; return $this->_sql;
} else { } else {
$params = array(); $params = array();
......
...@@ -722,7 +722,7 @@ class QueryBuilder extends \yii\base\Object ...@@ -722,7 +722,7 @@ class QueryBuilder extends \yii\base\Object
if (!is_array($condition)) { if (!is_array($condition)) {
return (string)$condition; return (string)$condition;
} elseif ($condition === array()) { } elseif (empty($condition)) {
return ''; return '';
} }
if (isset($condition[0])) { // operator format: operator, operand 1, operand 2, ... if (isset($condition[0])) { // operator format: operator, operand 1, operand 2, ...
...@@ -813,7 +813,7 @@ class QueryBuilder extends \yii\base\Object ...@@ -813,7 +813,7 @@ class QueryBuilder extends \yii\base\Object
$values = (array)$values; $values = (array)$values;
if ($values === array() || $column === array()) { if (empty($values) || empty($column)) {
return $operator === 'IN' ? '0=1' : ''; return $operator === 'IN' ? '0=1' : '';
} }
...@@ -885,7 +885,7 @@ class QueryBuilder extends \yii\base\Object ...@@ -885,7 +885,7 @@ class QueryBuilder extends \yii\base\Object
$values = (array)$values; $values = (array)$values;
if ($values === array()) { if (empty($values)) {
return $operator === 'LIKE' || $operator === 'OR LIKE' ? '0=1' : ''; return $operator === 'LIKE' || $operator === 'OR LIKE' ? '0=1' : '';
} }
......
...@@ -34,7 +34,7 @@ class Json ...@@ -34,7 +34,7 @@ class Json
$expressions = array(); $expressions = array();
$value = static::processData($value, $expressions); $value = static::processData($value, $expressions);
$json = json_encode($value, $options); $json = json_encode($value, $options);
return $expressions === array() ? $json : strtr($json, $expressions); return empty($expressions) ? $json : strtr($json, $expressions);
} }
/** /**
......
...@@ -109,7 +109,7 @@ class I18N extends Component ...@@ -109,7 +109,7 @@ class I18N extends Component
unset($params[0]); unset($params[0]);
} }
return $params === array() ? $message : strtr($message, $params); return empty($params) ? $message : strtr($message, $params);
} }
/** /**
......
...@@ -116,7 +116,7 @@ class FileValidator extends Validator ...@@ -116,7 +116,7 @@ class FileValidator extends Validator
} }
if (!is_array($this->types)) { if (!is_array($this->types)) {
$this->types = preg_split('/[\s,]+/', strtolower($this->types), -1, PREG_SPLIT_NO_EMPTY); $this->types = preg_split('/[\s,]+/', strtolower($this->types), -1, PREG_SPLIT_NO_EMPTY);
} }
} }
/** /**
...@@ -138,8 +138,8 @@ class FileValidator extends Validator ...@@ -138,8 +138,8 @@ class FileValidator extends Validator
} }
} }
$object->$attribute = array_values($files); $object->$attribute = array_values($files);
if ($files === array()) { if (empty($files)) {
$this->addError($object, $attribute, $this->uploadRequired); $this->addError($object, $attribute, $this->uploadRequired);
} }
if (count($files) > $this->maxFiles) { if (count($files) > $this->maxFiles) {
$this->addError($object, $attribute, $this->tooMany, array('{attribute}' => $attribute, '{limit}' => $this->maxFiles)); $this->addError($object, $attribute, $this->tooMany, array('{attribute}' => $attribute, '{limit}' => $this->maxFiles));
...@@ -153,7 +153,7 @@ class FileValidator extends Validator ...@@ -153,7 +153,7 @@ class FileValidator extends Validator
if ($file instanceof UploadedFile && $file->getError() != UPLOAD_ERR_NO_FILE) { if ($file instanceof UploadedFile && $file->getError() != UPLOAD_ERR_NO_FILE) {
$this->validateFile($object, $attribute, $file); $this->validateFile($object, $attribute, $file);
} else { } else {
$this->addError($object, $attribute, $this->uploadRequired); $this->addError($object, $attribute, $this->uploadRequired);
} }
} }
} }
......
...@@ -262,7 +262,6 @@ abstract class Validator extends Component ...@@ -262,7 +262,6 @@ abstract class Validator extends Component
*/ */
public function isEmpty($value, $trim = false) public function isEmpty($value, $trim = false)
{ {
return $value === null || $value === array() || $value === '' return $value === null || empty($value) || $value === '' || $trim && is_scalar($value) && trim($value) === '';
|| $trim && is_scalar($value) && trim($value) === '';
} }
} }
...@@ -251,7 +251,7 @@ class Sort extends \yii\base\Object ...@@ -251,7 +251,7 @@ class Sort extends \yii\base\Object
} }
} }
} }
if ($this->_attributeOrders === array() && is_array($this->defaults)) { if (empty($this->_attributeOrders) && is_array($this->defaults)) {
$this->_attributeOrders = $this->defaults; $this->_attributeOrders = $this->defaults;
} }
} }
......
...@@ -90,7 +90,7 @@ class UrlManager extends Component ...@@ -90,7 +90,7 @@ class UrlManager extends Component
*/ */
protected function compileRules() protected function compileRules()
{ {
if (!$this->enablePrettyUrl || $this->rules === array()) { if (!$this->enablePrettyUrl || empty($this->rules)) {
return; return;
} }
if (is_string($this->cache)) { if (is_string($this->cache)) {
......
...@@ -107,7 +107,7 @@ class FragmentCache extends Widget ...@@ -107,7 +107,7 @@ class FragmentCache extends Widget
$data = array($content, $this->dynamicPlaceholders); $data = array($content, $this->dynamicPlaceholders);
$this->cache->set($this->calculateKey(), $data, $this->duration, $this->dependency); $this->cache->set($this->calculateKey(), $data, $this->duration, $this->dependency);
if ($this->view->cacheStack === array() && !empty($this->dynamicPlaceholders)) { if (empty($this->view->cacheStack) && !empty($this->dynamicPlaceholders)) {
$content = $this->updateDynamicContent($content, $this->dynamicPlaceholders); $content = $this->updateDynamicContent($content, $this->dynamicPlaceholders);
} }
echo $content; echo $content;
...@@ -133,7 +133,7 @@ class FragmentCache extends Widget ...@@ -133,7 +133,7 @@ class FragmentCache extends Widget
if (is_array($data) && count($data) === 2) { if (is_array($data) && count($data) === 2) {
list ($content, $placeholders) = $data; list ($content, $placeholders) = $data;
if (is_array($placeholders) && count($placeholders) > 0) { if (is_array($placeholders) && count($placeholders) > 0) {
if ($this->view->cacheStack === array()) { if (empty($this->view->cacheStack)) {
// outermost cache: replace placeholder with dynamic content // outermost cache: replace placeholder with dynamic content
$content = $this->updateDynamicContent($content, $placeholders); $content = $this->updateDynamicContent($content, $placeholders);
} }
...@@ -171,4 +171,4 @@ class FragmentCache extends Widget ...@@ -171,4 +171,4 @@ class FragmentCache extends Widget
} }
return $this->cache->buildKey($factors); return $this->cache->buildKey($factors);
} }
} }
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