Skip to content

Commit

Permalink
Enable no_useless_else rule in php-cs-fixer (yiisoft#14420)
Browse files Browse the repository at this point in the history
  • Loading branch information
rob006 authored and samdark committed Jul 10, 2017
1 parent 341b8d0 commit fe8a0a6
Show file tree
Hide file tree
Showing 103 changed files with 742 additions and 716 deletions.
4 changes: 2 additions & 2 deletions build/controllers/Utf8Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ private function unicodeOrd($c)
return ($h & 0x0F) << 18 | (ord($c[1]) & 0x3F) << 12
| (ord($c[2]) & 0x3F) << 6
| (ord($c[3]) & 0x3F);
} else {
return false;
}

return false;
}
}
2 changes: 1 addition & 1 deletion cs/src/YiiConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function __construct($name = 'yii-cs-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,
Expand Down
4 changes: 2 additions & 2 deletions framework/base/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public function runWithParams($params)
$this->afterRun();

return $result;
} else {
return null;
}

return null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions framework/base/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,9 +651,9 @@ public function end($status = 0, $response = null)

if (YII_ENV_TEST) {
throw new ExitException($status);
} else {
exit($status);
}

exit($status);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions framework/base/DynamicModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public function __get($name)
{
if (array_key_exists($name, $this->_attributes)) {
return $this->_attributes[$name];
} else {
return parent::__get($name);
}

return parent::__get($name);
}

/**
Expand All @@ -106,9 +106,9 @@ public function __isset($name)
{
if (array_key_exists($name, $this->_attributes)) {
return isset($this->_attributes[$name]);
} else {
return parent::__isset($name);
}

return parent::__isset($name);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions framework/base/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ public function __get($name)
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);
}

/**
Expand Down Expand Up @@ -178,9 +178,9 @@ public function __isset($name)
$getter = 'get' . $name;
if (method_exists($this, $getter)) {
return $this->$getter() !== null;
} else {
return false;
}

return false;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions framework/base/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ public function getUrl($url)
{
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.');
}

/**
Expand All @@ -181,8 +181,8 @@ public function getPath($path)
{
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.');
}
}
8 changes: 4 additions & 4 deletions framework/base/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ public static function end()
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.');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions framework/caching/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ public function get($key)
}
if (is_array($value) && !($value[1] instanceof Dependency && $value[1]->isChanged($this))) {
return $value[0];
} else {
return false;
}

return false;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions framework/caching/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ protected function setValue($key, $value, $duration)
}

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;
}

/**
Expand Down Expand Up @@ -206,9 +206,9 @@ protected function getCacheFile($key)
}

return $base . DIRECTORY_SEPARATOR . $key . $this->cacheFileSuffix;
} else {
return $this->cachePath . DIRECTORY_SEPARATOR . $key . $this->cacheFileSuffix;
}

return $this->cachePath . DIRECTORY_SEPARATOR . $key . $this->cacheFileSuffix;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions framework/caching/MemCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ protected function setValues($data, $duration)
// 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);
}

/**
Expand Down
13 changes: 7 additions & 6 deletions framework/captcha/CaptchaAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,12 @@ public function run()
// 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());
}

/**
Expand Down Expand Up @@ -255,9 +256,9 @@ protected function renderImage($code)
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");
}

/**
Expand Down
14 changes: 7 additions & 7 deletions framework/console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ protected function loadConfig($config)
$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");
}
}
}
Expand Down Expand Up @@ -147,12 +147,12 @@ public function handleRequest($request)
$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;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions framework/console/controllers/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ protected function loadTargets($targets, $bundles)
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;
Expand Down Expand Up @@ -732,10 +732,10 @@ public function actionTemplate($configFile)
}
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;
}

/**
Expand Down
24 changes: 12 additions & 12 deletions framework/console/controllers/BaseMigrateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ public function beforeAction($action)
$this->stdout("Yii Migration Tool (based on Yii v{$version})\n\n");

return true;
} else {
return false;
}

return false;
}

/**
Expand Down Expand Up @@ -673,12 +673,12 @@ protected function migrateUp($class)
$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;
}

/**
Expand All @@ -701,12 +701,12 @@ protected function migrateDown($class)
$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;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions framework/console/controllers/HelpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ protected function validateControllerClass($controllerClass)
if (class_exists($controllerClass)) {
$class = new \ReflectionClass($controllerClass);
return !$class->isAbstract() && $class->isSubclassOf('yii\console\Controller');
} else {
return false;
}

return false;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions framework/console/controllers/MigrateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ public function beforeAction($action)
$this->db = Instance::ensure($this->db, Connection::className());
}
return true;
} else {
return false;
}

return false;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions framework/data/ActiveDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ protected function prepareKeys($models)
}

return $keys;
} else {
return array_keys($models);
}

return array_keys($models);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions framework/data/ArrayDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ protected function prepareKeys($models)
}

return $keys;
} else {
return array_keys($models);
}

return array_keys($models);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions framework/data/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ public function getPageCount()
$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;
Expand Down Expand Up @@ -281,9 +281,9 @@ public function createUrl($page, $pageSize = null, $absolute = false)
$urlManager = $this->urlManager === null ? Yii::$app->getUrlManager() : $this->urlManager;
if ($absolute) {
return $urlManager->createAbsoluteUrl($params);
} else {
return $urlManager->createUrl($params);
}

return $urlManager->createUrl($params);
}

/**
Expand Down
Loading

0 comments on commit fe8a0a6

Please sign in to comment.