From d7df7053e02808b51e72a987ca67bd2170158c31 Mon Sep 17 00:00:00 2001
From: Alexander Kochetov <creocoder@gmail.com>
Date: Tue, 7 May 2013 19:51:29 +0400
Subject: [PATCH] === array() => empty()

---
 framework/YiiBase.php                               |  2 +-
 framework/console/controllers/MigrateController.php | 13 ++++++++-----
 framework/db/Command.php                            |  2 +-
 framework/db/QueryBuilder.php                       |  6 +++---
 framework/helpers/base/Json.php                     |  2 +-
 framework/i18n/I18N.php                             |  2 +-
 framework/validators/FileValidator.php              |  8 ++++----
 framework/validators/Validator.php                  |  3 +--
 framework/web/Sort.php                              |  2 +-
 framework/web/UrlManager.php                        |  2 +-
 framework/widgets/FragmentCache.php                 |  6 +++---
 11 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/framework/YiiBase.php b/framework/YiiBase.php
index c911f78..b608150 100644
--- a/framework/YiiBase.php
+++ b/framework/YiiBase.php
@@ -456,7 +456,7 @@ class YiiBase
 			}
 			return $reflection->newInstanceArgs($args);
 		} else {
-			return $config === array() ? new $class : new $class($config);
+			return empty($config) ? new $class : new $class($config);
 		}
 	}
 
diff --git a/framework/console/controllers/MigrateController.php b/framework/console/controllers/MigrateController.php
index 3f816f1..fb06c66 100644
--- a/framework/console/controllers/MigrateController.php
+++ b/framework/console/controllers/MigrateController.php
@@ -144,7 +144,8 @@ class MigrateController extends Controller
 	 */
 	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";
 			Yii::$app->end();
 		}
@@ -198,7 +199,8 @@ class MigrateController extends Controller
 			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";
 			return;
 		}
@@ -244,7 +246,8 @@ class MigrateController extends Controller
 			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";
 			return;
 		}
@@ -407,7 +410,7 @@ class MigrateController extends Controller
 	{
 		$limit = (int)$limit;
 		$migrations = $this->getMigrationHistory($limit);
-		if ($migrations === array()) {
+		if (empty($migrations)) {
 			echo "No migration has been done before.\n";
 		} else {
 			$n = count($migrations);
@@ -441,7 +444,7 @@ class MigrateController extends Controller
 	{
 		$limit = (int)$limit;
 		$migrations = $this->getNewMigrations();
-		if ($migrations === array()) {
+		if (empty($migrations)) {
 			echo "No new migrations found. Your system is up-to-date.\n";
 		} else {
 			$n = count($migrations);
diff --git a/framework/db/Command.php b/framework/db/Command.php
index dc6c972..a117685 100644
--- a/framework/db/Command.php
+++ b/framework/db/Command.php
@@ -106,7 +106,7 @@ class Command extends \yii\base\Component
 	 */
 	public function getRawSql()
 	{
-		if ($this->_params === array()) {
+		if (empty($this->_params)) {
 			return $this->_sql;
 		} else {
 			$params = array();
diff --git a/framework/db/QueryBuilder.php b/framework/db/QueryBuilder.php
index 441d287..258ad44 100644
--- a/framework/db/QueryBuilder.php
+++ b/framework/db/QueryBuilder.php
@@ -722,7 +722,7 @@ class QueryBuilder extends \yii\base\Object
 
 		if (!is_array($condition)) {
 			return (string)$condition;
-		} elseif ($condition === array()) {
+		} elseif (empty($condition)) {
 			return '';
 		}
 		if (isset($condition[0])) { // operator format: operator, operand 1, operand 2, ...
@@ -813,7 +813,7 @@ class QueryBuilder extends \yii\base\Object
 
 		$values = (array)$values;
 
-		if ($values === array() || $column === array()) {
+		if (empty($values) || empty($column)) {
 			return $operator === 'IN' ? '0=1' : '';
 		}
 
@@ -885,7 +885,7 @@ class QueryBuilder extends \yii\base\Object
 
 		$values = (array)$values;
 
-		if ($values === array()) {
+		if (empty($values)) {
 			return $operator === 'LIKE' || $operator === 'OR LIKE' ? '0=1' : '';
 		}
 
diff --git a/framework/helpers/base/Json.php b/framework/helpers/base/Json.php
index 262dd81..8de55f9 100644
--- a/framework/helpers/base/Json.php
+++ b/framework/helpers/base/Json.php
@@ -34,7 +34,7 @@ class Json
 		$expressions = array();
 		$value = static::processData($value, $expressions);
 		$json = json_encode($value, $options);
-		return $expressions === array() ? $json : strtr($json, $expressions);
+		return empty($expressions) ? $json : strtr($json, $expressions);
 	}
 
 	/**
diff --git a/framework/i18n/I18N.php b/framework/i18n/I18N.php
index 8667abc..7fae5b0 100644
--- a/framework/i18n/I18N.php
+++ b/framework/i18n/I18N.php
@@ -109,7 +109,7 @@ class I18N extends Component
 			unset($params[0]);
 		}
 
-		return $params === array() ? $message : strtr($message, $params);
+		return empty($params) ? $message : strtr($message, $params);
 	}
 
 	/**
diff --git a/framework/validators/FileValidator.php b/framework/validators/FileValidator.php
index ebe6cad..cc36d07 100644
--- a/framework/validators/FileValidator.php
+++ b/framework/validators/FileValidator.php
@@ -116,7 +116,7 @@ class FileValidator extends Validator
 		}
 		if (!is_array($this->types)) {
 			$this->types = preg_split('/[\s,]+/', strtolower($this->types), -1, PREG_SPLIT_NO_EMPTY);
-		}		
+		}
 	}
 
 	/**
@@ -138,8 +138,8 @@ class FileValidator extends Validator
 				}
 			}
 			$object->$attribute = array_values($files);
-			if ($files === array()) {
-				$this->addError($object, $attribute, $this->uploadRequired);				
+			if (empty($files)) {
+				$this->addError($object, $attribute, $this->uploadRequired);
 			}
 			if (count($files) > $this->maxFiles) {
 				$this->addError($object, $attribute, $this->tooMany, array('{attribute}' => $attribute, '{limit}' => $this->maxFiles));
@@ -153,7 +153,7 @@ class FileValidator extends Validator
 			if ($file instanceof UploadedFile && $file->getError() != UPLOAD_ERR_NO_FILE) {
 				$this->validateFile($object, $attribute, $file);
 			} else {
-				$this->addError($object, $attribute, $this->uploadRequired);				
+				$this->addError($object, $attribute, $this->uploadRequired);
 			}
 		}
 	}
diff --git a/framework/validators/Validator.php b/framework/validators/Validator.php
index 677191b..1ac3f27 100644
--- a/framework/validators/Validator.php
+++ b/framework/validators/Validator.php
@@ -262,7 +262,6 @@ abstract class Validator extends Component
 	 */
 	public function isEmpty($value, $trim = false)
 	{
-		return $value === null || $value === array() || $value === ''
-			|| $trim && is_scalar($value) && trim($value) === '';
+		return $value === null || empty($value) || $value === '' || $trim && is_scalar($value) && trim($value) === '';
 	}
 }
diff --git a/framework/web/Sort.php b/framework/web/Sort.php
index 99084c1..324e733 100644
--- a/framework/web/Sort.php
+++ b/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;
 			}
 		}
diff --git a/framework/web/UrlManager.php b/framework/web/UrlManager.php
index a300033..23a20cf 100644
--- a/framework/web/UrlManager.php
+++ b/framework/web/UrlManager.php
@@ -90,7 +90,7 @@ class UrlManager extends Component
 	 */
 	protected function compileRules()
 	{
-		if (!$this->enablePrettyUrl || $this->rules === array()) {
+		if (!$this->enablePrettyUrl || empty($this->rules)) {
 			return;
 		}
 		if (is_string($this->cache)) {
diff --git a/framework/widgets/FragmentCache.php b/framework/widgets/FragmentCache.php
index 5b37f6e..aa24acd 100644
--- a/framework/widgets/FragmentCache.php
+++ b/framework/widgets/FragmentCache.php
@@ -107,7 +107,7 @@ class FragmentCache extends Widget
 			$data = array($content, $this->dynamicPlaceholders);
 			$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);
 			}
 			echo $content;
@@ -133,7 +133,7 @@ class FragmentCache extends Widget
 				if (is_array($data) && count($data) === 2) {
 					list ($content, $placeholders) = $data;
 					if (is_array($placeholders) && count($placeholders) > 0) {
-						if ($this->view->cacheStack === array()) {
+						if (empty($this->view->cacheStack)) {
 							// outermost cache: replace placeholder with dynamic content
 							$content = $this->updateDynamicContent($content, $placeholders);
 						}
@@ -171,4 +171,4 @@ class FragmentCache extends Widget
 		}
 		return $this->cache->buildKey($factors);
 	}
-}
+}
--
libgit2 0.27.1