diff --git a/framework/console/controllers/BaseMigrateController.php b/framework/console/controllers/BaseMigrateController.php index ff4acdfd44..03ba4b39ec 100644 --- a/framework/console/controllers/BaseMigrateController.php +++ b/framework/console/controllers/BaseMigrateController.php @@ -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]; } } diff --git a/framework/console/controllers/HelpController.php b/framework/console/controllers/HelpController.php index 889b8181ea..c24cf97be4 100644 --- a/framework/console/controllers/HelpController.php +++ b/framework/console/controllers/HelpController.php @@ -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); } } diff --git a/framework/console/controllers/MessageController.php b/framework/console/controllers/MessageController.php index f6c3feb0ee..60c8db05c4 100644 --- a/framework/console/controllers/MessageController.php +++ b/framework/console/controllers/MessageController.php @@ -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 { diff --git a/framework/data/Pagination.php b/framework/data/Pagination.php index 4f519f0958..09f551b95d 100644 --- a/framework/data/Pagination.php +++ b/framework/data/Pagination.php @@ -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]) { diff --git a/framework/db/ActiveRelationTrait.php b/framework/db/ActiveRelationTrait.php index 70eb649b90..17a5e97c3e 100644 --- a/framework/db/ActiveRelationTrait.php +++ b/framework/db/ActiveRelationTrait.php @@ -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) { diff --git a/framework/db/BaseActiveRecord.php b/framework/db/BaseActiveRecord.php index 673d222532..2243b4464b 100644 --- a/framework/db/BaseActiveRecord.php +++ b/framework/db/BaseActiveRecord.php @@ -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 = []; diff --git a/framework/db/QueryBuilder.php b/framework/db/QueryBuilder.php index d90238c2a5..da2c511a00 100644 --- a/framework/db/QueryBuilder.php +++ b/framework/db/QueryBuilder.php @@ -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)) { diff --git a/framework/helpers/BaseFileHelper.php b/framework/helpers/BaseFileHelper.php index a12101b81a..3a425c451c 100644 --- a/framework/helpers/BaseFileHelper.php +++ b/framework/helpers/BaseFileHelper.php @@ -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; diff --git a/framework/i18n/GettextMoFile.php b/framework/i18n/GettextMoFile.php index 300d486186..6946425150 100644 --- a/framework/i18n/GettextMoFile.php +++ b/framework/i18n/GettextMoFile.php @@ -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); } diff --git a/framework/log/Logger.php b/framework/log/Logger.php index aeb5fef5b4..a6ef2ae671 100644 --- a/framework/log/Logger.php +++ b/framework/log/Logger.php @@ -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; } diff --git a/framework/log/Target.php b/framework/log/Target.php index 8d4ca6083b..75179b0468 100644 --- a/framework/log/Target.php +++ b/framework/log/Target.php @@ -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; } diff --git a/framework/rbac/DbManager.php b/framework/rbac/DbManager.php index 056185f60e..11eed82c13 100644 --- a/framework/rbac/DbManager.php +++ b/framework/rbac/DbManager.php @@ -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(); diff --git a/framework/views/errorHandler/callStackItem.php b/framework/views/errorHandler/callStackItem.php index e86f44f3b9..0f30012a1e 100644 --- a/framework/views/errorHandler/callStackItem.php +++ b/framework/views/errorHandler/callStackItem.php @@ -9,7 +9,7 @@ /* @var $end integer */ /* @var $handler \yii\web\ErrorHandler */ ?> -
' . $this->htmlEncode($this->convertExceptionToString($exception)) . ''; } else { diff --git a/framework/web/Session.php b/framework/web/Session.php index 424e2327c2..0187072931 100644 --- a/framework/web/Session.php +++ b/framework/web/Session.php @@ -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; diff --git a/framework/widgets/BaseListView.php b/framework/widgets/BaseListView.php index 40fe191eb6..5b752b8ad9 100644 --- a/framework/widgets/BaseListView.php +++ b/framework/widgets/BaseListView.php @@ -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]); diff --git a/framework/widgets/InputWidget.php b/framework/widgets/InputWidget.php index 50bcd9eb4c..319eabcd6b 100644 --- a/framework/widgets/InputWidget.php +++ b/framework/widgets/InputWidget.php @@ -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'])) { diff --git a/framework/widgets/MaskedInput.php b/framework/widgets/MaskedInput.php index 0d49a8271e..2096ee99f4 100644 --- a/framework/widgets/MaskedInput.php +++ b/framework/widgets/MaskedInput.php @@ -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); }