Browse Source

!== array() => !empty()

tags/2.0.0-beta
Alexander Kochetov 12 years ago
parent
commit
48d04fbb8c
  1. 2
      framework/YiiBase.php
  2. 2
      framework/base/Controller.php
  3. 4
      framework/base/Dictionary.php
  4. 2
      framework/base/Vector.php
  5. 8
      framework/console/Controller.php
  6. 6
      framework/console/controllers/HelpController.php
  7. 2
      framework/db/ActiveQuery.php
  8. 2
      framework/db/Query.php
  9. 2
      framework/db/QueryBuilder.php
  10. 2
      framework/helpers/base/ArrayHelper.php
  11. 14
      framework/helpers/base/Html.php
  12. 4
      framework/web/UrlManager.php
  13. 4
      framework/web/UrlRule.php
  14. 6
      framework/widgets/ActiveField.php
  15. 4
      framework/widgets/ActiveForm.php
  16. 2
      framework/widgets/Menu.php

2
framework/YiiBase.php

@ -451,7 +451,7 @@ class YiiBase
} }
$args = func_get_args(); $args = func_get_args();
array_shift($args); // remove $config array_shift($args); // remove $config
if ($config !== array()) { if (!empty($config)) {
$args[] = $config; $args[] = $config;
} }
return $reflection->newInstanceArgs($args); return $reflection->newInstanceArgs($args);

2
framework/base/Controller.php

@ -183,7 +183,7 @@ class Controller extends Component
} }
} }
if ($missing !== array()) { if (!empty($missing)) {
throw new InvalidRequestException(Yii::t('yii|Missing required parameters: {params}', array( throw new InvalidRequestException(Yii::t('yii|Missing required parameters: {params}', array(
'{params}' => implode(', ', $missing), '{params}' => implode(', ', $missing),
))); )));

4
framework/base/Dictionary.php

@ -51,7 +51,7 @@ class Dictionary extends Object implements \IteratorAggregate, \ArrayAccess, \Co
*/ */
public function __construct($data = array(), $config = array()) public function __construct($data = array(), $config = array())
{ {
if ($data !== array()) { if (!empty($data)) {
$this->copyFrom($data); $this->copyFrom($data);
} }
parent::__construct($config); parent::__construct($config);
@ -187,7 +187,7 @@ class Dictionary extends Object implements \IteratorAggregate, \ArrayAccess, \Co
public function copyFrom($data) public function copyFrom($data)
{ {
if (is_array($data) || $data instanceof \Traversable) { if (is_array($data) || $data instanceof \Traversable) {
if ($this->_d !== array()) { if (!empty($this->_d)) {
$this->removeAll(); $this->removeAll();
} }
if ($data instanceof self) { if ($data instanceof self) {

2
framework/base/Vector.php

@ -58,7 +58,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
*/ */
public function __construct($data = array(), $config = array()) public function __construct($data = array(), $config = array())
{ {
if ($data !== array()) { if (!empty($data)) {
$this->copyFrom($data); $this->copyFrom($data);
} }
parent::__construct($config); parent::__construct($config);

8
framework/console/Controller.php

@ -45,7 +45,7 @@ class Controller extends \yii\base\Controller
*/ */
public function runAction($id, $params = array()) public function runAction($id, $params = array())
{ {
if ($params !== array()) { if (!empty($params)) {
$options = $this->globalOptions(); $options = $this->globalOptions();
foreach ($params as $name => $value) { foreach ($params as $name => $value) {
if (in_array($name, $options, true)) { if (in_array($name, $options, true)) {
@ -69,7 +69,7 @@ class Controller extends \yii\base\Controller
*/ */
public function bindActionParams($action, $params) public function bindActionParams($action, $params)
{ {
if ($params !== array()) { if (!empty($params)) {
$options = $this->globalOptions(); $options = $this->globalOptions();
foreach ($params as $name => $value) { foreach ($params as $name => $value) {
if (in_array($name, $options, true)) { if (in_array($name, $options, true)) {
@ -81,7 +81,7 @@ class Controller extends \yii\base\Controller
$args = isset($params[Request::ANONYMOUS_PARAMS]) ? $params[Request::ANONYMOUS_PARAMS] : array(); $args = isset($params[Request::ANONYMOUS_PARAMS]) ? $params[Request::ANONYMOUS_PARAMS] : array();
unset($params[Request::ANONYMOUS_PARAMS]); unset($params[Request::ANONYMOUS_PARAMS]);
if ($params !== array()) { if (!empty($params)) {
throw new Exception(Yii::t('yii|Unknown options: {params}', array( throw new Exception(Yii::t('yii|Unknown options: {params}', array(
'{params}' => implode(', ', array_keys($params)), '{params}' => implode(', ', array_keys($params)),
))); )));
@ -105,7 +105,7 @@ class Controller extends \yii\base\Controller
} }
} }
if ($missing !== array()) { if (!empty($missing)) {
throw new Exception(Yii::t('yii|Missing required arguments: {params}', array( throw new Exception(Yii::t('yii|Missing required arguments: {params}', array(
'{params}' => implode(', ', $missing), '{params}' => implode(', ', $missing),
))); )));

6
framework/console/controllers/HelpController.php

@ -142,7 +142,7 @@ class HelpController extends Controller
protected function getHelp() protected function getHelp()
{ {
$commands = $this->getCommands(); $commands = $this->getCommands();
if ($commands !== array()) { if (!empty($commands)) {
echo "The following commands are available:\n\n"; echo "The following commands are available:\n\n";
foreach ($commands as $command) { foreach ($commands as $command) {
echo "* $command\n"; echo "* $command\n";
@ -172,7 +172,7 @@ class HelpController extends Controller
} }
$actions = $this->getActions($controller); $actions = $this->getActions($controller);
if ($actions !== array()) { if (!empty($actions)) {
echo "\nSUB-COMMANDS\n\n"; echo "\nSUB-COMMANDS\n\n";
$prefix = $controller->getUniqueId(); $prefix = $controller->getUniqueId();
foreach ($actions as $action) { foreach ($actions as $action) {
@ -280,7 +280,7 @@ class HelpController extends Controller
} }
$options = $this->getOptionHelps($controller); $options = $this->getOptionHelps($controller);
if ($options !== array()) { if (!empty($options)) {
echo "\nOPTIONS\n\n"; echo "\nOPTIONS\n\n";
echo implode("\n\n", $options) . "\n\n"; echo implode("\n\n", $options) . "\n\n";
} }

2
framework/db/ActiveQuery.php

@ -103,7 +103,7 @@ class ActiveQuery extends Query
{ {
$command = $this->createCommand(); $command = $this->createCommand();
$rows = $command->queryAll(); $rows = $command->queryAll();
if ($rows !== array()) { if (!empty($rows)) {
$models = $this->createModels($rows); $models = $this->createModels($rows);
if (!empty($this->with)) { if (!empty($this->with)) {
$this->populateRelations($models, $this->with); $this->populateRelations($models, $this->with);

2
framework/db/Query.php

@ -589,7 +589,7 @@ class Query extends \yii\base\Component
*/ */
public function addParams($params) public function addParams($params)
{ {
if ($params !== array()) { if (!empty($params)) {
if ($this->params === null) { if ($this->params === null) {
$this->params = $params; $this->params = $params;
} else { } else {

2
framework/db/QueryBuilder.php

@ -777,7 +777,7 @@ class QueryBuilder extends \yii\base\Object
$parts[] = $operand; $parts[] = $operand;
} }
} }
if ($parts !== array()) { if (!empty($parts)) {
return '(' . implode(") $operator (", $parts) . ')'; return '(' . implode(") $operator (", $parts) . ')';
} else { } else {
return ''; return '';

2
framework/helpers/base/ArrayHelper.php

@ -36,7 +36,7 @@ class ArrayHelper
{ {
$args = func_get_args(); $args = func_get_args();
$res = array_shift($args); $res = array_shift($args);
while ($args !== array()) { while (!empty($args)) {
$next = array_shift($args); $next = array_shift($args);
foreach ($next as $k => $v) { foreach ($next as $k => $v) {
if (is_integer($k)) { if (is_integer($k)) {

14
framework/helpers/base/Html.php

@ -324,7 +324,7 @@ class Html
$options['action'] = $action; $options['action'] = $action;
$options['method'] = $method; $options['method'] = $method;
$form = static::beginTag('form', $options); $form = static::beginTag('form', $options);
if ($hiddenInputs !== array()) { if (!empty($hiddenInputs)) {
$form .= "\n" . implode("\n", $hiddenInputs); $form .= "\n" . implode("\n", $hiddenInputs);
} }
@ -618,7 +618,7 @@ class Html
* is present, a hidden input will be generated so that if the radio button is not checked and is submitted, * is present, a hidden input will be generated so that if the radio button is not checked and is submitted,
* the value of this attribute will still be submitted to the server via the hidden input. * the value of this attribute will still be submitted to the server via the hidden input.
* *
* The rest of the options will be rendered as the attributes of the resulting tag. The values will * The rest of the options will be rendered as the attributes of the resulting tag. The values will
* be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. * be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered.
* *
* @return string the generated radio button tag * @return string the generated radio button tag
@ -647,7 +647,7 @@ class Html
* is present, a hidden input will be generated so that if the checkbox is not checked and is submitted, * is present, a hidden input will be generated so that if the checkbox is not checked and is submitted,
* the value of this attribute will still be submitted to the server via the hidden input. * the value of this attribute will still be submitted to the server via the hidden input.
* *
* The rest of the options will be rendered as the attributes of the resulting tag. The values will * The rest of the options will be rendered as the attributes of the resulting tag. The values will
* be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. * be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered.
* *
* @return string the generated checkbox tag * @return string the generated checkbox tag
@ -694,9 +694,9 @@ class Html
* - groups: array, the attributes for the optgroup tags. The structure of this is similar to that of 'options', * - groups: array, the attributes for the optgroup tags. The structure of this is similar to that of 'options',
* except that the array keys represent the optgroup labels specified in $items. * except that the array keys represent the optgroup labels specified in $items.
* *
* The rest of the options will be rendered as the attributes of the resulting tag. The values will * The rest of the options will be rendered as the attributes of the resulting tag. The values will
* be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. * be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered.
* *
* @return string the generated drop-down list tag * @return string the generated drop-down list tag
*/ */
public static function dropDownList($name, $selection = null, $items = array(), $options = array()) public static function dropDownList($name, $selection = null, $items = array(), $options = array())
@ -737,9 +737,9 @@ class Html
* When this attribute is set, a hidden field will be generated so that if no option is selected in multiple * When this attribute is set, a hidden field will be generated so that if no option is selected in multiple
* mode, we can still obtain the posted unselect value. * mode, we can still obtain the posted unselect value.
* *
* The rest of the options will be rendered as the attributes of the resulting tag. The values will * The rest of the options will be rendered as the attributes of the resulting tag. The values will
* be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. * be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered.
* *
* @return string the generated list box tag * @return string the generated list box tag
*/ */
public static function listBox($name, $selection = null, $items = array(), $options = array()) public static function listBox($name, $selection = null, $items = array(), $options = array())

4
framework/web/UrlManager.php

@ -190,13 +190,13 @@ class UrlManager extends Component
if ($this->suffix !== null) { if ($this->suffix !== null) {
$route .= $this->suffix; $route .= $this->suffix;
} }
if ($params !== array()) { if (!empty($params)) {
$route .= '?' . http_build_query($params); $route .= '?' . http_build_query($params);
} }
return rtrim($baseUrl, '/') . '/' . $route . $anchor; return rtrim($baseUrl, '/') . '/' . $route . $anchor;
} else { } else {
$url = $baseUrl . '?' . $this->routeVar . '=' . $route; $url = $baseUrl . '?' . $this->routeVar . '=' . $route;
if ($params !== array()) { if (!empty($params)) {
$url .= '&' . http_build_query($params); $url .= '&' . http_build_query($params);
} }
return $url; return $url;

4
framework/web/UrlRule.php

@ -144,7 +144,7 @@ class UrlRule extends Object
$this->_template = preg_replace('/<(\w+):?([^>]+)?>/', '<$1>', $this->pattern); $this->_template = preg_replace('/<(\w+):?([^>]+)?>/', '<$1>', $this->pattern);
$this->pattern = '#^' . trim(strtr($this->_template, $tr), '/') . '$#u'; $this->pattern = '#^' . trim(strtr($this->_template, $tr), '/') . '$#u';
if ($this->_routeParams !== array()) { if (!empty($this->_routeParams)) {
$this->_routeRule = '#^' . strtr($this->route, $tr2) . '$#u'; $this->_routeRule = '#^' . strtr($this->route, $tr2) . '$#u';
} }
} }
@ -275,7 +275,7 @@ class UrlRule extends Object
$url .= ($this->suffix === null ? $manager->suffix : $this->suffix); $url .= ($this->suffix === null ? $manager->suffix : $this->suffix);
} }
if ($params !== array()) { if (!empty($params)) {
$url .= '?' . http_build_query($params); $url .= '?' . http_build_query($params);
} }
return $url; return $url;

6
framework/widgets/ActiveField.php

@ -104,7 +104,7 @@ class ActiveField extends Component
public function begin() public function begin()
{ {
$options = $this->getClientOptions(); $options = $this->getClientOptions();
if ($options !== array()) { if (!empty($options)) {
$this->form->attributes[$this->attribute] = $options; $this->form->attributes[$this->attribute] = $options;
} }
@ -123,7 +123,7 @@ class ActiveField extends Component
return Html::beginTag($this->tag, $options); return Html::beginTag($this->tag, $options);
} }
public function end() public function end()
{ {
return Html::endTag($this->tag); return Html::endTag($this->tag);
@ -143,7 +143,7 @@ class ActiveField extends Component
$validators[] = $js; $validators[] = $js;
} }
} }
if ($validators !== array()) { if (!empty($validators)) {
$options['validate'] = new JsExpression("function(attribute,value,messages){" . implode('', $validators) . '}'); $options['validate'] = new JsExpression("function(attribute,value,messages){" . implode('', $validators) . '}');
} }
} }

4
framework/widgets/ActiveForm.php

@ -130,7 +130,7 @@ class ActiveForm extends Widget
*/ */
public function run() public function run()
{ {
if ($this->attributes !== array()) { if (!empty($this->attributes)) {
$id = $this->options['id']; $id = $this->options['id'];
$options = Json::encode($this->getClientOptions()); $options = Json::encode($this->getClientOptions());
$attributes = Json::encode($this->attributes); $attributes = Json::encode($this->attributes);
@ -197,7 +197,7 @@ class ActiveForm extends Widget
$options['class'] .= ' ' . $this->errorSummaryCssClass; $options['class'] .= ' ' . $this->errorSummaryCssClass;
} }
if ($lines !== array()) { if (!empty($lines)) {
$content = "<ul><li>" . implode("</li>\n<li>", $lines) . "</li><ul>"; $content = "<ul><li>" . implode("</li>\n<li>", $lines) . "</li><ul>";
return Html::tag('div', $header . $content . $footer, $options); return Html::tag('div', $header . $content . $footer, $options);
} else { } else {

2
framework/widgets/Menu.php

@ -166,7 +166,7 @@ class Menu extends Widget
if ($this->itemCssClass !== null) { if ($this->itemCssClass !== null) {
$class[] = $this->itemCssClass; $class[] = $this->itemCssClass;
} }
if ($class !== array()) { if (!empty($class)) {
if (empty($options['class'])) { if (empty($options['class'])) {
$options['class'] = implode(' ', $class); $options['class'] = implode(' ', $class);
} else { } else {

Loading…
Cancel
Save