mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
Optimized checks order in conditions
This commit is contained in:
@ -615,7 +615,7 @@ abstract class BaseMigrateController extends Controller
|
||||
continue;
|
||||
}
|
||||
$path = $this->migrationPath . DIRECTORY_SEPARATOR . $file;
|
||||
if (preg_match('/^(m(\d{6}_\d{6})_.*?)\.php$/', $file, $matches) && is_file($path) && !isset($applied[$matches[2]])) {
|
||||
if (preg_match('/^(m(\d{6}_\d{6})_.*?)\.php$/', $file, $matches) && !isset($applied[$matches[2]]) && is_file($path)) {
|
||||
$migrations[] = $matches[1];
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ class HelpController extends Controller
|
||||
$class = new \ReflectionClass($controller);
|
||||
foreach ($class->getMethods() as $method) {
|
||||
$name = $method->getName();
|
||||
if ($method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0 && $name !== 'actions') {
|
||||
if ($name !== 'actions' && $method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0) {
|
||||
$actions[] = Inflector::camel2id(substr($name, 6), '-', true);
|
||||
}
|
||||
}
|
||||
|
@ -398,7 +398,7 @@ class MessageController extends Controller
|
||||
}
|
||||
ksort($existingMessages);
|
||||
foreach ($existingMessages as $message => $translation) {
|
||||
if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeUnused) {
|
||||
if (!$removeUnused && !isset($merged[$message]) && !isset($todo[$message])) {
|
||||
if (!empty($translation) && strncmp($translation, '@@', 2) === 0 && substr_compare($translation, '@@', -2, 2) === 0) {
|
||||
$todo[$message] = $translation;
|
||||
} else {
|
||||
@ -512,7 +512,7 @@ EOD;
|
||||
|
||||
// add obsolete unused messages
|
||||
foreach ($existingMessages as $message => $translation) {
|
||||
if (!isset($merged[$category . chr(4) . $message]) && !isset($todos[$category . chr(4) . $message]) && !$removeUnused) {
|
||||
if (!$removeUnused && !isset($merged[$category . chr(4) . $message]) && !isset($todos[$category . chr(4) . $message])) {
|
||||
if (!empty($translation) && substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') {
|
||||
$todos[$category . chr(4) . $message] = $translation;
|
||||
} else {
|
||||
|
@ -232,7 +232,7 @@ class Pagination extends Object implements Linkable
|
||||
$this->_pageSize = null;
|
||||
} else {
|
||||
$value = (int) $value;
|
||||
if ($validatePageSize && count($this->pageSizeLimit) === 2 && isset($this->pageSizeLimit[0], $this->pageSizeLimit[1])) {
|
||||
if ($validatePageSize && isset($this->pageSizeLimit[0], $this->pageSizeLimit[1]) && count($this->pageSizeLimit) === 2) {
|
||||
if ($value < $this->pageSizeLimit[0]) {
|
||||
$value = $this->pageSizeLimit[0];
|
||||
} elseif ($value > $this->pageSizeLimit[1]) {
|
||||
|
@ -215,7 +215,7 @@ trait ActiveRelationTrait
|
||||
$this->filterByModels($primaryModels);
|
||||
}
|
||||
|
||||
if (count($primaryModels) === 1 && !$this->multiple) {
|
||||
if (!$this->multiple && count($primaryModels) === 1) {
|
||||
$model = $this->one();
|
||||
foreach ($primaryModels as $i => $primaryModel) {
|
||||
if ($primaryModel instanceof ActiveRecordInterface) {
|
||||
|
@ -980,7 +980,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
|
||||
public function getPrimaryKey($asArray = false)
|
||||
{
|
||||
$keys = $this->primaryKey();
|
||||
if (count($keys) === 1 && !$asArray) {
|
||||
if (!$asArray && count($keys) === 1) {
|
||||
return isset($this->_attributes[$keys[0]]) ? $this->_attributes[$keys[0]] : null;
|
||||
} else {
|
||||
$values = [];
|
||||
@ -1014,7 +1014,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
|
||||
if (empty($keys)) {
|
||||
throw new Exception(get_class($this) . ' does not have a primary key. You should either define a primary key for the corresponding table or override the primaryKey() method.');
|
||||
}
|
||||
if (count($keys) === 1 && !$asArray) {
|
||||
if (!$asArray && count($keys) === 1) {
|
||||
return isset($this->_oldAttributes[$keys[0]]) ? $this->_oldAttributes[$keys[0]] : null;
|
||||
} else {
|
||||
$values = [];
|
||||
|
@ -189,7 +189,7 @@ class QueryBuilder extends \yii\base\Object
|
||||
foreach ($rows as $row) {
|
||||
$vs = [];
|
||||
foreach ($row as $i => $value) {
|
||||
if (!is_array($value) && isset($columns[$i]) && isset($columnSchemas[$columns[$i]])) {
|
||||
if (isset($columns[$i], $columnSchemas[$columns[$i]]) && !is_array($value)) {
|
||||
$value = $columnSchemas[$columns[$i]]->dbTypecast($value);
|
||||
}
|
||||
if (is_string($value)) {
|
||||
|
@ -305,7 +305,7 @@ class BaseFileHelper
|
||||
if (!is_dir($dir)) {
|
||||
return;
|
||||
}
|
||||
if (!is_link($dir) || isset($options['traverseSymlinks']) && $options['traverseSymlinks']) {
|
||||
if (isset($options['traverseSymlinks']) && $options['traverseSymlinks'] || !is_link($dir)) {
|
||||
if (!($handle = opendir($dir))) {
|
||||
return;
|
||||
}
|
||||
@ -424,7 +424,7 @@ class BaseFileHelper
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_dir($path) && !empty($options['only'])) {
|
||||
if (!empty($options['only']) && !is_dir($path)) {
|
||||
if (($except = self::lastExcludeMatchingFromList($options['basePath'], $path, $options['only'])) !== null) {
|
||||
// don't check PATTERN_NEGATIVE since those entries are not prefixed with !
|
||||
return true;
|
||||
|
@ -109,8 +109,7 @@ class GettextMoFile extends GettextFile
|
||||
$separatorPosition = strpos($id, chr(4));
|
||||
|
||||
|
||||
if (($context && $separatorPosition !== false && strncmp($id, $context, $separatorPosition) === 0) ||
|
||||
(!$context && $separatorPosition === false)) {
|
||||
if ((!$context && $separatorPosition === false) || ($context && $separatorPosition !== false && strncmp($id, $context, $separatorPosition) === 0)) {
|
||||
if ($separatorPosition !== false) {
|
||||
$id = substr($id, $separatorPosition+1);
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ class Logger extends Component
|
||||
$matched = empty($categories);
|
||||
foreach ($categories as $category) {
|
||||
$prefix = rtrim($category, '*');
|
||||
if (strpos($timing['category'], $prefix) === 0 && ($timing['category'] === $category || $prefix !== $category)) {
|
||||
if (($timing['category'] === $category || $prefix !== $category) && strpos($timing['category'], $prefix) === 0) {
|
||||
$matched = true;
|
||||
break;
|
||||
}
|
||||
@ -219,7 +219,7 @@ class Logger extends Component
|
||||
foreach ($excludeCategories as $category) {
|
||||
$prefix = rtrim($category, '*');
|
||||
foreach ($timings as $i => $timing) {
|
||||
if (strpos($timing['category'], $prefix) === 0 && ($timing['category'] === $category || $prefix !== $category)) {
|
||||
if (($timing['category'] === $category || $prefix !== $category) && strpos($timing['category'], $prefix) === 0) {
|
||||
$matched = false;
|
||||
break;
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ abstract class Target extends Component
|
||||
if ($matched) {
|
||||
foreach ($except as $category) {
|
||||
$prefix = rtrim($category, '*');
|
||||
if (strpos($message[2], $prefix) === 0 && ($message[2] === $category || $prefix !== $category)) {
|
||||
if (($message[2] === $category || $prefix !== $category) && strpos($message[2], $prefix) === 0) {
|
||||
$matched = false;
|
||||
break;
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ class DbManager extends BaseManager
|
||||
*/
|
||||
protected function updateItem($name, $item)
|
||||
{
|
||||
if (!$this->supportsCascadeUpdate() && $item->name !== $name) {
|
||||
if ($item->name !== $name && !$this->supportsCascadeUpdate()) {
|
||||
$this->db->createCommand()
|
||||
->update($this->itemChildTable, ['parent' => $item->name], ['parent' => $name])
|
||||
->execute();
|
||||
@ -259,7 +259,7 @@ class DbManager extends BaseManager
|
||||
*/
|
||||
protected function updateRule($name, $rule)
|
||||
{
|
||||
if (!$this->supportsCascadeUpdate() && $rule->name !== $name) {
|
||||
if ($rule->name !== $name && !$this->supportsCascadeUpdate()) {
|
||||
$this->db->createCommand()
|
||||
->update($this->itemTable, ['rule_name' => $rule->name], ['rule_name' => $name])
|
||||
->execute();
|
||||
|
@ -9,7 +9,7 @@
|
||||
/* @var $end integer */
|
||||
/* @var $handler \yii\web\ErrorHandler */
|
||||
?>
|
||||
<li class="<?php if (!$handler->isCoreFile($file) || $index === 1) echo 'application'; ?> call-stack-item"
|
||||
<li class="<?php if ($index === 1 || !$handler->isCoreFile($file)) echo 'application'; ?> call-stack-item"
|
||||
data-line="<?= (int) ($line - $begin) ?>">
|
||||
<div class="element-wrap">
|
||||
<div class="element">
|
||||
|
@ -448,7 +448,7 @@ class AssetManager extends Component
|
||||
if (!is_dir($dstDir)) {
|
||||
symlink($src, $dstDir);
|
||||
}
|
||||
} elseif (!is_dir($dstDir) || !empty($options['forceCopy']) || (!isset($options['forceCopy']) && $this->forceCopy)) {
|
||||
} elseif (!empty($options['forceCopy']) || ($this->forceCopy && !isset($options['forceCopy'])) || !is_dir($dstDir)) {
|
||||
$opts = [
|
||||
'dirMode' => $this->dirMode,
|
||||
'fileMode' => $this->fileMode,
|
||||
|
@ -84,7 +84,7 @@ class ErrorHandler extends \yii\base\ErrorHandler
|
||||
$response->data = $result;
|
||||
}
|
||||
} elseif ($response->format === Response::FORMAT_HTML) {
|
||||
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest' || YII_ENV_TEST) {
|
||||
if (YII_ENV_TEST || isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest') {
|
||||
// AJAX request
|
||||
$response->data = '<pre>' . $this->htmlEncode($this->convertExceptionToString($exception)) . '</pre>';
|
||||
} else {
|
||||
|
@ -205,7 +205,7 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
|
||||
if ($this->_hasSessionId === null) {
|
||||
$name = $this->getName();
|
||||
$request = Yii::$app->getRequest();
|
||||
if (ini_get('session.use_cookies') && !empty($_COOKIE[$name])) {
|
||||
if (!empty($_COOKIE[$name]) && ini_get('session.use_cookies')) {
|
||||
$this->_hasSessionId = true;
|
||||
} elseif (!ini_get('session.use_only_cookies') && ini_get('session.use_trans_sid')) {
|
||||
$this->_hasSessionId = $request->get($name) !== null;
|
||||
|
@ -121,7 +121,7 @@ abstract class BaseListView extends Widget
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
if ($this->dataProvider->getCount() > 0 || $this->showOnEmpty) {
|
||||
if ($this->showOnEmpty || $this->dataProvider->getCount() > 0) {
|
||||
$content = preg_replace_callback("/{\\w+}/", function ($matches) {
|
||||
$content = $this->renderSection($matches[0]);
|
||||
|
||||
|
@ -54,7 +54,7 @@ class InputWidget extends Widget
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if (!$this->hasModel() && $this->name === null) {
|
||||
if ($this->name === null && !$this->hasModel()) {
|
||||
throw new InvalidConfigException("Either 'name', or 'model' and 'attribute' properties must be specified.");
|
||||
}
|
||||
if (!isset($this->options['id'])) {
|
||||
|
@ -143,8 +143,8 @@ class MaskedInput extends InputWidget
|
||||
{
|
||||
$options = $this->clientOptions;
|
||||
foreach ($options as $key => $value) {
|
||||
if (in_array($key, ['oncomplete', 'onincomplete', 'oncleared', 'onKeyUp', 'onKeyDown', 'onBeforeMask',
|
||||
'onBeforePaste', 'onUnMask', 'isComplete', 'determineActiveMasksetIndex']) && !$value instanceof JsExpression
|
||||
if (!$value instanceof JsExpression && in_array($key, ['oncomplete', 'onincomplete', 'oncleared', 'onKeyUp',
|
||||
'onKeyDown', 'onBeforeMask', 'onBeforePaste', 'onUnMask', 'isComplete', 'determineActiveMasksetIndex'])
|
||||
) {
|
||||
$options[$key] = new JsExpression($value);
|
||||
}
|
||||
|
Reference in New Issue
Block a user