Browse Source

=== array() => empty()

tags/2.0.0-beta
Alexander Kochetov 12 years ago
parent
commit
d7df7053e0
  1. 2
      framework/YiiBase.php
  2. 13
      framework/console/controllers/MigrateController.php
  3. 2
      framework/db/Command.php
  4. 6
      framework/db/QueryBuilder.php
  5. 2
      framework/helpers/base/Json.php
  6. 2
      framework/i18n/I18N.php
  7. 2
      framework/validators/FileValidator.php
  8. 3
      framework/validators/Validator.php
  9. 2
      framework/web/Sort.php
  10. 2
      framework/web/UrlManager.php
  11. 4
      framework/widgets/FragmentCache.php

2
framework/YiiBase.php

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

13
framework/console/controllers/MigrateController.php

@ -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
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
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
{ {
$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
{ {
$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);

2
framework/db/Command.php

@ -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();

6
framework/db/QueryBuilder.php

@ -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
$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
$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' : '';
} }

2
framework/helpers/base/Json.php

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

2
framework/i18n/I18N.php

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

2
framework/validators/FileValidator.php

@ -138,7 +138,7 @@ 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) {

3
framework/validators/Validator.php

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

2
framework/web/Sort.php

@ -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;
} }
} }

2
framework/web/UrlManager.php

@ -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)) {

4
framework/widgets/FragmentCache.php

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

Loading…
Cancel
Save