From fe8a0a6a2ed09ae5b255e7f3b3e16c16d8789e3a Mon Sep 17 00:00:00 2001 From: Robert Korulczyk Date: Mon, 10 Jul 2017 10:26:21 +0200 Subject: [PATCH] Enable `no_useless_else` rule in php-cs-fixer (#14420) --- build/controllers/Utf8Controller.php | 4 +- cs/src/YiiConfig.php | 2 +- framework/base/Action.php | 4 +- framework/base/Application.php | 4 +- framework/base/DynamicModel.php | 8 +- framework/base/Object.php | 8 +- framework/base/Theme.php | 8 +- framework/base/Widget.php | 8 +- framework/caching/Cache.php | 4 +- framework/caching/FileCache.php | 12 +- framework/caching/MemCache.php | 4 +- framework/captcha/CaptchaAction.php | 13 +- framework/console/Application.php | 14 +- framework/console/controllers/AssetController.php | 10 +- .../console/controllers/BaseMigrateController.php | 24 ++-- framework/console/controllers/HelpController.php | 4 +- .../console/controllers/MigrateController.php | 4 +- framework/data/ActiveDataProvider.php | 4 +- framework/data/ArrayDataProvider.php | 4 +- framework/data/Pagination.php | 12 +- framework/data/Sort.php | 4 +- framework/db/ActiveQuery.php | 11 +- framework/db/ActiveRelationTrait.php | 82 ++++++------ framework/db/BaseActiveRecord.php | 77 +++++------ framework/db/ColumnSchemaBuilder.php | 4 +- framework/db/Command.php | 8 +- framework/db/Connection.php | 30 ++--- framework/db/Query.php | 11 +- framework/db/QueryBuilder.php | 42 +++--- framework/db/QueryTrait.php | 21 +-- framework/db/Schema.php | 26 ++-- framework/db/cubrid/QueryBuilder.php | 4 +- framework/db/mssql/QueryBuilder.php | 8 +- framework/db/mysql/QueryBuilder.php | 4 +- framework/db/pgsql/QueryBuilder.php | 4 +- framework/db/sqlite/QueryBuilder.php | 4 +- framework/di/Container.php | 34 ++--- framework/di/Instance.php | 12 +- framework/di/ServiceLocator.php | 16 +-- framework/filters/ContentNegotiator.php | 4 +- framework/filters/HttpCache.php | 4 +- framework/filters/PageCache.php | 8 +- framework/filters/RateLimiter.php | 6 +- framework/filters/auth/AuthMethod.php | 9 +- framework/grid/ActionColumn.php | 14 +- framework/grid/CheckboxColumn.php | 4 +- framework/grid/Column.php | 4 +- framework/grid/DataColumn.php | 20 +-- framework/grid/GridView.php | 20 +-- framework/grid/SerialColumn.php | 4 +- framework/helpers/BaseArrayHelper.php | 53 ++++---- framework/helpers/BaseFileHelper.php | 18 +-- framework/helpers/BaseHtml.php | 28 ++-- framework/helpers/BaseInflector.php | 8 +- framework/helpers/BaseStringHelper.php | 20 +-- framework/helpers/BaseUrl.php | 14 +- framework/i18n/DbMessageSource.php | 4 +- framework/i18n/Formatter.php | 142 +++++++++++---------- framework/i18n/GettextMessageSource.php | 4 +- framework/i18n/GettextMoFile.php | 4 +- framework/i18n/I18N.php | 44 +++---- framework/i18n/MessageFormatter.php | 16 +-- framework/i18n/MessageSource.php | 4 +- framework/i18n/PhpMessageSource.php | 4 +- framework/mail/BaseMailer.php | 4 +- framework/mutex/FileMutex.php | 12 +- framework/mutex/Mutex.php | 8 +- framework/rbac/BaseManager.php | 16 +-- framework/rbac/DbManager.php | 4 +- framework/rbac/PhpManager.php | 83 ++++++------ framework/rest/Action.php | 4 +- framework/rest/Serializer.php | 28 ++-- framework/test/ActiveFixture.php | 4 +- framework/test/ArrayFixture.php | 4 +- framework/test/BaseActiveFixture.php | 4 +- framework/validators/CompareValidator.php | 4 +- framework/validators/DateValidator.php | 11 +- framework/validators/EachValidator.php | 8 +- framework/validators/ExistValidator.php | 4 +- framework/validators/InlineValidator.php | 4 +- framework/validators/IpValidator.php | 21 +-- framework/validators/NumberValidator.php | 4 +- framework/validators/RequiredValidator.php | 8 +- framework/validators/Validator.php | 4 +- framework/web/Application.php | 20 +-- framework/web/AssetManager.php | 28 ++-- framework/web/ErrorHandler.php | 8 +- framework/web/GroupUrlRule.php | 10 +- framework/web/HeaderCollection.php | 8 +- framework/web/HttpException.php | 4 +- framework/web/MultiFieldSession.php | 4 +- framework/web/Response.php | 4 +- framework/web/Session.php | 12 +- framework/web/UrlManager.php | 44 +++---- framework/web/UrlRule.php | 8 +- framework/web/User.php | 8 +- framework/web/ViewAction.php | 12 +- framework/widgets/ActiveForm.php | 4 +- framework/widgets/DetailView.php | 4 +- framework/widgets/Menu.php | 12 +- tests/data/ar/Order.php | 4 +- .../controllers/PHPMessageControllerTest.php | 4 +- tests/framework/log/DispatcherTest.php | 4 +- 103 files changed, 742 insertions(+), 716 deletions(-) diff --git a/build/controllers/Utf8Controller.php b/build/controllers/Utf8Controller.php index 76d4d18..133928a 100644 --- a/build/controllers/Utf8Controller.php +++ b/build/controllers/Utf8Controller.php @@ -119,8 +119,8 @@ class Utf8Controller extends Controller return ($h & 0x0F) << 18 | (ord($c[1]) & 0x3F) << 12 | (ord($c[2]) & 0x3F) << 6 | (ord($c[3]) & 0x3F); - } else { - return false; } + + return false; } } diff --git a/cs/src/YiiConfig.php b/cs/src/YiiConfig.php index 4777805..0c452da 100644 --- a/cs/src/YiiConfig.php +++ b/cs/src/YiiConfig.php @@ -91,7 +91,7 @@ class YiiConfig extends Config 'no_trailing_comma_in_singleline_array' => true, 'no_unneeded_control_parentheses' => true, 'no_unused_imports' => true, -// 'no_useless_else' => true, // needs more discussion + 'no_useless_else' => true, 'no_useless_return' => true, 'no_whitespace_before_comma_in_array' => true, 'no_whitespace_in_blank_line' => true, diff --git a/framework/base/Action.php b/framework/base/Action.php index 9dc7063..3c0dbd6 100644 --- a/framework/base/Action.php +++ b/framework/base/Action.php @@ -95,9 +95,9 @@ class Action extends Component $this->afterRun(); return $result; - } else { - return null; } + + return null; } /** diff --git a/framework/base/Application.php b/framework/base/Application.php index 95380a6..3d5f498 100644 --- a/framework/base/Application.php +++ b/framework/base/Application.php @@ -651,9 +651,9 @@ abstract class Application extends Module if (YII_ENV_TEST) { throw new ExitException($status); - } else { - exit($status); } + + exit($status); } /** diff --git a/framework/base/DynamicModel.php b/framework/base/DynamicModel.php index 69e271a..a0c5bf8 100644 --- a/framework/base/DynamicModel.php +++ b/framework/base/DynamicModel.php @@ -82,9 +82,9 @@ class DynamicModel extends Model { if (array_key_exists($name, $this->_attributes)) { return $this->_attributes[$name]; - } else { - return parent::__get($name); } + + return parent::__get($name); } /** @@ -106,9 +106,9 @@ class DynamicModel extends Model { if (array_key_exists($name, $this->_attributes)) { return isset($this->_attributes[$name]); - } else { - return parent::__isset($name); } + + return parent::__isset($name); } /** diff --git a/framework/base/Object.php b/framework/base/Object.php index ff674b5..d37e29b 100644 --- a/framework/base/Object.php +++ b/framework/base/Object.php @@ -134,9 +134,9 @@ class Object implements Configurable return $this->$getter(); } elseif (method_exists($this, 'set' . $name)) { throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name); - } else { - throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name); } + + throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name); } /** @@ -178,9 +178,9 @@ class Object implements Configurable $getter = 'get' . $name; if (method_exists($this, $getter)) { return $this->$getter() !== null; - } else { - return false; } + + return false; } /** diff --git a/framework/base/Theme.php b/framework/base/Theme.php index 32a0f4d..514e8fe 100644 --- a/framework/base/Theme.php +++ b/framework/base/Theme.php @@ -166,9 +166,9 @@ class Theme extends Component { if (($baseUrl = $this->getBaseUrl()) !== null) { return $baseUrl . '/' . ltrim($url, '/'); - } else { - throw new InvalidConfigException('The "baseUrl" property must be set.'); } + + throw new InvalidConfigException('The "baseUrl" property must be set.'); } /** @@ -181,8 +181,8 @@ class Theme extends Component { if (($basePath = $this->getBasePath()) !== null) { return $basePath . DIRECTORY_SEPARATOR . ltrim($path, '/\\'); - } else { - throw new InvalidConfigException('The "basePath" property must be set.'); } + + throw new InvalidConfigException('The "basePath" property must be set.'); } } diff --git a/framework/base/Widget.php b/framework/base/Widget.php index 2ae908d..bdd8b16 100644 --- a/framework/base/Widget.php +++ b/framework/base/Widget.php @@ -111,12 +111,12 @@ class Widget extends Component implements ViewContextInterface echo $result; } return $widget; - } else { - throw new InvalidCallException('Expecting end() of ' . get_class($widget) . ', found ' . get_called_class()); } - } else { - throw new InvalidCallException('Unexpected ' . get_called_class() . '::end() call. A matching begin() is not found.'); + + throw new InvalidCallException('Expecting end() of ' . get_class($widget) . ', found ' . get_called_class()); } + + throw new InvalidCallException('Unexpected ' . get_called_class() . '::end() call. A matching begin() is not found.'); } /** diff --git a/framework/caching/Cache.php b/framework/caching/Cache.php index 42e7139..d11b4bf 100644 --- a/framework/caching/Cache.php +++ b/framework/caching/Cache.php @@ -121,9 +121,9 @@ abstract class Cache extends Component implements CacheInterface } if (is_array($value) && !($value[1] instanceof Dependency && $value[1]->isChanged($this))) { return $value[0]; - } else { - return false; } + + return false; } /** diff --git a/framework/caching/FileCache.php b/framework/caching/FileCache.php index 31939b0..d884f80 100644 --- a/framework/caching/FileCache.php +++ b/framework/caching/FileCache.php @@ -150,11 +150,11 @@ class FileCache extends Cache } return @touch($cacheFile, $duration + time()); - } else { - $error = error_get_last(); - Yii::warning("Unable to write cache file '{$cacheFile}': {$error['message']}", __METHOD__); - return false; } + + $error = error_get_last(); + Yii::warning("Unable to write cache file '{$cacheFile}': {$error['message']}", __METHOD__); + return false; } /** @@ -206,9 +206,9 @@ class FileCache extends Cache } return $base . DIRECTORY_SEPARATOR . $key . $this->cacheFileSuffix; - } else { - return $this->cachePath . DIRECTORY_SEPARATOR . $key . $this->cacheFileSuffix; } + + return $this->cachePath . DIRECTORY_SEPARATOR . $key . $this->cacheFileSuffix; } /** diff --git a/framework/caching/MemCache.php b/framework/caching/MemCache.php index 7a5dac1..92fa947 100644 --- a/framework/caching/MemCache.php +++ b/framework/caching/MemCache.php @@ -317,9 +317,9 @@ class MemCache extends Cache // Memcached::setMulti() returns boolean // @see http://php.net/manual/en/memcached.setmulti.php return $this->_cache->setMulti($data, $expire) ? [] : array_keys($data); - } else { - return parent::setValues($data, $duration); } + + return parent::setValues($data, $duration); } /** diff --git a/framework/captcha/CaptchaAction.php b/framework/captcha/CaptchaAction.php index 81f3b3d..b7a7c95 100644 --- a/framework/captcha/CaptchaAction.php +++ b/framework/captcha/CaptchaAction.php @@ -134,11 +134,12 @@ class CaptchaAction extends Action // when src attribute of image tag is changed 'url' => Url::to([$this->id, 'v' => uniqid()]), ]; - } else { - $this->setHttpHeaders(); - Yii::$app->response->format = Response::FORMAT_RAW; - return $this->renderImage($this->getVerifyCode()); } + + $this->setHttpHeaders(); + Yii::$app->response->format = Response::FORMAT_RAW; + + return $this->renderImage($this->getVerifyCode()); } /** @@ -255,9 +256,9 @@ class CaptchaAction extends Action return $this->renderImageByGD($code); } elseif ($imageLibrary === 'imagick') { return $this->renderImageByImagick($code); - } else { - throw new InvalidConfigException("Defined library '{$imageLibrary}' is not supported"); } + + throw new InvalidConfigException("Defined library '{$imageLibrary}' is not supported"); } /** diff --git a/framework/console/Application.php b/framework/console/Application.php index 758aafe..6210d86 100644 --- a/framework/console/Application.php +++ b/framework/console/Application.php @@ -106,9 +106,9 @@ class Application extends \yii\base\Application $path = substr($param, strlen($option)); if (!empty($path) && is_file($file = Yii::getAlias($path))) { return require($file); - } else { - exit("The configuration file does not exist: $path\n"); } + + exit("The configuration file does not exist: $path\n"); } } } @@ -147,12 +147,12 @@ class Application extends \yii\base\Application $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; - } else { - $response = $this->getResponse(); - $response->exitStatus = $result; - - return $response; } + + $response = $this->getResponse(); + $response->exitStatus = $result; + + return $response; } /** diff --git a/framework/console/controllers/AssetController.php b/framework/console/controllers/AssetController.php index dc63c7c..3417fa1 100644 --- a/framework/console/controllers/AssetController.php +++ b/framework/console/controllers/AssetController.php @@ -320,9 +320,9 @@ class AssetController extends Controller usort($target['depends'], function ($a, $b) use ($bundleOrders) { if ($bundleOrders[$a] == $bundleOrders[$b]) { return 0; - } else { - return $bundleOrders[$a] > $bundleOrders[$b] ? 1 : -1; } + + return $bundleOrders[$a] > $bundleOrders[$b] ? 1 : -1; }); if (!isset($target['class'])) { $target['class'] = $name; @@ -732,10 +732,10 @@ EOD; } if (!file_put_contents($configFile, $template)) { throw new Exception("Unable to write template file '{$configFile}'."); - } else { - $this->stdout("Configuration file template created at '{$configFile}'.\n\n", Console::FG_GREEN); - return self::EXIT_CODE_NORMAL; } + + $this->stdout("Configuration file template created at '{$configFile}'.\n\n", Console::FG_GREEN); + return self::EXIT_CODE_NORMAL; } /** diff --git a/framework/console/controllers/BaseMigrateController.php b/framework/console/controllers/BaseMigrateController.php index 25fec0b..e8f5e46 100644 --- a/framework/console/controllers/BaseMigrateController.php +++ b/framework/console/controllers/BaseMigrateController.php @@ -130,9 +130,9 @@ abstract class BaseMigrateController extends Controller $this->stdout("Yii Migration Tool (based on Yii v{$version})\n\n"); return true; - } else { - return false; } + + return false; } /** @@ -673,12 +673,12 @@ abstract class BaseMigrateController extends Controller $this->stdout("*** applied $class (time: " . sprintf('%.3f', $time) . "s)\n\n", Console::FG_GREEN); return true; - } else { - $time = microtime(true) - $start; - $this->stdout("*** failed to apply $class (time: " . sprintf('%.3f', $time) . "s)\n\n", Console::FG_RED); - - return false; } + + $time = microtime(true) - $start; + $this->stdout("*** failed to apply $class (time: " . sprintf('%.3f', $time) . "s)\n\n", Console::FG_RED); + + return false; } /** @@ -701,12 +701,12 @@ abstract class BaseMigrateController extends Controller $this->stdout("*** reverted $class (time: " . sprintf('%.3f', $time) . "s)\n\n", Console::FG_GREEN); return true; - } else { - $time = microtime(true) - $start; - $this->stdout("*** failed to revert $class (time: " . sprintf('%.3f', $time) . "s)\n\n", Console::FG_RED); - - return false; } + + $time = microtime(true) - $start; + $this->stdout("*** failed to revert $class (time: " . sprintf('%.3f', $time) . "s)\n\n", Console::FG_RED); + + return false; } /** diff --git a/framework/console/controllers/HelpController.php b/framework/console/controllers/HelpController.php index e6649df..aa5e6c3 100644 --- a/framework/console/controllers/HelpController.php +++ b/framework/console/controllers/HelpController.php @@ -273,9 +273,9 @@ class HelpController extends Controller if (class_exists($controllerClass)) { $class = new \ReflectionClass($controllerClass); return !$class->isAbstract() && $class->isSubclassOf('yii\console\Controller'); - } else { - return false; } + + return false; } /** diff --git a/framework/console/controllers/MigrateController.php b/framework/console/controllers/MigrateController.php index c234e35..f9ea987 100644 --- a/framework/console/controllers/MigrateController.php +++ b/framework/console/controllers/MigrateController.php @@ -170,9 +170,9 @@ class MigrateController extends BaseMigrateController $this->db = Instance::ensure($this->db, Connection::className()); } return true; - } else { - return false; } + + return false; } /** diff --git a/framework/data/ActiveDataProvider.php b/framework/data/ActiveDataProvider.php index 6fd1b44..e304008 100644 --- a/framework/data/ActiveDataProvider.php +++ b/framework/data/ActiveDataProvider.php @@ -152,9 +152,9 @@ class ActiveDataProvider extends BaseDataProvider } return $keys; - } else { - return array_keys($models); } + + return array_keys($models); } /** diff --git a/framework/data/ArrayDataProvider.php b/framework/data/ArrayDataProvider.php index 2680b0d..c6f621a 100644 --- a/framework/data/ArrayDataProvider.php +++ b/framework/data/ArrayDataProvider.php @@ -113,9 +113,9 @@ class ArrayDataProvider extends BaseDataProvider } return $keys; - } else { - return array_keys($models); } + + return array_keys($models); } /** diff --git a/framework/data/Pagination.php b/framework/data/Pagination.php index 429a508..7404c4d 100644 --- a/framework/data/Pagination.php +++ b/framework/data/Pagination.php @@ -153,11 +153,11 @@ class Pagination extends Object implements Linkable $pageSize = $this->getPageSize(); if ($pageSize < 1) { return $this->totalCount > 0 ? 1 : 0; - } else { - $totalCount = $this->totalCount < 0 ? 0 : (int) $this->totalCount; - - return (int) (($totalCount + $pageSize - 1) / $pageSize); } + + $totalCount = $this->totalCount < 0 ? 0 : (int) $this->totalCount; + + return (int) (($totalCount + $pageSize - 1) / $pageSize); } private $_page; @@ -281,9 +281,9 @@ class Pagination extends Object implements Linkable $urlManager = $this->urlManager === null ? Yii::$app->getUrlManager() : $this->urlManager; if ($absolute) { return $urlManager->createAbsoluteUrl($params); - } else { - return $urlManager->createUrl($params); } + + return $urlManager->createUrl($params); } /** diff --git a/framework/data/Sort.php b/framework/data/Sort.php index 46f8204..d3dd59d 100644 --- a/framework/data/Sort.php +++ b/framework/data/Sort.php @@ -412,9 +412,9 @@ class Sort extends Object $urlManager = $this->urlManager === null ? Yii::$app->getUrlManager() : $this->urlManager; if ($absolute) { return $urlManager->createAbsoluteUrl($params); - } else { - return $urlManager->createUrl($params); } + + return $urlManager->createUrl($params); } /** diff --git a/framework/db/ActiveQuery.php b/framework/db/ActiveQuery.php index 03f6ed2..7145b1d 100644 --- a/framework/db/ActiveQuery.php +++ b/framework/db/ActiveQuery.php @@ -295,9 +295,9 @@ class ActiveQuery extends Query implements ActiveQueryInterface if ($row !== false) { $models = $this->populate([$row]); return reset($models) ?: null; - } else { - return null; } + + return null; } /** @@ -545,9 +545,9 @@ class ActiveQuery extends Query implements ActiveQueryInterface { if (is_array($joinType) && isset($joinType[$name])) { return $joinType[$name]; - } else { - return is_string($joinType) ? $joinType : 'INNER JOIN'; } + + return is_string($joinType) ? $joinType : 'INNER JOIN'; } /** @@ -564,9 +564,8 @@ class ActiveQuery extends Query implements ActiveQueryInterface foreach ($this->from as $alias => $tableName) { if (is_string($alias)) { return [$tableName, $alias]; - } else { - break; } + break; } } diff --git a/framework/db/ActiveRelationTrait.php b/framework/db/ActiveRelationTrait.php index dfe3a55..85c021c 100644 --- a/framework/db/ActiveRelationTrait.php +++ b/framework/db/ActiveRelationTrait.php @@ -232,57 +232,57 @@ trait ActiveRelationTrait } return [$model]; + } + + // https://github.com/yiisoft/yii2/issues/3197 + // delay indexing related models after buckets are built + $indexBy = $this->indexBy; + $this->indexBy = null; + $models = $this->all(); + + if (isset($viaModels, $viaQuery)) { + $buckets = $this->buildBuckets($models, $this->link, $viaModels, $viaQuery->link); } else { - // https://github.com/yiisoft/yii2/issues/3197 - // delay indexing related models after buckets are built - $indexBy = $this->indexBy; - $this->indexBy = null; - $models = $this->all(); - - if (isset($viaModels, $viaQuery)) { - $buckets = $this->buildBuckets($models, $this->link, $viaModels, $viaQuery->link); - } else { - $buckets = $this->buildBuckets($models, $this->link); - } + $buckets = $this->buildBuckets($models, $this->link); + } - $this->indexBy = $indexBy; - if ($this->indexBy !== null && $this->multiple) { - $buckets = $this->indexBuckets($buckets, $this->indexBy); - } + $this->indexBy = $indexBy; + if ($this->indexBy !== null && $this->multiple) { + $buckets = $this->indexBuckets($buckets, $this->indexBy); + } - $link = array_values(isset($viaQuery) ? $viaQuery->link : $this->link); - foreach ($primaryModels as $i => $primaryModel) { - if ($this->multiple && count($link) === 1 && is_array($keys = $primaryModel[reset($link)])) { - $value = []; - foreach ($keys as $key) { - $key = $this->normalizeModelKey($key); - if (isset($buckets[$key])) { - if ($this->indexBy !== null) { - // if indexBy is set, array_merge will cause renumbering of numeric array - foreach ($buckets[$key] as $bucketKey => $bucketValue) { - $value[$bucketKey] = $bucketValue; - } - } else { - $value = array_merge($value, $buckets[$key]); + $link = array_values(isset($viaQuery) ? $viaQuery->link : $this->link); + foreach ($primaryModels as $i => $primaryModel) { + if ($this->multiple && count($link) === 1 && is_array($keys = $primaryModel[reset($link)])) { + $value = []; + foreach ($keys as $key) { + $key = $this->normalizeModelKey($key); + if (isset($buckets[$key])) { + if ($this->indexBy !== null) { + // if indexBy is set, array_merge will cause renumbering of numeric array + foreach ($buckets[$key] as $bucketKey => $bucketValue) { + $value[$bucketKey] = $bucketValue; } + } else { + $value = array_merge($value, $buckets[$key]); } } - } else { - $key = $this->getModelKey($primaryModel, $link); - $value = isset($buckets[$key]) ? $buckets[$key] : ($this->multiple ? [] : null); - } - if ($primaryModel instanceof ActiveRecordInterface) { - $primaryModel->populateRelation($name, $value); - } else { - $primaryModels[$i][$name] = $value; } + } else { + $key = $this->getModelKey($primaryModel, $link); + $value = isset($buckets[$key]) ? $buckets[$key] : ($this->multiple ? [] : null); } - if ($this->inverseOf !== null) { - $this->populateInverseRelation($primaryModels, $models, $name, $this->inverseOf); + if ($primaryModel instanceof ActiveRecordInterface) { + $primaryModel->populateRelation($name, $value); + } else { + $primaryModels[$i][$name] = $value; } - - return $models; } + if ($this->inverseOf !== null) { + $this->populateInverseRelation($primaryModels, $models, $name, $this->inverseOf); + } + + return $models; } /** diff --git a/framework/db/BaseActiveRecord.php b/framework/db/BaseActiveRecord.php index 1afc56d..b1e4b13 100644 --- a/framework/db/BaseActiveRecord.php +++ b/framework/db/BaseActiveRecord.php @@ -278,17 +278,17 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface return $this->_attributes[$name]; } elseif ($this->hasAttribute($name)) { return null; - } else { - if (isset($this->_related[$name]) || array_key_exists($name, $this->_related)) { - return $this->_related[$name]; - } - $value = parent::__get($name); - if ($value instanceof ActiveQueryInterface) { - return $this->_related[$name] = $value->findFor($name, $this); - } else { - return $value; - } } + + if (isset($this->_related[$name]) || array_key_exists($name, $this->_related)) { + return $this->_related[$name]; + } + $value = parent::__get($name); + if ($value instanceof ActiveQueryInterface) { + return $this->_related[$name] = $value->findFor($name, $this); + } + + return $value; } /** @@ -575,12 +575,12 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface if (isset($this->_attributes[$name], $this->_oldAttributes[$name])) { if ($identical) { return $this->_attributes[$name] !== $this->_oldAttributes[$name]; - } else { - return $this->_attributes[$name] != $this->_oldAttributes[$name]; } - } else { - return isset($this->_attributes[$name]) || isset($this->_oldAttributes[$name]); + + return $this->_attributes[$name] != $this->_oldAttributes[$name]; } + + return isset($this->_attributes[$name]) || isset($this->_oldAttributes[$name]); } /** @@ -641,9 +641,9 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface { if ($this->getIsNewRecord()) { return $this->insert($runValidation, $attributeNames); - } else { - return $this->update($runValidation, $attributeNames) !== false; } + + return $this->update($runValidation, $attributeNames) !== false; } /** @@ -819,10 +819,11 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface } $this->_oldAttributes[$name] = $this->_attributes[$name]; } + return true; - } else { - return false; } + + return false; } /** @@ -1074,14 +1075,14 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface $keys = $this->primaryKey(); if (!$asArray && count($keys) === 1) { return isset($this->_attributes[$keys[0]]) ? $this->_attributes[$keys[0]] : null; - } else { - $values = []; - foreach ($keys as $name) { - $values[$name] = isset($this->_attributes[$name]) ? $this->_attributes[$name] : null; - } + } - return $values; + $values = []; + foreach ($keys as $name) { + $values[$name] = isset($this->_attributes[$name]) ? $this->_attributes[$name] : null; } + + return $values; } /** @@ -1108,14 +1109,14 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface } if (!$asArray && count($keys) === 1) { return isset($this->_oldAttributes[$keys[0]]) ? $this->_oldAttributes[$keys[0]] : null; - } else { - $values = []; - foreach ($keys as $name) { - $values[$name] = isset($this->_oldAttributes[$name]) ? $this->_oldAttributes[$name] : null; - } + } - return $values; + $values = []; + foreach ($keys as $name) { + $values[$name] = isset($this->_oldAttributes[$name]) ? $this->_oldAttributes[$name] : null; } + + return $values; } /** @@ -1193,16 +1194,16 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface } catch (UnknownMethodException $e) { if ($throwException) { throw new InvalidParamException(get_class($this) . ' has no relation named "' . $name . '".', 0, $e); - } else { - return null; } + + return null; } if (!$relation instanceof ActiveQueryInterface) { if ($throwException) { throw new InvalidParamException(get_class($this) . ' has no relation named "' . $name . '".'); - } else { - return null; } + + return null; } if (method_exists($this, $getter)) { @@ -1212,9 +1213,9 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface if ($realName !== $name) { if ($throwException) { throw new InvalidParamException('Relation names are case sensitive. ' . get_class($this) . " has a relation named \"$realName\" instead of \"$name\"."); - } else { - return null; } + + return null; } } @@ -1538,9 +1539,9 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface $pks = static::primaryKey(); if (count($keys) === count($pks)) { return count(array_intersect($keys, $pks)) === count($pks); - } else { - return false; } + + return false; } /** diff --git a/framework/db/ColumnSchemaBuilder.php b/framework/db/ColumnSchemaBuilder.php index 34aae2e..d9ff8a2 100644 --- a/framework/db/ColumnSchemaBuilder.php +++ b/framework/db/ColumnSchemaBuilder.php @@ -312,9 +312,9 @@ class ColumnSchemaBuilder extends Object return ' NOT NULL'; } elseif ($this->isNotNull === false) { return ' NULL'; - } else { - return ''; } + + return ''; } /** diff --git a/framework/db/Command.php b/framework/db/Command.php index 67b58a1..d1058ac 100644 --- a/framework/db/Command.php +++ b/framework/db/Command.php @@ -388,9 +388,9 @@ class Command extends Component $result = $this->queryInternal('fetchColumn', 0); if (is_resource($result) && get_resource_type($result) === 'stream') { return stream_get_contents($result); - } else { - return $result; } + + return $result; } /** @@ -985,9 +985,9 @@ class Command extends Component } if (!$this->db->enableProfiling) { return [false, isset($rawSql) ? $rawSql : null]; - } else { - return [true, isset($rawSql) ? $rawSql : $this->getRawSql()]; } + + return [true, isset($rawSql) ? $rawSql : $this->getRawSql()]; } /** diff --git a/framework/db/Connection.php b/framework/db/Connection.php index 57800b1..93c5c63 100644 --- a/framework/db/Connection.php +++ b/framework/db/Connection.php @@ -564,9 +564,9 @@ class Connection extends Component if ($db !== null) { $this->pdo = $db->pdo; return; - } else { - throw new InvalidConfigException('None of the master DB servers is available.'); } + + throw new InvalidConfigException('None of the master DB servers is available.'); } if (empty($this->dsn)) { @@ -768,17 +768,17 @@ class Connection extends Component { if ($this->_schema !== null) { return $this->_schema; - } else { - $driver = $this->getDriverName(); - if (isset($this->schemaMap[$driver])) { - $config = !is_array($this->schemaMap[$driver]) ? ['class' => $this->schemaMap[$driver]] : $this->schemaMap[$driver]; - $config['db'] = $this; + } - return $this->_schema = Yii::createObject($config); - } else { - throw new NotSupportedException("Connection does not support reading schema information for '$driver' DBMS."); - } + $driver = $this->getDriverName(); + if (isset($this->schemaMap[$driver])) { + $config = !is_array($this->schemaMap[$driver]) ? ['class' => $this->schemaMap[$driver]] : $this->schemaMap[$driver]; + $config['db'] = $this; + + return $this->_schema = Yii::createObject($config); } + + throw new NotSupportedException("Connection does not support reading schema information for '$driver' DBMS."); } /** @@ -866,9 +866,9 @@ class Connection extends Component function ($matches) { if (isset($matches[3])) { return $this->quoteColumnName($matches[3]); - } else { - return str_replace('%', $this->tablePrefix, $this->quoteTableName($matches[2])); } + + return str_replace('%', $this->tablePrefix, $this->quoteTableName($matches[2])); }, $sql ); @@ -913,9 +913,9 @@ class Connection extends Component $db = $this->getSlave(false); if ($db === null) { return $fallbackToMaster ? $this->getMasterPdo() : null; - } else { - return $db->pdo; } + + return $db->pdo; } /** diff --git a/framework/db/Query.php b/framework/db/Query.php index 95c0919..cd19292 100644 --- a/framework/db/Query.php +++ b/framework/db/Query.php @@ -431,12 +431,13 @@ class Query extends Component implements QueryInterface $this->offset = $offset; return $command->queryScalar(); - } else { - return (new self())->select([$selectExpression]) - ->from(['c' => $this]) - ->createCommand($db) - ->queryScalar(); } + + return (new self()) + ->select([$selectExpression]) + ->from(['c' => $this]) + ->createCommand($db) + ->queryScalar(); } /** diff --git a/framework/db/QueryBuilder.php b/framework/db/QueryBuilder.php index 77a72bf..20b81f4 100644 --- a/framework/db/QueryBuilder.php +++ b/framework/db/QueryBuilder.php @@ -1135,9 +1135,9 @@ class QueryBuilder extends \yii\base\Object if (!is_array($columns)) { if (strpos($columns, '(') !== false) { return $columns; - } else { - $columns = preg_split('/\s*,\s*/', $columns, -1, PREG_SPLIT_NO_EMPTY); } + + $columns = preg_split('/\s*,\s*/', $columns, -1, PREG_SPLIT_NO_EMPTY); } foreach ($columns as $i => $column) { if ($column instanceof Expression) { @@ -1179,9 +1179,10 @@ class QueryBuilder extends \yii\base\Object } array_shift($condition); return $this->$method($operator, $condition, $params); - } else { // hash format: 'column1' => 'value1', 'column2' => 'value2', ... - return $this->buildHashCondition($condition, $params); } + + // hash format: 'column1' => 'value1', 'column2' => 'value2', ... + return $this->buildHashCondition($condition, $params); } /** @@ -1244,9 +1245,9 @@ class QueryBuilder extends \yii\base\Object } if (!empty($parts)) { return '(' . implode(") $operator (", $parts) . ')'; - } else { - return ''; } + + return ''; } /** @@ -1384,10 +1385,10 @@ class QueryBuilder extends \yii\base\Object if (count($sqlValues) > 1) { return "$column $operator (" . implode(', ', $sqlValues) . ')'; - } else { - $operator = $operator === 'IN' ? '=' : '<>'; - return $column . $operator . reset($sqlValues); } + + $operator = $operator === 'IN' ? '=' : '<>'; + return $column . $operator . reset($sqlValues); } /** @@ -1409,12 +1410,13 @@ class QueryBuilder extends \yii\base\Object } } return '(' . implode(', ', $columns) . ") $operator ($sql)"; - } else { - if (strpos($columns, '(') === false) { - $columns = $this->db->quoteColumnName($columns); - } - return "$columns $operator ($sql)"; } + + if (strpos($columns, '(') === false) { + $columns = $this->db->quoteColumnName($columns); + } + + return "$columns $operator ($sql)"; } /** @@ -1539,9 +1541,9 @@ class QueryBuilder extends \yii\base\Object if ($operands[0] instanceof Query) { list($sql, $params) = $this->build($operands[0], $params); return "$operator ($sql)"; - } else { - throw new InvalidParamException('Subquery for EXISTS operator must be a Query object.'); } + + throw new InvalidParamException('Subquery for EXISTS operator must be a Query object.'); } /** @@ -1574,11 +1576,11 @@ class QueryBuilder extends \yii\base\Object } elseif ($value instanceof Query) { list($sql, $params) = $this->build($value, $params); return "$column $operator ($sql)"; - } else { - $phName = self::PARAM_PREFIX . count($params); - $params[$phName] = $value; - return "$column $operator $phName"; } + + $phName = self::PARAM_PREFIX . count($params); + $params[$phName] = $value; + return "$column $operator $phName"; } /** diff --git a/framework/db/QueryTrait.php b/framework/db/QueryTrait.php index c5e1ecf..f62e097 100644 --- a/framework/db/QueryTrait.php +++ b/framework/db/QueryTrait.php @@ -360,18 +360,19 @@ trait QueryTrait return [$columns]; } elseif (is_array($columns)) { return $columns; - } else { - $columns = preg_split('/\s*,\s*/', trim($columns), -1, PREG_SPLIT_NO_EMPTY); - $result = []; - foreach ($columns as $column) { - if (preg_match('/^(.*?)\s+(asc|desc)$/i', $column, $matches)) { - $result[$matches[1]] = strcasecmp($matches[2], 'desc') ? SORT_ASC : SORT_DESC; - } else { - $result[$column] = SORT_ASC; - } + } + + $columns = preg_split('/\s*,\s*/', trim($columns), -1, PREG_SPLIT_NO_EMPTY); + $result = []; + foreach ($columns as $column) { + if (preg_match('/^(.*?)\s+(asc|desc)$/i', $column, $matches)) { + $result[$matches[1]] = strcasecmp($matches[2], 'desc') ? SORT_ASC : SORT_DESC; + } else { + $result[$column] = SORT_ASC; } - return $result; } + + return $result; } /** diff --git a/framework/db/Schema.php b/framework/db/Schema.php index 2fbe3c5..f312260 100644 --- a/framework/db/Schema.php +++ b/framework/db/Schema.php @@ -345,9 +345,9 @@ abstract class Schema extends Object { if ($this->db->isActive) { return $this->db->pdo->lastInsertId($sequenceName === '' ? null : $this->quoteTableName($sequenceName)); - } else { - throw new InvalidCallException('DB Connection is not active.'); } + + throw new InvalidCallException('DB Connection is not active.'); } /** @@ -417,9 +417,9 @@ abstract class Schema extends Object if ($tableSchema->columns[$name]->autoIncrement) { $result[$name] = $this->getLastInsertID($tableSchema->sequenceName); break; - } else { - $result[$name] = isset($columns[$name]) ? $columns[$name] : $tableSchema->columns[$name]->defaultValue; } + + $result[$name] = isset($columns[$name]) ? $columns[$name] : $tableSchema->columns[$name]->defaultValue; } return $result; } @@ -439,10 +439,10 @@ abstract class Schema extends Object if (($value = $this->db->getSlavePdo()->quote($str)) !== false) { return $value; - } else { - // the driver doesn't support quote (e.g. oci) - return "'" . addcslashes(str_replace("'", "''", $str), "\000\n\r\\\032") . "'"; } + + // the driver doesn't support quote (e.g. oci) + return "'" . addcslashes(str_replace("'", "''", $str), "\000\n\r\\\032") . "'"; } /** @@ -533,9 +533,9 @@ abstract class Schema extends Object $name = preg_replace('/\\{\\{(.*?)\\}\\}/', '\1', $name); return str_replace('%', $this->db->tablePrefix, $name); - } else { - return $name; } + + return $name; } /** @@ -560,12 +560,12 @@ abstract class Schema extends Object return PHP_INT_SIZE === 8 && !$column->unsigned ? 'integer' : 'string'; } elseif ($column->type === 'integer') { return PHP_INT_SIZE === 4 && $column->unsigned ? 'string' : 'integer'; - } else { - return $typeMap[$column->type]; } - } else { - return 'string'; + + return $typeMap[$column->type]; } + + return 'string'; } /** diff --git a/framework/db/cubrid/QueryBuilder.php b/framework/db/cubrid/QueryBuilder.php index d5333d7..97359b1 100644 --- a/framework/db/cubrid/QueryBuilder.php +++ b/framework/db/cubrid/QueryBuilder.php @@ -84,9 +84,9 @@ class QueryBuilder extends \yii\db\QueryBuilder return 'ALTER TABLE ' . $this->db->schema->quoteTableName($tableName) . " AUTO_INCREMENT=$value;"; } elseif ($table === null) { throw new InvalidParamException("Table not found: $tableName"); - } else { - throw new InvalidParamException("There is not sequence associated with table '$tableName'."); } + + throw new InvalidParamException("There is not sequence associated with table '$tableName'."); } /** diff --git a/framework/db/mssql/QueryBuilder.php b/framework/db/mssql/QueryBuilder.php index 944d391..82042ec 100644 --- a/framework/db/mssql/QueryBuilder.php +++ b/framework/db/mssql/QueryBuilder.php @@ -69,9 +69,9 @@ class QueryBuilder extends \yii\db\QueryBuilder if ($this->isOldMssql()) { return $this->oldBuildOrderByAndLimit($sql, $orderBy, $limit, $offset); - } else { - return $this->newBuildOrderByAndLimit($sql, $orderBy, $limit, $offset); } + + return $this->newBuildOrderByAndLimit($sql, $orderBy, $limit, $offset); } /** @@ -220,9 +220,9 @@ class QueryBuilder extends \yii\db\QueryBuilder return "DBCC CHECKIDENT ('{$tableName}', RESEED, {$value})"; } elseif ($table === null) { throw new InvalidParamException("Table not found: $tableName"); - } else { - throw new InvalidParamException("There is not sequence associated with table '$tableName'."); } + + throw new InvalidParamException("There is not sequence associated with table '$tableName'."); } /** diff --git a/framework/db/mysql/QueryBuilder.php b/framework/db/mysql/QueryBuilder.php index 44c69ca..77f340a 100644 --- a/framework/db/mysql/QueryBuilder.php +++ b/framework/db/mysql/QueryBuilder.php @@ -171,9 +171,9 @@ class QueryBuilder extends \yii\db\QueryBuilder return "ALTER TABLE $tableName AUTO_INCREMENT=$value"; } elseif ($table === null) { throw new InvalidParamException("Table not found: $tableName"); - } else { - throw new InvalidParamException("There is no sequence associated with table '$tableName'."); } + + throw new InvalidParamException("There is no sequence associated with table '$tableName'."); } /** diff --git a/framework/db/pgsql/QueryBuilder.php b/framework/db/pgsql/QueryBuilder.php index 54fcfb7..b79533c 100644 --- a/framework/db/pgsql/QueryBuilder.php +++ b/framework/db/pgsql/QueryBuilder.php @@ -173,9 +173,9 @@ class QueryBuilder extends \yii\db\QueryBuilder return "SELECT SETVAL('$sequence',$value,false)"; } elseif ($table === null) { throw new InvalidParamException("Table not found: $tableName"); - } else { - throw new InvalidParamException("There is not sequence associated with table '$tableName'."); } + + throw new InvalidParamException("There is not sequence associated with table '$tableName'."); } /** diff --git a/framework/db/sqlite/QueryBuilder.php b/framework/db/sqlite/QueryBuilder.php index bd96614..c9f9fa0 100644 --- a/framework/db/sqlite/QueryBuilder.php +++ b/framework/db/sqlite/QueryBuilder.php @@ -150,9 +150,9 @@ class QueryBuilder extends \yii\db\QueryBuilder return "UPDATE sqlite_sequence SET seq='$value' WHERE name='{$table->name}'"; } elseif ($table === null) { throw new InvalidParamException("Table not found: $tableName"); - } else { - throw new InvalidParamException("There is not sequence associated with table '$tableName'.'"); } + + throw new InvalidParamException("There is not sequence associated with table '$tableName'.'"); } /** diff --git a/framework/di/Container.php b/framework/di/Container.php index 2346fd5..cdfa867 100644 --- a/framework/di/Container.php +++ b/framework/di/Container.php @@ -334,9 +334,9 @@ class Container extends Component } } return $definition; - } else { - throw new InvalidConfigException("Unsupported definition type for \"$class\": " . gettype($definition)); } + + throw new InvalidConfigException("Unsupported definition type for \"$class\": " . gettype($definition)); } /** @@ -379,13 +379,14 @@ class Container extends Component // set $config as the last parameter (existing one will be overwritten) $dependencies[count($dependencies) - 1] = $config; return $reflection->newInstanceArgs($dependencies); - } else { - $object = $reflection->newInstanceArgs($dependencies); - foreach ($config as $name => $value) { - $object->$name = $value; - } - return $object; } + + $object = $reflection->newInstanceArgs($dependencies); + foreach ($config as $name => $value) { + $object->$name = $value; + } + + return $object; } /** @@ -400,13 +401,14 @@ class Container extends Component return $params; } elseif (empty($params)) { return $this->_params[$class]; - } else { - $ps = $this->_params[$class]; - foreach ($params as $index => $value) { - $ps[$index] = $value; - } - return $ps; } + + $ps = $this->_params[$class]; + foreach ($params as $index => $value) { + $ps[$index] = $value; + } + + return $ps; } /** @@ -494,9 +496,9 @@ class Container extends Component { if (is_callable($callback)) { return call_user_func_array($callback, $this->resolveCallableDependencies($callback, $params)); - } else { - return call_user_func_array($callback, $params); } + + return call_user_func_array($callback, $params); } /** diff --git a/framework/di/Instance.php b/framework/di/Instance.php index 6b0823b..dfc0ee9 100644 --- a/framework/di/Instance.php +++ b/framework/di/Instance.php @@ -119,9 +119,9 @@ class Instance $component = $container->get($class, [], $reference); if ($type === null || $component instanceof $type) { return $component; - } else { - throw new InvalidConfigException('Invalid data type: ' . $class . '. ' . $type . ' is expected.'); } + + throw new InvalidConfigException('Invalid data type: ' . $class . '. ' . $type . ' is expected.'); } elseif (empty($reference)) { throw new InvalidConfigException('The required component is not specified.'); } @@ -140,9 +140,9 @@ class Instance } if ($type === null || $component instanceof $type) { return $component; - } else { - throw new InvalidConfigException('"' . $reference->id . '" refers to a ' . get_class($component) . " component. $type is expected."); } + + throw new InvalidConfigException('"' . $reference->id . '" refers to a ' . get_class($component) . " component. $type is expected."); } $valueType = is_object($reference) ? get_class($reference) : gettype($reference); @@ -162,9 +162,9 @@ class Instance } if (Yii::$app && Yii::$app->has($this->id)) { return Yii::$app->get($this->id); - } else { - return Yii::$container->get($this->id); } + + return Yii::$container->get($this->id); } /** diff --git a/framework/di/ServiceLocator.php b/framework/di/ServiceLocator.php index 6fd064a..94a6a40 100644 --- a/framework/di/ServiceLocator.php +++ b/framework/di/ServiceLocator.php @@ -71,9 +71,9 @@ class ServiceLocator extends Component { if ($this->has($name)) { return $this->get($name); - } else { - return parent::__get($name); } + + return parent::__get($name); } /** @@ -86,9 +86,9 @@ class ServiceLocator extends Component { if ($this->has($name)) { return true; - } else { - return parent::__isset($name); } + + return parent::__isset($name); } /** @@ -131,14 +131,14 @@ class ServiceLocator extends Component $definition = $this->_definitions[$id]; if (is_object($definition) && !$definition instanceof Closure) { return $this->_components[$id] = $definition; - } else { - return $this->_components[$id] = Yii::createObject($definition); } + + return $this->_components[$id] = Yii::createObject($definition); } elseif ($throwException) { throw new InvalidConfigException("Unknown component ID: $id"); - } else { - return null; } + + return null; } /** diff --git a/framework/filters/ContentNegotiator.php b/framework/filters/ContentNegotiator.php index 987ad55..622a692 100644 --- a/framework/filters/ContentNegotiator.php +++ b/framework/filters/ContentNegotiator.php @@ -176,9 +176,9 @@ class ContentNegotiator extends ActionFilter implements BootstrapInterface $response->acceptMimeType = null; $response->acceptParams = []; return; - } else { - throw new UnsupportedMediaTypeHttpException('The requested response format is not supported: ' . $format); } + + throw new UnsupportedMediaTypeHttpException('The requested response format is not supported: ' . $format); } $types = $request->getAcceptableContentTypes(); diff --git a/framework/filters/HttpCache.php b/framework/filters/HttpCache.php index 00f384a..f7b3f81 100644 --- a/framework/filters/HttpCache.php +++ b/framework/filters/HttpCache.php @@ -171,9 +171,9 @@ class HttpCache extends ActionFilter return $etag !== null && in_array($etag, Yii::$app->request->getETags(), true); } elseif (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { return $lastModified !== null && @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $lastModified; - } else { - return false; } + + return false; } /** diff --git a/framework/filters/PageCache.php b/framework/filters/PageCache.php index cff555f..91b4358 100644 --- a/framework/filters/PageCache.php +++ b/framework/filters/PageCache.php @@ -171,11 +171,11 @@ class PageCache extends ActionFilter $response->on(Response::EVENT_AFTER_SEND, [$this, 'cacheResponse']); Yii::trace('Valid page content is not found in the cache.', __METHOD__); return true; - } else { - $this->restoreResponse($response, $data); - Yii::trace('Valid page content is found in the cache.', __METHOD__); - return false; } + + $this->restoreResponse($response, $data); + Yii::trace('Valid page content is found in the cache.', __METHOD__); + return false; } /** diff --git a/framework/filters/RateLimiter.php b/framework/filters/RateLimiter.php index 8e6f4fa..cb2f1c4 100644 --- a/framework/filters/RateLimiter.php +++ b/framework/filters/RateLimiter.php @@ -120,10 +120,10 @@ class RateLimiter extends ActionFilter $user->saveAllowance($request, $action, 0, $current); $this->addRateLimitHeaders($response, $limit, 0, $window); throw new TooManyRequestsHttpException($this->errorMessage); - } else { - $user->saveAllowance($request, $action, $allowance - 1, $current); - $this->addRateLimitHeaders($response, $limit, $allowance - 1, (int) (($limit - $allowance) * $window / $limit)); } + + $user->saveAllowance($request, $action, $allowance - 1, $current); + $this->addRateLimitHeaders($response, $limit, $allowance - 1, (int) (($limit - $allowance) * $window / $limit)); } /** diff --git a/framework/filters/auth/AuthMethod.php b/framework/filters/auth/AuthMethod.php index fe8f25c..043c648 100644 --- a/framework/filters/auth/AuthMethod.php +++ b/framework/filters/auth/AuthMethod.php @@ -69,11 +69,12 @@ abstract class AuthMethod extends ActionFilter implements AuthInterface if ($identity !== null || $this->isOptional($action)) { return true; - } else { - $this->challenge($response); - $this->handleFailure($response); - return false; } + + $this->challenge($response); + $this->handleFailure($response); + + return false; } /** diff --git a/framework/grid/ActionColumn.php b/framework/grid/ActionColumn.php index c65cedc..b2d1286 100644 --- a/framework/grid/ActionColumn.php +++ b/framework/grid/ActionColumn.php @@ -198,12 +198,12 @@ class ActionColumn extends Column { if (is_callable($this->urlCreator)) { return call_user_func($this->urlCreator, $action, $model, $key, $index, $this); - } else { - $params = is_array($key) ? $key : ['id' => (string) $key]; - $params[0] = $this->controller ? $this->controller . '/' . $action : $action; - - return Url::toRoute($params); } + + $params = is_array($key) ? $key : ['id' => (string) $key]; + $params[0] = $this->controller ? $this->controller . '/' . $action : $action; + + return Url::toRoute($params); } /** @@ -225,9 +225,9 @@ class ActionColumn extends Column if ($isVisible && isset($this->buttons[$name])) { $url = $this->createUrl($name, $model, $key, $index); return call_user_func($this->buttons[$name], $url, $model, $key); - } else { - return ''; } + + return ''; }, $this->template); } } diff --git a/framework/grid/CheckboxColumn.php b/framework/grid/CheckboxColumn.php index b1afdc6..b30e51e 100644 --- a/framework/grid/CheckboxColumn.php +++ b/framework/grid/CheckboxColumn.php @@ -103,9 +103,9 @@ class CheckboxColumn extends Column { if ($this->header !== null || !$this->multiple) { return parent::renderHeaderCellContent(); - } else { - return Html::checkbox($this->getHeaderCheckBoxName(), false, ['class' => 'select-on-check-all']); } + + return Html::checkbox($this->getHeaderCheckBoxName(), false, ['class' => 'select-on-check-all']); } /** diff --git a/framework/grid/Column.php b/framework/grid/Column.php index 96d83fd..69d94ce 100644 --- a/framework/grid/Column.php +++ b/framework/grid/Column.php @@ -162,9 +162,9 @@ class Column extends Object { if ($this->content !== null) { return call_user_func($this->content, $model, $key, $index, $this); - } else { - return $this->grid->emptyCell; } + + return $this->grid->emptyCell; } /** diff --git a/framework/grid/DataColumn.php b/framework/grid/DataColumn.php index b3d751d..f5055fe 100644 --- a/framework/grid/DataColumn.php +++ b/framework/grid/DataColumn.php @@ -130,9 +130,9 @@ class DataColumn extends Column if ($this->attribute !== null && $this->enableSorting && ($sort = $this->grid->dataProvider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { return $sort->link($this->attribute, array_merge($this->sortLinkOptions, ['label' => $label])); - } else { - return $label; } + + return $label; } /** @@ -197,12 +197,12 @@ class DataColumn extends Column $this->grid->formatter->booleanFormat[0], $this->grid->formatter->booleanFormat[1], ], $options) . $error; - } else { - return Html::activeTextInput($model, $this->attribute, $this->filterInputOptions) . $error; } - } else { - return parent::renderFilterCellContent(); + + return Html::activeTextInput($model, $this->attribute, $this->filterInputOptions) . $error; } + + return parent::renderFilterCellContent(); } /** @@ -217,9 +217,9 @@ class DataColumn extends Column if ($this->value !== null) { if (is_string($this->value)) { return ArrayHelper::getValue($model, $this->value); - } else { - return call_user_func($this->value, $model, $key, $index, $this); } + + return call_user_func($this->value, $model, $key, $index, $this); } elseif ($this->attribute !== null) { return ArrayHelper::getValue($model, $this->attribute); } @@ -233,8 +233,8 @@ class DataColumn extends Column { if ($this->content === null) { return $this->grid->formatter->format($this->getDataCellValue($model, $key, $index), $this->format); - } else { - return parent::renderDataCellContent($model, $key, $index); } + + return parent::renderDataCellContent($model, $key, $index); } } diff --git a/framework/grid/GridView.php b/framework/grid/GridView.php index 3e9d47a..62edded 100644 --- a/framework/grid/GridView.php +++ b/framework/grid/GridView.php @@ -299,9 +299,9 @@ class GridView extends BaseListView { if ($this->filterModel instanceof Model && $this->filterModel->hasErrors()) { return Html::errorSummary($this->filterModel, $this->filterErrorSummaryOptions); - } else { - return ''; } + + return ''; } /** @@ -365,9 +365,9 @@ class GridView extends BaseListView { if (!empty($this->caption)) { return Html::tag('caption', $this->caption, $this->captionOptions); - } else { - return false; } + + return false; } /** @@ -391,9 +391,9 @@ class GridView extends BaseListView } return Html::tag('colgroup', implode("\n", $cols)); - } else { - return false; } + + return false; } /** @@ -450,9 +450,9 @@ class GridView extends BaseListView } return Html::tag('tr', implode('', $cells), $this->filterRowOptions); - } else { - return ''; } + + return ''; } /** @@ -487,9 +487,9 @@ class GridView extends BaseListView $colspan = count($this->columns); return "\n" . $this->renderEmpty() . "\n"; - } else { - return "\n" . implode("\n", $rows) . "\n"; } + + return "\n" . implode("\n", $rows) . "\n"; } /** diff --git a/framework/grid/SerialColumn.php b/framework/grid/SerialColumn.php index d24a9b3..9505b26 100644 --- a/framework/grid/SerialColumn.php +++ b/framework/grid/SerialColumn.php @@ -43,8 +43,8 @@ class SerialColumn extends Column $pagination = $this->grid->dataProvider->getPagination(); if ($pagination !== false) { return $pagination->getOffset() + $index + 1; - } else { - return $index + 1; } + + return $index + 1; } } diff --git a/framework/helpers/BaseArrayHelper.php b/framework/helpers/BaseArrayHelper.php index 54ee6c4..13c5390 100644 --- a/framework/helpers/BaseArrayHelper.php +++ b/framework/helpers/BaseArrayHelper.php @@ -94,9 +94,9 @@ class BaseArrayHelper } return $recursive ? static::toArray($result, $properties) : $result; - } else { - return [$object]; } + + return [$object]; } /** @@ -209,9 +209,9 @@ class BaseArrayHelper return $array->$key; } elseif (is_array($array)) { return (isset($array[$key]) || array_key_exists($key, $array)) ? $array[$key] : $default; - } else { - return $default; } + + return $default; } /** @@ -526,15 +526,15 @@ class BaseArrayHelper // Function `isset` checks key faster but skips `null`, `array_key_exists` handles this case // http://php.net/manual/en/function.array-key-exists.php#107786 return isset($array[$key]) || array_key_exists($key, $array); - } else { - foreach (array_keys($array) as $k) { - if (strcasecmp($key, $k) === 0) { - return true; - } - } + } - return false; + foreach (array_keys($array) as $k) { + if (strcasecmp($key, $k) === 0) { + return true; + } } + + return false; } /** @@ -679,14 +679,15 @@ class BaseArrayHelper } } return true; - } else { - foreach ($array as $key => $value) { - if (is_string($key)) { - return true; - } + } + + foreach ($array as $key => $value) { + if (is_string($key)) { + return true; } - return false; } + + return false; } /** @@ -714,14 +715,15 @@ class BaseArrayHelper if ($consecutive) { return array_keys($array) === range(0, count($array) - 1); - } else { - foreach ($array as $key => $value) { - if (!is_int($key)) { - return false; - } + } + + foreach ($array as $key => $value) { + if (!is_int($key)) { + return false; } - return true; } + + return true; } /** @@ -789,10 +791,11 @@ class BaseArrayHelper return false; } } + return true; - } else { - throw new InvalidParamException('Argument $needles must be an array or implement Traversable'); } + + throw new InvalidParamException('Argument $needles must be an array or implement Traversable'); } /** diff --git a/framework/helpers/BaseFileHelper.php b/framework/helpers/BaseFileHelper.php index bdef6d6..3e0c903 100644 --- a/framework/helpers/BaseFileHelper.php +++ b/framework/helpers/BaseFileHelper.php @@ -104,15 +104,15 @@ class BaseFileHelper $desiredFile = dirname($file) . DIRECTORY_SEPARATOR . $language . DIRECTORY_SEPARATOR . basename($file); if (is_file($desiredFile)) { return $desiredFile; - } else { - $language = substr($language, 0, 2); - if ($language === $sourceLanguage) { - return $file; - } - $desiredFile = dirname($file) . DIRECTORY_SEPARATOR . $language . DIRECTORY_SEPARATOR . basename($file); + } - return is_file($desiredFile) ? $desiredFile : $file; + $language = substr($language, 0, 2); + if ($language === $sourceLanguage) { + return $file; } + $desiredFile = dirname($file) . DIRECTORY_SEPARATOR . $language . DIRECTORY_SEPARATOR . basename($file); + + return is_file($desiredFile) ? $desiredFile : $file; } /** @@ -138,9 +138,9 @@ class BaseFileHelper if (!extension_loaded('fileinfo')) { if ($checkExtension) { return static::getMimeTypeByExtension($file, $magicFile); - } else { - throw new InvalidConfigException('The fileinfo PHP extension is not installed.'); } + + throw new InvalidConfigException('The fileinfo PHP extension is not installed.'); } $info = finfo_open(FILEINFO_MIME_TYPE, $magicFile); diff --git a/framework/helpers/BaseHtml.php b/framework/helpers/BaseHtml.php index c5914b9..14621b9 100644 --- a/framework/helpers/BaseHtml.php +++ b/framework/helpers/BaseHtml.php @@ -243,9 +243,9 @@ class BaseHtml } elseif (isset($options['noscript']) && $options['noscript'] === true) { unset($options['noscript']); return ''; - } else { - return static::tag('link', '', $options); } + + return static::tag('link', '', $options); } /** @@ -270,9 +270,9 @@ class BaseHtml $condition = $options['condition']; unset($options['condition']); return self::wrapIntoCondition(static::tag('script', '', $options), $condition); - } else { - return static::tag('script', '', $options); } + + return static::tag('script', '', $options); } /** @@ -300,9 +300,9 @@ class BaseHtml if ($request instanceof Request && $request->enableCsrfValidation) { return static::tag('meta', '', ['name' => 'csrf-param', 'content' => $request->csrfParam]) . "\n " . static::tag('meta', '', ['name' => 'csrf-token', 'content' => $request->getCsrfToken()]) . "\n"; - } else { - return ''; } + + return ''; } /** @@ -764,9 +764,9 @@ class BaseHtml unset($options['label'], $options['labelOptions']); $content = static::label(static::input($type, $name, $value, $options) . ' ' . $label, null, $labelOptions); return $hidden . $content; - } else { - return $hidden . static::input($type, $name, $value, $options); } + + return $hidden . static::input($type, $name, $value, $options); } /** @@ -1556,9 +1556,9 @@ class BaseHtml { if (empty($options['multiple'])) { return static::activeListInput('dropDownList', $model, $attribute, $items, $options); - } else { - return static::activeListBox($model, $attribute, $items, $options); } + + return static::activeListBox($model, $attribute, $items, $options); } /** @@ -2080,9 +2080,9 @@ class BaseHtml { if (preg_match(static::$attributeRegex, $attribute, $matches)) { return $matches[2]; - } else { - throw new InvalidParamException('Attribute name must contain word characters only.'); } + + throw new InvalidParamException('Attribute name must contain word characters only.'); } /** @@ -2161,9 +2161,9 @@ class BaseHtml return $attribute . $suffix; } elseif ($formName !== '') { return $formName . $prefix . "[$attribute]" . $suffix; - } else { - throw new InvalidParamException(get_class($model) . '::formName() cannot be empty for tabular inputs.'); } + + throw new InvalidParamException(get_class($model) . '::formName() cannot be empty for tabular inputs.'); } /** diff --git a/framework/helpers/BaseInflector.php b/framework/helpers/BaseInflector.php index 38f9e06..ae6e06b 100644 --- a/framework/helpers/BaseInflector.php +++ b/framework/helpers/BaseInflector.php @@ -385,9 +385,9 @@ class BaseInflector $regex = $strict ? '/[A-Z]/' : '/(?charset) > $length) { return rtrim(mb_substr($string, 0, $length, $encoding ?: Yii::$app->charset)) . $suffix; - } else { - return $string; } + + return $string; } /** @@ -134,9 +134,9 @@ class BaseStringHelper $words = preg_split('/(\s+)/u', trim($string), null, PREG_SPLIT_DELIM_CAPTURE); if (count($words) / 2 > $count) { return implode('', array_slice($words, 0, ($count * 2) - 1)) . $suffix; - } else { - return $string; } + + return $string; } /** @@ -215,9 +215,9 @@ class BaseStringHelper } if ($caseSensitive) { return strncmp($string, $with, $bytes) === 0; - } else { - return mb_strtolower(mb_substr($string, 0, $bytes, '8bit'), Yii::$app->charset) === mb_strtolower($with, Yii::$app->charset); } + + return mb_strtolower(mb_substr($string, 0, $bytes, '8bit'), Yii::$app->charset) === mb_strtolower($with, Yii::$app->charset); } /** @@ -240,9 +240,9 @@ class BaseStringHelper return false; } return substr_compare($string, $with, -$bytes, $bytes) === 0; - } else { - return mb_strtolower(mb_substr($string, -$bytes, mb_strlen($string, '8bit'), '8bit'), Yii::$app->charset) === mb_strtolower($with, Yii::$app->charset); } + + return mb_strtolower(mb_substr($string, -$bytes, mb_strlen($string, '8bit'), '8bit'), Yii::$app->charset) === mb_strtolower($with, Yii::$app->charset); } /** diff --git a/framework/helpers/BaseUrl.php b/framework/helpers/BaseUrl.php index 740c19c..c2c14c0 100644 --- a/framework/helpers/BaseUrl.php +++ b/framework/helpers/BaseUrl.php @@ -100,9 +100,9 @@ class BaseUrl if ($scheme !== false) { return static::getUrlManager()->createAbsoluteUrl($route, is_string($scheme) ? $scheme : null); - } else { - return static::getUrlManager()->createUrl($route); } + + return static::getUrlManager()->createUrl($route); } /** @@ -140,10 +140,10 @@ class BaseUrl if (strpos($route, '/') === false) { // empty or an action ID return $route === '' ? Yii::$app->controller->getRoute() : Yii::$app->controller->getUniqueId() . '/' . $route; - } else { - // relative to module - return ltrim(Yii::$app->controller->module->getUniqueId() . '/' . $route, '/'); } + + // relative to module + return ltrim(Yii::$app->controller->module->getUniqueId() . '/' . $route, '/'); } /** @@ -320,9 +320,9 @@ class BaseUrl { if ($name === null) { return Yii::$app->getUser()->getReturnUrl(); - } else { - return Yii::$app->getSession()->get($name); } + + return Yii::$app->getSession()->get($name); } /** diff --git a/framework/i18n/DbMessageSource.php b/framework/i18n/DbMessageSource.php index 5bfaece..e2048c2 100644 --- a/framework/i18n/DbMessageSource.php +++ b/framework/i18n/DbMessageSource.php @@ -127,9 +127,9 @@ class DbMessageSource extends MessageSource } return $messages; - } else { - return $this->loadMessagesFromDb($category, $language); } + + return $this->loadMessagesFromDb($category, $language); } /** diff --git a/framework/i18n/Formatter.php b/framework/i18n/Formatter.php index fc407b2..3842af8 100644 --- a/framework/i18n/Formatter.php +++ b/framework/i18n/Formatter.php @@ -328,9 +328,9 @@ class Formatter extends Component $method = 'as' . $format; if ($this->hasMethod($method)) { return call_user_func_array([$this, $method], $params); - } else { - throw new InvalidParamException("Unknown format type: $format"); } + + throw new InvalidParamException("Unknown format type: $format"); } @@ -649,21 +649,22 @@ class Formatter extends Component $timestamp = new DateTime($timestamp->format(DateTime::ISO8601), $timestamp->getTimezone()); } return $formatter->format($timestamp); + } + + if (strncmp($format, 'php:', 4) === 0) { + $format = substr($format, 4); } else { - if (strncmp($format, 'php:', 4) === 0) { - $format = substr($format, 4); + $format = FormatConverter::convertDateIcuToPhp($format, $type, $this->locale); + } + if ($timeZone != null) { + if ($timestamp instanceof \DateTimeImmutable) { + $timestamp = $timestamp->setTimezone(new DateTimeZone($timeZone)); } else { - $format = FormatConverter::convertDateIcuToPhp($format, $type, $this->locale); - } - if ($timeZone != null) { - if ($timestamp instanceof \DateTimeImmutable) { - $timestamp = $timestamp->setTimezone(new DateTimeZone($timeZone)); - } else { - $timestamp->setTimezone(new DateTimeZone($timeZone)); - } + $timestamp->setTimezone(new DateTimeZone($timeZone)); } - return $timestamp->format($format); } + + return $timestamp->format($format); } /** @@ -718,9 +719,9 @@ class Formatter extends Component !($info['hour'] === false && $info['minute'] === false && $info['second'] === false), !($info['year'] === false && $info['month'] === false && $info['day'] === false), ]; - } else { - return new DateTime($value, new DateTimeZone($this->defaultTimeZone)); } + + return new DateTime($value, new DateTimeZone($this->defaultTimeZone)); } catch (\Exception $e) { throw new InvalidParamException("'$value' is not a valid date time value: " . $e->getMessage() . "\n" . print_r(DateTime::getLastErrors(), true), $e->getCode(), $e); @@ -826,28 +827,30 @@ class Formatter extends Component if ($interval->s == 0) { return Yii::t('yii', 'just now', [], $this->locale); } + return Yii::t('yii', 'in {delta, plural, =1{a second} other{# seconds}}', ['delta' => $interval->s], $this->locale); - } else { - if ($interval->y >= 1) { - return Yii::t('yii', '{delta, plural, =1{a year} other{# years}} ago', ['delta' => $interval->y], $this->locale); - } - if ($interval->m >= 1) { - return Yii::t('yii', '{delta, plural, =1{a month} other{# months}} ago', ['delta' => $interval->m], $this->locale); - } - if ($interval->d >= 1) { - return Yii::t('yii', '{delta, plural, =1{a day} other{# days}} ago', ['delta' => $interval->d], $this->locale); - } - if ($interval->h >= 1) { - return Yii::t('yii', '{delta, plural, =1{an hour} other{# hours}} ago', ['delta' => $interval->h], $this->locale); - } - if ($interval->i >= 1) { - return Yii::t('yii', '{delta, plural, =1{a minute} other{# minutes}} ago', ['delta' => $interval->i], $this->locale); - } - if ($interval->s == 0) { - return Yii::t('yii', 'just now', [], $this->locale); - } - return Yii::t('yii', '{delta, plural, =1{a second} other{# seconds}} ago', ['delta' => $interval->s], $this->locale); } + + if ($interval->y >= 1) { + return Yii::t('yii', '{delta, plural, =1{a year} other{# years}} ago', ['delta' => $interval->y], $this->locale); + } + if ($interval->m >= 1) { + return Yii::t('yii', '{delta, plural, =1{a month} other{# months}} ago', ['delta' => $interval->m], $this->locale); + } + if ($interval->d >= 1) { + return Yii::t('yii', '{delta, plural, =1{a day} other{# days}} ago', ['delta' => $interval->d], $this->locale); + } + if ($interval->h >= 1) { + return Yii::t('yii', '{delta, plural, =1{an hour} other{# hours}} ago', ['delta' => $interval->h], $this->locale); + } + if ($interval->i >= 1) { + return Yii::t('yii', '{delta, plural, =1{a minute} other{# minutes}} ago', ['delta' => $interval->i], $this->locale); + } + if ($interval->s == 0) { + return Yii::t('yii', 'just now', [], $this->locale); + } + + return Yii::t('yii', '{delta, plural, =1{a second} other{# seconds}} ago', ['delta' => $interval->s], $this->locale); } /** @@ -941,10 +944,11 @@ class Formatter extends Component if (($result = $f->format($value, NumberFormatter::TYPE_INT64)) === false) { throw new InvalidParamException('Formatting integer value failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage()); } + return $result; - } else { - return number_format((int) $value, 0, $this->decimalSeparator, $this->thousandSeparator); } + + return number_format((int) $value, 0, $this->decimalSeparator, $this->thousandSeparator); } /** @@ -980,13 +984,15 @@ class Formatter extends Component if (($result = $f->format($value)) === false) { throw new InvalidParamException('Formatting decimal value failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage()); } + return $result; - } else { - if ($decimals === null) { - $decimals = 2; - } - return number_format($value, $decimals, $this->decimalSeparator, $this->thousandSeparator); } + + if ($decimals === null) { + $decimals = 2; + } + + return number_format($value, $decimals, $this->decimalSeparator, $this->thousandSeparator); } @@ -1019,13 +1025,14 @@ class Formatter extends Component throw new InvalidParamException('Formatting percent value failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage()); } return $result; - } else { - if ($decimals === null) { - $decimals = 0; - } - $value *= 100; - return number_format($value, $decimals, $this->decimalSeparator, $this->thousandSeparator) . '%'; } + + if ($decimals === null) { + $decimals = 0; + } + + $value *= 100; + return number_format($value, $decimals, $this->decimalSeparator, $this->thousandSeparator) . '%'; } /** @@ -1056,14 +1063,15 @@ class Formatter extends Component if (($result = $f->format($value)) === false) { throw new InvalidParamException('Formatting scientific number value failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage()); } + return $result; - } else { - if ($decimals !== null) { - return sprintf("%.{$decimals}E", $value); - } else { - return sprintf('%.E', $value); - } } + + if ($decimals !== null) { + return sprintf("%.{$decimals}E", $value); + } + + return sprintf('%.E', $value); } /** @@ -1104,16 +1112,18 @@ class Formatter extends Component if ($result === false) { throw new InvalidParamException('Formatting currency value failed: ' . $formatter->getErrorCode() . ' ' . $formatter->getErrorMessage()); } + return $result; - } else { - if ($currency === null) { - if ($this->currencyCode === null) { - throw new InvalidConfigException('The default currency code for the formatter is not defined and the php intl extension is not installed which could take the default currency from the locale.'); - } - $currency = $this->currencyCode; + } + + if ($currency === null) { + if ($this->currencyCode === null) { + throw new InvalidConfigException('The default currency code for the formatter is not defined and the php intl extension is not installed which could take the default currency from the locale.'); } - return $currency . ' ' . $this->asDecimal($value, 2, $options, $textOptions); + $currency = $this->currencyCode; } + + return $currency . ' ' . $this->asDecimal($value, 2, $options, $textOptions); } /** @@ -1137,10 +1147,11 @@ class Formatter extends Component if (($result = $f->format($value)) === false) { throw new InvalidParamException('Formatting number as spellout failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage()); } + return $result; - } else { - throw new InvalidConfigException('Format as Spellout is only supported when PHP intl extension is installed.'); } + + throw new InvalidConfigException('Format as Spellout is only supported when PHP intl extension is installed.'); } /** @@ -1164,10 +1175,11 @@ class Formatter extends Component if (($result = $f->format($value)) === false) { throw new InvalidParamException('Formatting number as ordinal failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage()); } + return $result; - } else { - throw new InvalidConfigException('Format as Ordinal is only supported when PHP intl extension is installed.'); } + + throw new InvalidConfigException('Format as Ordinal is only supported when PHP intl extension is installed.'); } /** diff --git a/framework/i18n/GettextMessageSource.php b/framework/i18n/GettextMessageSource.php index 60e9934..32a3bf1 100644 --- a/framework/i18n/GettextMessageSource.php +++ b/framework/i18n/GettextMessageSource.php @@ -162,8 +162,8 @@ class GettextMessageSource extends MessageSource } return $messages; - } else { - return null; } + + return null; } } diff --git a/framework/i18n/GettextMoFile.php b/framework/i18n/GettextMoFile.php index 8aaf6be..43b5afa 100644 --- a/framework/i18n/GettextMoFile.php +++ b/framework/i18n/GettextMoFile.php @@ -207,9 +207,9 @@ class GettextMoFile extends GettextFile { if ($byteCount > 0) { return fread($fileHandle, $byteCount); - } else { - return null; } + + return null; } /** diff --git a/framework/i18n/I18N.php b/framework/i18n/I18N.php index 36bc1ae..e881afe 100644 --- a/framework/i18n/I18N.php +++ b/framework/i18n/I18N.php @@ -89,9 +89,9 @@ class I18N extends Component $translation = $messageSource->translate($category, $message, $language); if ($translation === false) { return $this->format($message, $params, $messageSource->sourceLanguage); - } else { - return $this->format($translation, $params, $language); } + + return $this->format($translation, $params, $language); } /** @@ -117,9 +117,9 @@ class I18N extends Component Yii::warning("Formatting message for language '$language' failed with error: $errorMessage. The message being formatted was: $message.", __METHOD__); return $message; - } else { - return $result; } + + return $result; } $p = []; @@ -172,31 +172,31 @@ class I18N extends Component $source = $this->translations[$category]; if ($source instanceof MessageSource) { return $source; - } else { - return $this->translations[$category] = Yii::createObject($source); - } - } else { - // try wildcard matching - foreach ($this->translations as $pattern => $source) { - if (strpos($pattern, '*') > 0 && strpos($category, rtrim($pattern, '*')) === 0) { - if ($source instanceof MessageSource) { - return $source; - } else { - return $this->translations[$category] = $this->translations[$pattern] = Yii::createObject($source); - } - } } - // match '*' in the last - if (isset($this->translations['*'])) { - $source = $this->translations['*']; + + return $this->translations[$category] = Yii::createObject($source); + } + // try wildcard matching + foreach ($this->translations as $pattern => $source) { + if (strpos($pattern, '*') > 0 && strpos($category, rtrim($pattern, '*')) === 0) { if ($source instanceof MessageSource) { return $source; - } else { - return $this->translations[$category] = $this->translations['*'] = Yii::createObject($source); } + + return $this->translations[$category] = $this->translations[$pattern] = Yii::createObject($source); } } + // match '*' in the last + if (isset($this->translations['*'])) { + $source = $this->translations['*']; + if ($source instanceof MessageSource) { + return $source; + } + + return $this->translations[$category] = $this->translations['*'] = Yii::createObject($source); + } + throw new InvalidConfigException("Unable to locate message source for category '$category'."); } } diff --git a/framework/i18n/MessageFormatter.php b/framework/i18n/MessageFormatter.php index d591d0d..e964e6a 100644 --- a/framework/i18n/MessageFormatter.php +++ b/framework/i18n/MessageFormatter.php @@ -126,9 +126,9 @@ class MessageFormatter extends Component $this->_errorCode = $formatter->getErrorCode(); $this->_errorMessage = $formatter->getErrorMessage(); return false; - } else { - return $result; } + + return $result; } /** @@ -187,14 +187,14 @@ class MessageFormatter extends Component $this->_errorMessage = $formatter->getErrorMessage(); return false; - } else { - $values = []; - foreach ($result as $key => $value) { - $values[$map[$key]] = $value; - } + } - return $values; + $values = []; + foreach ($result as $key => $value) { + $values[$map[$key]] = $value; } + + return $values; } /** diff --git a/framework/i18n/MessageSource.php b/framework/i18n/MessageSource.php index 9d8ea1f..24a4a74 100644 --- a/framework/i18n/MessageSource.php +++ b/framework/i18n/MessageSource.php @@ -85,9 +85,9 @@ class MessageSource extends Component { if ($this->forceTranslation || $language !== $this->sourceLanguage) { return $this->translateMessage($category, $message, $language); - } else { - return false; } + + return false; } /** diff --git a/framework/i18n/PhpMessageSource.php b/framework/i18n/PhpMessageSource.php index e1a9eec..cbbc3ed 100644 --- a/framework/i18n/PhpMessageSource.php +++ b/framework/i18n/PhpMessageSource.php @@ -159,8 +159,8 @@ class PhpMessageSource extends MessageSource } return $messages; - } else { - return null; } + + return null; } } diff --git a/framework/mail/BaseMailer.php b/framework/mail/BaseMailer.php index 98ede5d..582d319 100644 --- a/framework/mail/BaseMailer.php +++ b/framework/mail/BaseMailer.php @@ -301,9 +301,9 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont $output = $this->getView()->render($view, $params, $this); if ($layout !== false) { return $this->getView()->render($layout, ['content' => $output, 'message' => $this->_message], $this); - } else { - return $output; } + + return $output; } /** diff --git a/framework/mutex/FileMutex.php b/framework/mutex/FileMutex.php index 973c633..d0cfe8e 100644 --- a/framework/mutex/FileMutex.php +++ b/framework/mutex/FileMutex.php @@ -117,13 +117,13 @@ class FileMutex extends Mutex { if (!isset($this->_files[$name]) || !flock($this->_files[$name], LOCK_UN)) { return false; - } else { - fclose($this->_files[$name]); - unlink($this->getLockFilePath($name)); - unset($this->_files[$name]); - - return true; } + + fclose($this->_files[$name]); + unlink($this->getLockFilePath($name)); + unset($this->_files[$name]); + + return true; } /** diff --git a/framework/mutex/Mutex.php b/framework/mutex/Mutex.php index 95a7bec..9720745 100644 --- a/framework/mutex/Mutex.php +++ b/framework/mutex/Mutex.php @@ -72,9 +72,9 @@ abstract class Mutex extends Component $this->_locks[] = $name; return true; - } else { - return false; } + + return false; } /** @@ -91,9 +91,9 @@ abstract class Mutex extends Component } return true; - } else { - return false; } + + return false; } /** diff --git a/framework/rbac/BaseManager.php b/framework/rbac/BaseManager.php index 371c0fd..999a7ca 100644 --- a/framework/rbac/BaseManager.php +++ b/framework/rbac/BaseManager.php @@ -128,9 +128,9 @@ abstract class BaseManager extends Component implements ManagerInterface return $this->addItem($object); } elseif ($object instanceof Rule) { return $this->addRule($object); - } else { - throw new InvalidParamException('Adding unsupported object type.'); } + + throw new InvalidParamException('Adding unsupported object type.'); } /** @@ -142,9 +142,9 @@ abstract class BaseManager extends Component implements ManagerInterface return $this->removeItem($object); } elseif ($object instanceof Rule) { return $this->removeRule($object); - } else { - throw new InvalidParamException('Removing unsupported object type.'); } + + throw new InvalidParamException('Removing unsupported object type.'); } /** @@ -161,9 +161,9 @@ abstract class BaseManager extends Component implements ManagerInterface return $this->updateItem($name, $object); } elseif ($object instanceof Rule) { return $this->updateRule($name, $object); - } else { - throw new InvalidParamException('Updating unsupported object type.'); } + + throw new InvalidParamException('Updating unsupported object type.'); } /** @@ -235,9 +235,9 @@ abstract class BaseManager extends Component implements ManagerInterface $rule = $this->getRule($item->ruleName); if ($rule instanceof Rule) { return $rule->execute($user, $item, $params); - } else { - throw new InvalidConfigException("Rule not found: {$item->ruleName}"); } + + throw new InvalidConfigException("Rule not found: {$item->ruleName}"); } /** diff --git a/framework/rbac/DbManager.php b/framework/rbac/DbManager.php index 08577a3..4989080 100644 --- a/framework/rbac/DbManager.php +++ b/framework/rbac/DbManager.php @@ -129,9 +129,9 @@ class DbManager extends BaseManager $this->loadFromCache(); if ($this->items !== null) { return $this->checkAccessFromCache($userId, $permissionName, $params, $assignments); - } else { - return $this->checkAccessRecursive($userId, $permissionName, $params, $assignments); } + + return $this->checkAccessRecursive($userId, $permissionName, $params, $assignments); } /** diff --git a/framework/rbac/PhpManager.php b/framework/rbac/PhpManager.php index 663c7cd..f935495 100644 --- a/framework/rbac/PhpManager.php +++ b/framework/rbac/PhpManager.php @@ -226,9 +226,9 @@ class PhpManager extends BaseManager unset($this->children[$parent->name][$child->name]); $this->saveItems(); return true; - } else { - return false; } + + return false; } /** @@ -240,9 +240,9 @@ class PhpManager extends BaseManager unset($this->children[$parent->name]); $this->saveItems(); return true; - } else { - return false; } + + return false; } /** @@ -262,15 +262,16 @@ class PhpManager extends BaseManager throw new InvalidParamException("Unknown role '{$role->name}'."); } elseif (isset($this->assignments[$userId][$role->name])) { throw new InvalidParamException("Authorization item '{$role->name}' has already been assigned to user '$userId'."); - } else { - $this->assignments[$userId][$role->name] = new Assignment([ - 'userId' => $userId, - 'roleName' => $role->name, - 'createdAt' => time(), - ]); - $this->saveAssignments(); - return $this->assignments[$userId][$role->name]; } + + $this->assignments[$userId][$role->name] = new Assignment([ + 'userId' => $userId, + 'roleName' => $role->name, + 'createdAt' => time(), + ]); + $this->saveAssignments(); + + return $this->assignments[$userId][$role->name]; } /** @@ -282,9 +283,9 @@ class PhpManager extends BaseManager unset($this->assignments[$userId][$role->name]); $this->saveAssignments(); return true; - } else { - return false; } + + return false; } /** @@ -298,9 +299,9 @@ class PhpManager extends BaseManager } $this->saveAssignments(); return true; - } else { - return false; } + + return false; } /** @@ -345,9 +346,9 @@ class PhpManager extends BaseManager $this->saveItems(); $this->saveAssignments(); return true; - } else { - return false; } + + return false; } /** @@ -630,9 +631,9 @@ class PhpManager extends BaseManager } $this->saveRules(); return true; - } else { - return false; } + + return false; } /** @@ -653,29 +654,29 @@ class PhpManager extends BaseManager if ($name !== $item->name) { if (isset($this->items[$item->name])) { throw new InvalidParamException("Unable to change the item name. The name '{$item->name}' is already used by another item."); - } else { - // Remove old item in case of renaming - unset($this->items[$name]); + } - if (isset($this->children[$name])) { - $this->children[$item->name] = $this->children[$name]; - unset($this->children[$name]); - } - foreach ($this->children as &$children) { - if (isset($children[$name])) { - $children[$item->name] = $children[$name]; - unset($children[$name]); - } + // Remove old item in case of renaming + unset($this->items[$name]); + + if (isset($this->children[$name])) { + $this->children[$item->name] = $this->children[$name]; + unset($this->children[$name]); + } + foreach ($this->children as &$children) { + if (isset($children[$name])) { + $children[$item->name] = $children[$name]; + unset($children[$name]); } - foreach ($this->assignments as &$assignments) { - if (isset($assignments[$name])) { - $assignments[$item->name] = $assignments[$name]; - $assignments[$item->name]->roleName = $item->name; - unset($assignments[$name]); - } + } + foreach ($this->assignments as &$assignments) { + if (isset($assignments[$name])) { + $assignments[$item->name] = $assignments[$name]; + $assignments[$item->name]->roleName = $item->name; + unset($assignments[$name]); } - $this->saveAssignments(); } + $this->saveAssignments(); } $this->items[$item->name] = $item; @@ -779,9 +780,9 @@ class PhpManager extends BaseManager { if (is_file($file)) { return require($file); - } else { - return []; } + + return []; } /** diff --git a/framework/rest/Action.php b/framework/rest/Action.php index dfaf0d9..08f89d4 100644 --- a/framework/rest/Action.php +++ b/framework/rest/Action.php @@ -99,8 +99,8 @@ class Action extends \yii\base\Action if (isset($model)) { return $model; - } else { - throw new NotFoundHttpException("Object not found: $id"); } + + throw new NotFoundHttpException("Object not found: $id"); } } diff --git a/framework/rest/Serializer.php b/framework/rest/Serializer.php index 33e5637..52f5828 100644 --- a/framework/rest/Serializer.php +++ b/framework/rest/Serializer.php @@ -150,9 +150,9 @@ class Serializer extends Component return $this->serializeModel($data); } elseif ($data instanceof DataProviderInterface) { return $this->serializeDataProvider($data); - } else { - return $data; } + + return $data; } /** @@ -195,16 +195,16 @@ class Serializer extends Component return null; } elseif ($this->collectionEnvelope === null) { return $models; - } else { - $result = [ - $this->collectionEnvelope => $models, - ]; - if ($pagination !== false) { - return array_merge($result, $this->serializePagination($pagination)); - } else { - return $result; - } } + + $result = [ + $this->collectionEnvelope => $models, + ]; + if ($pagination !== false) { + return array_merge($result, $this->serializePagination($pagination)); + } + + return $result; } /** @@ -254,10 +254,10 @@ class Serializer extends Component { if ($this->request->getIsHead()) { return null; - } else { - list($fields, $expand) = $this->getRequestedFields(); - return $model->toArray($fields, $expand); } + + list($fields, $expand) = $this->getRequestedFields(); + return $model->toArray($fields, $expand); } /** diff --git a/framework/test/ActiveFixture.php b/framework/test/ActiveFixture.php index 5f2937e..da06502 100644 --- a/framework/test/ActiveFixture.php +++ b/framework/test/ActiveFixture.php @@ -99,9 +99,9 @@ class ActiveFixture extends BaseActiveFixture $dataFile = dirname($class->getFileName()) . '/data/' . $this->getTableSchema()->fullName . '.php'; return is_file($dataFile) ? require($dataFile) : []; - } else { - return parent::getData(); } + + return parent::getData(); } /** diff --git a/framework/test/ArrayFixture.php b/framework/test/ArrayFixture.php index f96d721..9b0ca3e 100644 --- a/framework/test/ArrayFixture.php +++ b/framework/test/ArrayFixture.php @@ -62,9 +62,9 @@ class ArrayFixture extends Fixture implements \IteratorAggregate, \ArrayAccess, $dataFile = Yii::getAlias($this->dataFile); if (is_file($dataFile)) { return require($dataFile); - } else { - throw new InvalidConfigException("Fixture data file does not exist: {$this->dataFile}"); } + + throw new InvalidConfigException("Fixture data file does not exist: {$this->dataFile}"); } /** diff --git a/framework/test/BaseActiveFixture.php b/framework/test/BaseActiveFixture.php index fd86f1f..acc1732 100644 --- a/framework/test/BaseActiveFixture.php +++ b/framework/test/BaseActiveFixture.php @@ -101,9 +101,9 @@ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate $dataFile = Yii::getAlias($this->dataFile); if (is_file($dataFile)) { return require($dataFile); - } else { - throw new InvalidConfigException("Fixture data file does not exist: {$this->dataFile}"); } + + throw new InvalidConfigException("Fixture data file does not exist: {$this->dataFile}"); } /** diff --git a/framework/validators/CompareValidator.php b/framework/validators/CompareValidator.php index de9d707..5eb5fc0 100644 --- a/framework/validators/CompareValidator.php +++ b/framework/validators/CompareValidator.php @@ -176,9 +176,9 @@ class CompareValidator extends Validator 'compareValue' => $this->compareValue, 'compareValueOrAttribute' => $this->compareValue, ]]; - } else { - return null; } + + return null; } /** diff --git a/framework/validators/DateValidator.php b/framework/validators/DateValidator.php index 04c1ac7..1acb672 100644 --- a/framework/validators/DateValidator.php +++ b/framework/validators/DateValidator.php @@ -312,9 +312,9 @@ class DateValidator extends Validator return [$this->tooSmall, ['min' => $this->minString]]; } elseif ($this->max !== null && $timestamp > $this->max) { return [$this->tooBig, ['max' => $this->maxString]]; - } else { - return null; } + + return null; } /** @@ -346,11 +346,12 @@ class DateValidator extends Validator } else { if (extension_loaded('intl')) { return $this->parseDateValueIntl($value, $format); - } else { - // fallback to PHP if intl is not installed - $format = FormatConverter::convertDateIcuToPhp($format, 'date'); } + + // fallback to PHP if intl is not installed + $format = FormatConverter::convertDateIcuToPhp($format, 'date'); } + return $this->parseDateValuePHP($value, $format); } diff --git a/framework/validators/EachValidator.php b/framework/validators/EachValidator.php index 385e4f2..d86154e 100644 --- a/framework/validators/EachValidator.php +++ b/framework/validators/EachValidator.php @@ -116,9 +116,9 @@ class EachValidator extends Validator $model = new Model(); // mock up context model } return Validator::createValidator($rule[0], $model, $this->attributes, array_slice($rule, 1)); - } else { - throw new InvalidConfigException('Invalid validation rule: a rule must be an array specifying validator type.'); } + + throw new InvalidConfigException('Invalid validation rule: a rule must be an array specifying validator type.'); } /** @@ -184,9 +184,9 @@ class EachValidator extends Validator if ($this->allowMessageFromRule) { $result[1]['value'] = $v; return $result; - } else { - return [$this->message, ['value' => $v]]; } + + return [$this->message, ['value' => $v]]; } } diff --git a/framework/validators/ExistValidator.php b/framework/validators/ExistValidator.php index a582701..31072f8 100644 --- a/framework/validators/ExistValidator.php +++ b/framework/validators/ExistValidator.php @@ -183,9 +183,9 @@ class ExistValidator extends Validator return [$this->message, []]; } return $query->count("DISTINCT [[$this->targetAttribute]]") == count($value) ? null : [$this->message, []]; - } else { - return $query->exists() ? null : [$this->message, []]; } + + return $query->exists() ? null : [$this->message, []]; } /** diff --git a/framework/validators/InlineValidator.php b/framework/validators/InlineValidator.php index 38988e3..3192598 100644 --- a/framework/validators/InlineValidator.php +++ b/framework/validators/InlineValidator.php @@ -84,8 +84,8 @@ class InlineValidator extends Validator } return call_user_func($method, $attribute, $this->params, $this); - } else { - return null; } + + return null; } } diff --git a/framework/validators/IpValidator.php b/framework/validators/IpValidator.php index 89800b2..72ac999 100644 --- a/framework/validators/IpValidator.php +++ b/framework/validators/IpValidator.php @@ -297,9 +297,9 @@ class IpValidator extends Validator if (is_array($result)) { $result[1] = array_merge(['ip' => is_array($value) ? 'array()' : $value], $result[1]); return $result; - } else { - return null; } + + return null; } /** @@ -564,16 +564,17 @@ class IpValidator extends Validator { if ($this->getIpVersion($ip) === 4) { return str_pad(base_convert(ip2long($ip), 10, 2), static::IPV4_ADDRESS_LENGTH, '0', STR_PAD_LEFT); - } else { - $unpack = unpack('A16', inet_pton($ip)); - $binStr = array_shift($unpack); - $bytes = static::IPV6_ADDRESS_LENGTH / 8; // 128 bit / 8 = 16 bytes + } + + $unpack = unpack('A16', inet_pton($ip)); + $binStr = array_shift($unpack); + $bytes = static::IPV6_ADDRESS_LENGTH / 8; // 128 bit / 8 = 16 bytes $result = ''; - while ($bytes-- > 0) { - $result = sprintf('%08b', isset($binStr[$bytes]) ? ord($binStr[$bytes]) : '0') . $result; - } - return $result; + while ($bytes-- > 0) { + $result = sprintf('%08b', isset($binStr[$bytes]) ? ord($binStr[$bytes]) : '0') . $result; } + + return $result; } /** diff --git a/framework/validators/NumberValidator.php b/framework/validators/NumberValidator.php index ca18d59..e438c04 100644 --- a/framework/validators/NumberValidator.php +++ b/framework/validators/NumberValidator.php @@ -113,9 +113,9 @@ class NumberValidator extends Validator return [$this->tooSmall, ['min' => $this->min]]; } elseif ($this->max !== null && $value > $this->max) { return [$this->tooBig, ['max' => $this->max]]; - } else { - return null; } + + return null; } /** diff --git a/framework/validators/RequiredValidator.php b/framework/validators/RequiredValidator.php index bba8a15..a8c620a 100644 --- a/framework/validators/RequiredValidator.php +++ b/framework/validators/RequiredValidator.php @@ -76,11 +76,11 @@ class RequiredValidator extends Validator } if ($this->requiredValue === null) { return [$this->message, []]; - } else { - return [$this->message, [ - 'requiredValue' => $this->requiredValue, - ]]; } + + return [$this->message, [ + 'requiredValue' => $this->requiredValue, + ]]; } /** diff --git a/framework/validators/Validator.php b/framework/validators/Validator.php index 021a721..ffac4dc 100644 --- a/framework/validators/Validator.php +++ b/framework/validators/Validator.php @@ -428,9 +428,9 @@ class Validator extends Component { if ($this->isEmpty !== null) { return call_user_func($this->isEmpty, $value); - } else { - return $value === null || $value === [] || $value === ''; } + + return $value === null || $value === [] || $value === ''; } /** diff --git a/framework/web/Application.php b/framework/web/Application.php index a43090b..b5c4e93 100644 --- a/framework/web/Application.php +++ b/framework/web/Application.php @@ -102,14 +102,14 @@ class Application extends \yii\base\Application $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; - } else { - $response = $this->getResponse(); - if ($result !== null) { - $response->data = $result; - } + } - return $response; + $response = $this->getResponse(); + if ($result !== null) { + $response->data = $result; } + + return $response; } catch (InvalidRouteException $e) { throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'), $e->getCode(), $e); } @@ -125,12 +125,12 @@ class Application extends \yii\base\Application if ($this->_homeUrl === null) { if ($this->getUrlManager()->showScriptName) { return $this->getRequest()->getScriptUrl(); - } else { - return $this->getRequest()->getBaseUrl() . '/'; } - } else { - return $this->_homeUrl; + + return $this->getRequest()->getBaseUrl() . '/'; } + + return $this->_homeUrl; } /** diff --git a/framework/web/AssetManager.php b/framework/web/AssetManager.php index c7b2cd7..3a64186 100644 --- a/framework/web/AssetManager.php +++ b/framework/web/AssetManager.php @@ -213,9 +213,9 @@ class AssetManager extends Component throw new InvalidConfigException("The directory does not exist: {$this->basePath}"); } elseif (!is_writable($this->basePath)) { throw new InvalidConfigException("The directory is not writable by the Web process: {$this->basePath}"); - } else { - $this->basePath = realpath($this->basePath); } + + $this->basePath = realpath($this->basePath); $this->baseUrl = rtrim(Yii::getAlias($this->baseUrl), '/'); } @@ -243,9 +243,9 @@ class AssetManager extends Component return $this->bundles[$name] = $this->loadBundle($name, $this->bundles[$name], $publish); } elseif ($this->bundles[$name] === false) { return $this->loadDummyBundle($name); - } else { - throw new InvalidConfigException("Invalid asset bundle configuration: $name"); } + + throw new InvalidConfigException("Invalid asset bundle configuration: $name"); } /** @@ -319,9 +319,9 @@ class AssetManager extends Component if ($this->appendTimestamp && ($timestamp = @filemtime("$basePath/$asset")) > 0) { return "$baseUrl/$asset?v=$timestamp"; - } else { - return "$baseUrl/$asset"; } + + return "$baseUrl/$asset"; } /** @@ -334,9 +334,9 @@ class AssetManager extends Component { if (($actualAsset = $this->resolveAsset($bundle, $asset)) !== false) { return Url::isRelative($actualAsset) ? $this->basePath . '/' . $actualAsset : false; - } else { - return Url::isRelative($asset) ? $bundle->basePath . '/' . $asset : false; } + + return Url::isRelative($asset) ? $bundle->basePath . '/' . $asset : false; } /** @@ -456,9 +456,9 @@ class AssetManager extends Component if (is_file($src)) { return $this->_published[$path] = $this->publishFile($src); - } else { - return $this->_published[$path] = $this->publishDirectory($src, $options); } + + return $this->_published[$path] = $this->publishDirectory($src, $options); } /** @@ -564,9 +564,9 @@ class AssetManager extends Component } if (is_string($path) && ($path = realpath($path)) !== false) { return $this->basePath . DIRECTORY_SEPARATOR . $this->hash($path) . (is_file($path) ? DIRECTORY_SEPARATOR . basename($path) : ''); - } else { - return false; } + + return false; } /** @@ -585,9 +585,9 @@ class AssetManager extends Component } if (is_string($path) && ($path = realpath($path)) !== false) { return $this->baseUrl . '/' . $this->hash($path) . (is_file($path) ? '/' . basename($path) : ''); - } else { - return false; } + + return false; } /** diff --git a/framework/web/ErrorHandler.php b/framework/web/ErrorHandler.php index d4a2f66..7ca0bad 100644 --- a/framework/web/ErrorHandler.php +++ b/framework/web/ErrorHandler.php @@ -250,9 +250,9 @@ class ErrorHandler extends \yii\base\ErrorHandler require(Yii::getAlias($_file_)); return ob_get_clean(); - } else { - return Yii::$app->getView()->renderFile($_file_, $_params_, $this); } + + return Yii::$app->getView()->renderFile($_file_, $_params_, $this); } /** @@ -265,9 +265,9 @@ class ErrorHandler extends \yii\base\ErrorHandler { if (($previous = $exception->getPrevious()) !== null) { return $this->renderFile($this->previousExceptionView, ['exception' => $previous]); - } else { - return ''; } + + return ''; } /** diff --git a/framework/web/GroupUrlRule.php b/framework/web/GroupUrlRule.php index 800dd84..dad6ef9 100644 --- a/framework/web/GroupUrlRule.php +++ b/framework/web/GroupUrlRule.php @@ -116,9 +116,9 @@ class GroupUrlRule extends CompositeUrlRule $pathInfo = $request->getPathInfo(); if ($this->prefix === '' || strpos($pathInfo . '/', $this->prefix . '/') === 0) { return parent::parseRequest($manager, $request); - } else { - return false; } + + return false; } /** @@ -128,9 +128,9 @@ class GroupUrlRule extends CompositeUrlRule { if ($this->routePrefix === '' || strpos($route, $this->routePrefix . '/') === 0) { return parent::createUrl($manager, $route, $params); - } else { - $this->createStatus = UrlRule::CREATE_STATUS_ROUTE_MISMATCH; - return false; } + + $this->createStatus = UrlRule::CREATE_STATUS_ROUTE_MISMATCH; + return false; } } diff --git a/framework/web/HeaderCollection.php b/framework/web/HeaderCollection.php index 2a616ef..f9b55f9 100644 --- a/framework/web/HeaderCollection.php +++ b/framework/web/HeaderCollection.php @@ -74,9 +74,9 @@ class HeaderCollection extends Object implements \IteratorAggregate, \ArrayAcces $name = strtolower($name); if (isset($this->_headers[$name])) { return $first ? reset($this->_headers[$name]) : $this->_headers[$name]; - } else { - return $default; } + + return $default; } /** @@ -151,9 +151,9 @@ class HeaderCollection extends Object implements \IteratorAggregate, \ArrayAcces $value = $this->_headers[$name]; unset($this->_headers[$name]); return $value; - } else { - return null; } + + return null; } /** diff --git a/framework/web/HttpException.php b/framework/web/HttpException.php index db4a720..f7f6ac5 100644 --- a/framework/web/HttpException.php +++ b/framework/web/HttpException.php @@ -55,8 +55,8 @@ class HttpException extends UserException { if (isset(Response::$httpStatuses[$this->statusCode])) { return Response::$httpStatuses[$this->statusCode]; - } else { - return 'Error'; } + + return 'Error'; } } diff --git a/framework/web/MultiFieldSession.php b/framework/web/MultiFieldSession.php index dcb0d6d..02ef540 100644 --- a/framework/web/MultiFieldSession.php +++ b/framework/web/MultiFieldSession.php @@ -134,8 +134,8 @@ abstract class MultiFieldSession extends Session return session_encode(); } return $fields['data']; - } else { - return isset($fields['data']) ? $fields['data'] : ''; } + + return isset($fields['data']) ? $fields['data'] : ''; } } diff --git a/framework/web/Response.php b/framework/web/Response.php index a39ba1d..4b4d7e3 100644 --- a/framework/web/Response.php +++ b/framework/web/Response.php @@ -647,9 +647,9 @@ class Response extends \yii\base\Response } if ($start < 0 || $start > $end) { return false; - } else { - return [$start, $end]; } + + return [$start, $end]; } /** diff --git a/framework/web/Session.php b/framework/web/Session.php index 2455888..3e4e2c2 100644 --- a/framework/web/Session.php +++ b/framework/web/Session.php @@ -395,9 +395,9 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co return false; } elseif (ini_get('session.use_only_cookies') === '1') { return true; - } else { - return null; } + + return null; } /** @@ -622,9 +622,9 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co unset($_SESSION[$key]); return $value; - } else { - return null; } + + return null; } /** @@ -697,9 +697,9 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co } return $value; - } else { - return $defaultValue; } + + return $defaultValue; } /** diff --git a/framework/web/UrlManager.php b/framework/web/UrlManager.php index 9633df7..ec23690 100644 --- a/framework/web/UrlManager.php +++ b/framework/web/UrlManager.php @@ -308,18 +308,18 @@ class UrlManager extends Component if ($normalized) { // pathInfo was changed by normalizer - we need also normalize route return $this->normalizer->normalizeRoute([$pathInfo, []]); - } else { - return [$pathInfo, []]; - } - } else { - Yii::trace('Pretty URL not enabled. Using default URL parsing logic.', __METHOD__); - $route = $request->getQueryParam($this->routeParam, ''); - if (is_array($route)) { - $route = ''; } - return [(string) $route, []]; + return [$pathInfo, []]; + } + + Yii::trace('Pretty URL not enabled. Using default URL parsing logic.', __METHOD__); + $route = $request->getQueryParam($this->routeParam, ''); + if (is_array($route)) { + $route = ''; } + + return [(string) $route, []]; } /** @@ -393,19 +393,19 @@ class UrlManager extends Component if (strpos($url, '://') !== false) { if ($baseUrl !== '' && ($pos = strpos($url, '/', 8)) !== false) { return substr($url, 0, $pos) . $baseUrl . substr($url, $pos) . $anchor; - } else { - return $url . $baseUrl . $anchor; } + + return $url . $baseUrl . $anchor; } elseif (strpos($url, '//') === 0) { if ($baseUrl !== '' && ($pos = strpos($url, '/', 2)) !== false) { return substr($url, 0, $pos) . $baseUrl . substr($url, $pos) . $anchor; - } else { - return $url . $baseUrl . $anchor; } - } else { - $url = ltrim($url, '/'); - return "$baseUrl/{$url}{$anchor}"; + + return $url . $baseUrl . $anchor; } + + $url = ltrim($url, '/'); + return "$baseUrl/{$url}{$anchor}"; } if ($this->suffix !== null) { @@ -417,14 +417,14 @@ class UrlManager extends Component $route = ltrim($route, '/'); return "$baseUrl/{$route}{$anchor}"; - } else { - $url = "$baseUrl?{$this->routeParam}=" . urlencode($route); - if (!empty($params) && ($query = http_build_query($params)) !== '') { - $url .= '&' . $query; - } + } - return $url . $anchor; + $url = "$baseUrl?{$this->routeParam}=" . urlencode($route); + if (!empty($params) && ($query = http_build_query($params)) !== '') { + $url .= '&' . $query; } + + return $url . $anchor; } /** diff --git a/framework/web/UrlRule.php b/framework/web/UrlRule.php index d66595b..84b44fe 100644 --- a/framework/web/UrlRule.php +++ b/framework/web/UrlRule.php @@ -353,9 +353,9 @@ class UrlRule extends Object implements UrlRuleInterface { if ($this->normalizer === null) { return $manager->normalizer; - } else { - return $this->normalizer; } + + return $this->normalizer; } /** @@ -439,9 +439,9 @@ class UrlRule extends Object implements UrlRuleInterface if ($normalized) { // pathInfo was changed by normalizer - we need also normalize route return $this->getNormalizer($manager)->normalizeRoute([$route, $params]); - } else { - return [$route, $params]; } + + return [$route, $params]; } /** diff --git a/framework/web/User.php b/framework/web/User.php index c483e81..69e849d 100644 --- a/framework/web/User.php +++ b/framework/web/User.php @@ -271,9 +271,9 @@ class User extends Component $identity = $class::findIdentityByAccessToken($token, $type); if ($identity && $this->login($identity)) { return $identity; - } else { - return null; } + + return null; } /** @@ -363,9 +363,9 @@ class User extends Component if (is_array($url)) { if (isset($url[0])) { return Yii::$app->getUrlManager()->createUrl($url); - } else { - $url = null; } + + $url = null; } return $url === null ? Yii::$app->getHomeUrl() : $url; diff --git a/framework/web/ViewAction.php b/framework/web/ViewAction.php index 9a45954..17c2d45 100644 --- a/framework/web/ViewAction.php +++ b/framework/web/ViewAction.php @@ -87,11 +87,11 @@ class ViewAction extends Action if (YII_DEBUG) { throw new NotFoundHttpException($e->getMessage()); - } else { - throw new NotFoundHttpException( - Yii::t('yii', 'The requested view "{name}" was not found.', ['name' => $viewName]) - ); } + + throw new NotFoundHttpException( + Yii::t('yii', 'The requested view "{name}" was not found.', ['name' => $viewName]) + ); } return $output; @@ -121,9 +121,9 @@ class ViewAction extends Action if (!is_string($viewName) || !preg_match('~^\w(?:(?!\/\.{0,2}\/)[\w\/\-\.])*$~', $viewName)) { if (YII_DEBUG) { throw new NotFoundHttpException("The requested view \"$viewName\" must start with a word character, must not contain /../ or /./, can contain only word characters, forward slashes, dots and dashes."); - } else { - throw new NotFoundHttpException(Yii::t('yii', 'The requested view "{name}" was not found.', ['name' => $viewName])); } + + throw new NotFoundHttpException(Yii::t('yii', 'The requested view "{name}" was not found.', ['name' => $viewName])); } return empty($this->viewPrefix) ? $viewName : $this->viewPrefix . '/' . $viewName; diff --git a/framework/widgets/ActiveForm.php b/framework/widgets/ActiveForm.php index a65f04f..fe5c7d8 100644 --- a/framework/widgets/ActiveForm.php +++ b/framework/widgets/ActiveForm.php @@ -342,9 +342,9 @@ class ActiveForm extends Widget $field = array_pop($this->_fields); if ($field instanceof ActiveField) { return $field->end(); - } else { - throw new InvalidCallException('Mismatching endField() call.'); } + + throw new InvalidCallException('Mismatching endField() call.'); } /** diff --git a/framework/widgets/DetailView.php b/framework/widgets/DetailView.php index afe747f..5590173 100644 --- a/framework/widgets/DetailView.php +++ b/framework/widgets/DetailView.php @@ -179,9 +179,9 @@ class DetailView extends Widget '{captionOptions}' => $captionOptions, '{contentOptions}' => $contentOptions, ]); - } else { - return call_user_func($this->template, $attribute, $index, $this); } + + return call_user_func($this->template, $attribute, $index, $this); } /** diff --git a/framework/widgets/Menu.php b/framework/widgets/Menu.php index 9869650..6efaa7e 100644 --- a/framework/widgets/Menu.php +++ b/framework/widgets/Menu.php @@ -238,13 +238,13 @@ class Menu extends Widget '{url}' => Html::encode(Url::to($item['url'])), '{label}' => $item['label'], ]); - } else { - $template = ArrayHelper::getValue($item, 'template', $this->labelTemplate); - - return strtr($template, [ - '{label}' => $item['label'], - ]); } + + $template = ArrayHelper::getValue($item, 'template', $this->labelTemplate); + + return strtr($template, [ + '{label}' => $item['label'], + ]); } /** diff --git a/tests/data/ar/Order.php b/tests/data/ar/Order.php index 464f374..9e65b48 100644 --- a/tests/data/ar/Order.php +++ b/tests/data/ar/Order.php @@ -196,9 +196,9 @@ class Order extends ActiveRecord $this->created_at = time(); return true; - } else { - return false; } + + return false; } public function attributeLabels() diff --git a/tests/framework/console/controllers/PHPMessageControllerTest.php b/tests/framework/console/controllers/PHPMessageControllerTest.php index 4c74d60..c8a1fec 100644 --- a/tests/framework/console/controllers/PHPMessageControllerTest.php +++ b/tests/framework/console/controllers/PHPMessageControllerTest.php @@ -88,8 +88,8 @@ class PHPMessageControllerTest extends BaseMessageControllerTest // https://github.com/facebook/hhvm/issues/1447 $content = file_get_contents($messageFilePath); return eval(substr($content, strpos($content, 'return '))); - } else { - return require $messageFilePath; } + + return require $messageFilePath; } } diff --git a/tests/framework/log/DispatcherTest.php b/tests/framework/log/DispatcherTest.php index a9182f6..cf3a7c9 100644 --- a/tests/framework/log/DispatcherTest.php +++ b/tests/framework/log/DispatcherTest.php @@ -10,9 +10,9 @@ namespace yii\log { { if (\yiiunit\framework\log\DispatcherTest::$microtimeIsMocked) { return \yiiunit\framework\log\DispatcherTest::microtime(func_get_args()); - } else { - return \microtime($get_as_float); } + + return \microtime($get_as_float); } }