Commit 0e1a23f0 by Alexander Makarov

Merge pull request #2610 from AlexGx/code-style-fix

Code style fix
parents ff379f09 d3171b6c
...@@ -442,17 +442,17 @@ class Formatter extends Component ...@@ -442,17 +442,17 @@ class Formatter extends Component
switch($position) { switch($position) {
case 0: case 0:
return $verbose ? Yii::t('yii','{n, plural, =1{# byte} other{# bytes}}', $params) : Yii::t('yii', '{n} B', $params); return $verbose ? Yii::t('yii', '{n, plural, =1{# byte} other{# bytes}}', $params) : Yii::t('yii', '{n} B', $params);
case 1: case 1:
return $verbose ? Yii::t('yii','{n, plural, =1{# kilobyte} other{# kilobytes}}', $params) : Yii::t('yii','{n} KB', $params); return $verbose ? Yii::t('yii', '{n, plural, =1{# kilobyte} other{# kilobytes}}', $params) : Yii::t('yii', '{n} KB', $params);
case 2: case 2:
return $verbose ? Yii::t('yii','{n, plural, =1{# megabyte} other{# megabytes}}', $params) : Yii::t('yii','{n} MB', $params); return $verbose ? Yii::t('yii', '{n, plural, =1{# megabyte} other{# megabytes}}', $params) : Yii::t('yii', '{n} MB', $params);
case 3: case 3:
return $verbose ? Yii::t('yii','{n, plural, =1{# gigabyte} other{# gigabytes}}', $params) : Yii::t('yii','{n} GB', $params); return $verbose ? Yii::t('yii', '{n, plural, =1{# gigabyte} other{# gigabytes}}', $params) : Yii::t('yii', '{n} GB', $params);
case 4: case 4:
return $verbose ? Yii::t('yii','{n, plural, =1{# terabyte} other{# terabytes}}', $params) : Yii::t('yii','{n} TB', $params); return $verbose ? Yii::t('yii', '{n, plural, =1{# terabyte} other{# terabytes}}', $params) : Yii::t('yii', '{n} TB', $params);
default: default:
return $verbose ? Yii::t('yii','{n, plural, =1{# petabyte} other{# petabytes}}', $params) : Yii::t('yii','{n} PB', $params); return $verbose ? Yii::t('yii', '{n, plural, =1{# petabyte} other{# petabytes}}', $params) : Yii::t('yii', '{n} PB', $params);
} }
} }
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
namespace yii\base; namespace yii\base;
use Yii; use Yii;
/** /**
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
namespace yii\caching; namespace yii\caching;
use yii\base\InvalidConfigException; use yii\base\InvalidConfigException;
/** /**
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
namespace yii\caching; namespace yii\caching;
use yii\base\InvalidConfigException; use yii\base\InvalidConfigException;
/** /**
......
...@@ -64,7 +64,7 @@ class FixtureController extends Controller ...@@ -64,7 +64,7 @@ class FixtureController extends Controller
public function globalOptions() public function globalOptions()
{ {
return array_merge(parent::globalOptions(), [ return array_merge(parent::globalOptions(), [
'namespace','globalFixtures' 'namespace', 'globalFixtures'
]); ]);
} }
...@@ -74,6 +74,7 @@ class FixtureController extends Controller ...@@ -74,6 +74,7 @@ class FixtureController extends Controller
* whitespace between names. Note that if you are loading fixtures to storage, for example: database or nosql, * whitespace between names. Note that if you are loading fixtures to storage, for example: database or nosql,
* storage will not be cleared, data will be appended to already existed. * storage will not be cleared, data will be appended to already existed.
* @param array $fixtures * @param array $fixtures
* @param array $except
* @throws \yii\console\Exception * @throws \yii\console\Exception
*/ */
public function actionLoad(array $fixtures, array $except = []) public function actionLoad(array $fixtures, array $except = [])
...@@ -99,7 +100,7 @@ class FixtureController extends Controller ...@@ -99,7 +100,7 @@ class FixtureController extends Controller
} }
$filtered = array_diff($foundFixtures, $except); $filtered = array_diff($foundFixtures, $except);
$fixtures = $this->getFixturesConfig(array_merge($this->globalFixtures ,$filtered)); $fixtures = $this->getFixturesConfig(array_merge($this->globalFixtures, $filtered));
if (!$fixtures) { if (!$fixtures) {
throw new Exception('No fixtures were found in namespace: "' . $this->namespace . '"' . ''); throw new Exception('No fixtures were found in namespace: "' . $this->namespace . '"' . '');
...@@ -317,5 +318,4 @@ class FixtureController extends Controller ...@@ -317,5 +318,4 @@ class FixtureController extends Controller
{ {
return Yii::getAlias('@' . str_replace('\\', '/', $this->namespace)); return Yii::getAlias('@' . str_replace('\\', '/', $this->namespace));
} }
} }
...@@ -268,7 +268,7 @@ class MessageController extends Controller ...@@ -268,7 +268,7 @@ class MessageController extends Controller
{ {
echo "Saving messages to $fileName..."; echo "Saving messages to $fileName...";
if (is_file($fileName)) { if (is_file($fileName)) {
if($format === 'po'){ if ($format === 'po') {
$translated = file_get_contents($fileName); $translated = file_get_contents($fileName);
preg_match_all('/(?<=msgid ").*(?="\n(#*)msgstr)/', $translated, $keys); preg_match_all('/(?<=msgid ").*(?="\n(#*)msgstr)/', $translated, $keys);
preg_match_all('/(?<=msgstr ").*(?="\n\n)/', $translated, $values); preg_match_all('/(?<=msgstr ").*(?="\n\n)/', $translated, $values);
...@@ -285,7 +285,7 @@ class MessageController extends Controller ...@@ -285,7 +285,7 @@ class MessageController extends Controller
$merged = []; $merged = [];
$untranslated = []; $untranslated = [];
foreach ($messages as $message) { foreach ($messages as $message) {
if($format === 'po'){ if ($format === 'po') {
$message = preg_replace('/\"/', '\"', $message); $message = preg_replace('/\"/', '\"', $message);
} }
if (array_key_exists($message, $translated) && strlen($translated[$message]) > 0) { if (array_key_exists($message, $translated) && strlen($translated[$message]) > 0) {
...@@ -317,9 +317,9 @@ class MessageController extends Controller ...@@ -317,9 +317,9 @@ class MessageController extends Controller
if (false === $overwrite) { if (false === $overwrite) {
$fileName .= '.merged'; $fileName .= '.merged';
} }
if ($format === 'po'){ if ($format === 'po') {
$output = ''; $output = '';
foreach ($merged as $k => $v){ foreach ($merged as $k => $v) {
$k = preg_replace('/(\")|(\\\")/', "\\\"", $k); $k = preg_replace('/(\")|(\\\")/', "\\\"", $k);
$v = preg_replace('/(\")|(\\\")/', "\\\"", $v); $v = preg_replace('/(\")|(\\\")/', "\\\"", $v);
if (substr($v, 0, 2) === '@@' && substr($v, -2) === '@@') { if (substr($v, 0, 2) === '@@' && substr($v, -2) === '@@') {
...@@ -338,7 +338,7 @@ class MessageController extends Controller ...@@ -338,7 +338,7 @@ class MessageController extends Controller
if ($format === 'po') { if ($format === 'po') {
$merged = ''; $merged = '';
sort($messages); sort($messages);
foreach($messages as $message) { foreach ($messages as $message) {
$message = preg_replace('/(\")|(\\\")/', '\\\"', $message); $message = preg_replace('/(\")|(\\\")/', '\\\"', $message);
$merged .= "msgid \"$message\"\n"; $merged .= "msgid \"$message\"\n";
$merged .= "msgstr \"\"\n"; $merged .= "msgstr \"\"\n";
......
...@@ -120,7 +120,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface ...@@ -120,7 +120,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
$this->findWith($this->with, $models); $this->findWith($this->with, $models);
} }
if (!$this->asArray) { if (!$this->asArray) {
foreach($models as $model) { foreach ($models as $model) {
$model->afterFind(); $model->afterFind();
} }
} }
......
...@@ -599,7 +599,7 @@ class QueryBuilder extends \yii\base\Object ...@@ -599,7 +599,7 @@ class QueryBuilder extends \yii\base\Object
if (strpos($column, '(') === false) { if (strpos($column, '(') === false) {
$column = $this->db->quoteColumnName($column); $column = $this->db->quoteColumnName($column);
} }
$columns[$i] = "$column AS " . $this->db->quoteColumnName($i);; $columns[$i] = "$column AS " . $this->db->quoteColumnName($i);
} elseif (strpos($column, '(') === false) { } elseif (strpos($column, '(') === false) {
if (preg_match('/^(.*?)(?i:\s+as\s+|\s+)([\w\-_\.]+)$/', $column, $matches)) { if (preg_match('/^(.*?)(?i:\s+as\s+|\s+)([\w\-_\.]+)$/', $column, $matches)) {
$columns[$i] = $this->db->quoteColumnName($matches[1]) . ' AS ' . $this->db->quoteColumnName($matches[2]); $columns[$i] = $this->db->quoteColumnName($matches[1]) . ' AS ' . $this->db->quoteColumnName($matches[2]);
......
...@@ -147,6 +147,7 @@ class BaseFileHelper ...@@ -147,6 +147,7 @@ class BaseFileHelper
* @param string $src the source directory * @param string $src the source directory
* @param string $dst the destination directory * @param string $dst the destination directory
* @param array $options options for directory copy. Valid options are: * @param array $options options for directory copy. Valid options are:
* @throws \yii\base\InvalidParamException if unable to open directory
* *
* - dirMode: integer, the permission to be set for newly copied directories. Defaults to 0775. * - dirMode: integer, the permission to be set for newly copied directories. Defaults to 0775.
* - fileMode: integer, the permission to be set for newly copied files. Defaults to the current environment setting. * - fileMode: integer, the permission to be set for newly copied files. Defaults to the current environment setting.
...@@ -280,14 +281,14 @@ class BaseFileHelper ...@@ -280,14 +281,14 @@ class BaseFileHelper
$options['basePath'] = realpath($dir); $options['basePath'] = realpath($dir);
// this should also be done only once // this should also be done only once
if (isset($options['except'])) { if (isset($options['except'])) {
foreach($options['except'] as $key=>$value) { foreach ($options['except'] as $key => $value) {
if (is_string($value)) { if (is_string($value)) {
$options['except'][$key] = static::parseExcludePattern($value); $options['except'][$key] = static::parseExcludePattern($value);
} }
} }
} }
if (isset($options['only'])) { if (isset($options['only'])) {
foreach($options['only'] as $key=>$value) { foreach ($options['only'] as $key => $value) {
if (is_string($value)) { if (is_string($value)) {
$options['only'][$key] = static::parseExcludePattern($value); $options['only'][$key] = static::parseExcludePattern($value);
} }
...@@ -397,7 +398,7 @@ class BaseFileHelper ...@@ -397,7 +398,7 @@ class BaseFileHelper
if ($pattern === $baseName) { if ($pattern === $baseName) {
return true; return true;
} }
} else if ($flags & self::PATTERN_ENDSWITH) { } elseif ($flags & self::PATTERN_ENDSWITH) {
/* "*literal" matching against "fooliteral" */ /* "*literal" matching against "fooliteral" */
$n = StringHelper::byteLength($pattern); $n = StringHelper::byteLength($pattern);
if (StringHelper::byteSubstr($pattern, 1, $n) === StringHelper::byteSubstr($baseName, -$n, $n)) { if (StringHelper::byteSubstr($pattern, 1, $n) === StringHelper::byteSubstr($baseName, -$n, $n)) {
...@@ -472,7 +473,7 @@ class BaseFileHelper ...@@ -472,7 +473,7 @@ class BaseFileHelper
*/ */
private static function lastExcludeMatchingFromList($basePath, $path, $excludes) private static function lastExcludeMatchingFromList($basePath, $path, $excludes)
{ {
foreach(array_reverse($excludes) as $exclude) { foreach (array_reverse($excludes) as $exclude) {
if (is_string($exclude)) { if (is_string($exclude)) {
$exclude = self::parseExcludePattern($exclude); $exclude = self::parseExcludePattern($exclude);
} }
...@@ -508,13 +509,14 @@ class BaseFileHelper ...@@ -508,13 +509,14 @@ class BaseFileHelper
if (!is_string($pattern)) { if (!is_string($pattern)) {
throw new InvalidParamException('Exclude/include pattern must be a string.'); throw new InvalidParamException('Exclude/include pattern must be a string.');
} }
$result = array( $result = [
'pattern' => $pattern, 'pattern' => $pattern,
'flags' => 0, 'flags' => 0,
'firstWildcard' => false, 'firstWildcard' => false,
); ];
if (!isset($pattern[0])) if (!isset($pattern[0])) {
return $result; return $result;
}
if ($pattern[0] == '!') { if ($pattern[0] == '!') {
$result['flags'] |= self::PATTERN_NEGATIVE; $result['flags'] |= self::PATTERN_NEGATIVE;
...@@ -526,11 +528,13 @@ class BaseFileHelper ...@@ -526,11 +528,13 @@ class BaseFileHelper
$len--; $len--;
$result['flags'] |= self::PATTERN_MUSTBEDIR; $result['flags'] |= self::PATTERN_MUSTBEDIR;
} }
if (strpos($pattern, '/') === false) if (strpos($pattern, '/') === false) {
$result['flags'] |= self::PATTERN_NODIR; $result['flags'] |= self::PATTERN_NODIR;
}
$result['firstWildcard'] = self::firstWildcardInPattern($pattern); $result['firstWildcard'] = self::firstWildcardInPattern($pattern);
if ($pattern[0] == '*' && self::firstWildcardInPattern(StringHelper::byteSubstr($pattern, 1, StringHelper::byteLength($pattern))) === false) if ($pattern[0] == '*' && self::firstWildcardInPattern(StringHelper::byteSubstr($pattern, 1, StringHelper::byteLength($pattern))) === false) {
$result['flags'] |= self::PATTERN_ENDSWITH; $result['flags'] |= self::PATTERN_ENDSWITH;
}
$result['pattern'] = $pattern; $result['pattern'] = $pattern;
return $result; return $result;
} }
...@@ -542,8 +546,8 @@ class BaseFileHelper ...@@ -542,8 +546,8 @@ class BaseFileHelper
*/ */
private static function firstWildcardInPattern($pattern) private static function firstWildcardInPattern($pattern)
{ {
$wildcards = array('*','?','[','\\'); $wildcards = ['*', '?', '[', '\\'];
$wildcardSearch = function($r, $c) use ($pattern) { $wildcardSearch = function ($r, $c) use ($pattern) {
$p = strpos($pattern, $c); $p = strpos($pattern, $c);
return $r===false ? $p : ($p===false ? $r : min($r, $p)); return $r===false ? $p : ($p===false ? $r : min($r, $p));
}; };
......
...@@ -86,7 +86,7 @@ class BaseMarkdown ...@@ -86,7 +86,7 @@ class BaseMarkdown
/** @var \cebe\markdown\Markdown $parser */ /** @var \cebe\markdown\Markdown $parser */
if (!isset(static::$flavors[$flavor])) { if (!isset(static::$flavors[$flavor])) {
throw new InvalidParamException("Markdown flavor '$flavor' is not defined.'"); throw new InvalidParamException("Markdown flavor '$flavor' is not defined.'");
} elseif(!is_object($config = static::$flavors[$flavor])) { } elseif (!is_object($config = static::$flavors[$flavor])) {
$parser = Yii::createObject($config); $parser = Yii::createObject($config);
if (is_array($config)) { if (is_array($config)) {
foreach ($config as $name => $value) { foreach ($config as $name => $value) {
......
...@@ -107,10 +107,10 @@ class BaseSecurity ...@@ -107,10 +107,10 @@ class BaseSecurity
*/ */
protected static function stripPadding($data) protected static function stripPadding($data)
{ {
$end = StringHelper::byteSubstr($data, -1, NULL); $end = StringHelper::byteSubstr($data, -1, null);
$last = ord($end); $last = ord($end);
$n = StringHelper::byteLength($data) - $last; $n = StringHelper::byteLength($data) - $last;
if (StringHelper::byteSubstr($data, $n, NULL) == str_repeat($end, $last)) { if (StringHelper::byteSubstr($data, $n, null) == str_repeat($end, $last)) {
return StringHelper::byteSubstr($data, 0, $n); return StringHelper::byteSubstr($data, 0, $n);
} }
return false; return false;
......
...@@ -70,9 +70,9 @@ class GettextMessageSource extends MessageSource ...@@ -70,9 +70,9 @@ class GettextMessageSource extends MessageSource
if ($messages === null && $fallbackMessages === null && $fallbackLanguage != $this->sourceLanguage) { if ($messages === null && $fallbackMessages === null && $fallbackLanguage != $this->sourceLanguage) {
Yii::error("The message file for category '$category' does not exist: $messageFile Fallback file does not exist as well: $fallbackMessageFile", __METHOD__); Yii::error("The message file for category '$category' does not exist: $messageFile Fallback file does not exist as well: $fallbackMessageFile", __METHOD__);
} else if (empty($messages)) { } elseif (empty($messages)) {
return $fallbackMessages; return $fallbackMessages;
} else if (!empty($fallbackMessages)) { } elseif (!empty($fallbackMessages)) {
foreach ($fallbackMessages as $key => $value) { foreach ($fallbackMessages as $key => $value) {
if (!empty($value) && empty($messages[$key])) { if (!empty($value) && empty($messages[$key])) {
$messages[$key] = $fallbackMessages[$key]; $messages[$key] = $fallbackMessages[$key];
......
...@@ -126,7 +126,7 @@ class I18N extends Component ...@@ -126,7 +126,7 @@ class I18N extends Component
} }
$p = []; $p = [];
foreach($params as $name => $value) { foreach ($params as $name => $value) {
$p['{' . $name . '}'] = $value; $p['{' . $name . '}'] = $value;
} }
return strtr($message, $p); return strtr($message, $p);
......
...@@ -143,7 +143,7 @@ class MessageFormatter extends Component ...@@ -143,7 +143,7 @@ class MessageFormatter extends Component
return false; return false;
} }
$map = []; $map = [];
foreach($tokens as $i => $token) { foreach ($tokens as $i => $token) {
if (is_array($token)) { if (is_array($token)) {
$param = trim($token[0]); $param = trim($token[0]);
if (!isset($map[$param])) { if (!isset($map[$param])) {
...@@ -169,7 +169,7 @@ class MessageFormatter extends Component ...@@ -169,7 +169,7 @@ class MessageFormatter extends Component
return false; return false;
} else { } else {
$values = []; $values = [];
foreach($result as $key => $value) { foreach ($result as $key => $value) {
$values[$map[$key]] = $value; $values[$map[$key]] = $value;
} }
return $values; return $values;
...@@ -190,7 +190,7 @@ class MessageFormatter extends Component ...@@ -190,7 +190,7 @@ class MessageFormatter extends Component
if (($tokens = self::tokenizePattern($pattern)) === false) { if (($tokens = self::tokenizePattern($pattern)) === false) {
return false; return false;
} }
foreach($tokens as $i => $token) { foreach ($tokens as $i => $token) {
if (!is_array($token)) { if (!is_array($token)) {
continue; continue;
} }
...@@ -244,7 +244,7 @@ class MessageFormatter extends Component ...@@ -244,7 +244,7 @@ class MessageFormatter extends Component
$this->_errorMessage = "Message pattern is invalid."; $this->_errorMessage = "Message pattern is invalid.";
return false; return false;
} }
foreach($tokens as $i => $token) { foreach ($tokens as $i => $token) {
if (is_array($token)) { if (is_array($token)) {
if (($tokens[$i] = $this->parseToken($token, $args, $locale)) === false) { if (($tokens[$i] = $this->parseToken($token, $args, $locale)) === false) {
$this->_errorCode = -1; $this->_errorCode = -1;
......
...@@ -73,9 +73,9 @@ class PhpMessageSource extends MessageSource ...@@ -73,9 +73,9 @@ class PhpMessageSource extends MessageSource
if ($messages === null && $fallbackMessages === null && $fallbackLanguage != $this->sourceLanguage) { if ($messages === null && $fallbackMessages === null && $fallbackLanguage != $this->sourceLanguage) {
Yii::error("The message file for category '$category' does not exist: $messageFile Fallback file does not exist as well: $fallbackMessageFile", __METHOD__); Yii::error("The message file for category '$category' does not exist: $messageFile Fallback file does not exist as well: $fallbackMessageFile", __METHOD__);
} else if (empty($messages)) { } elseif (empty($messages)) {
return $fallbackMessages; return $fallbackMessages;
} else if (!empty($fallbackMessages)) { } elseif (!empty($fallbackMessages)) {
foreach ($fallbackMessages as $key => $value) { foreach ($fallbackMessages as $key => $value) {
if (!empty($value) && empty($messages[$key])) { if (!empty($value) && empty($messages[$key])) {
$messages[$key] = $fallbackMessages[$key]; $messages[$key] = $fallbackMessages[$key];
......
...@@ -348,5 +348,4 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont ...@@ -348,5 +348,4 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
$event = new MailEvent(['message' => $message, 'isSuccessful' => $isSuccessful]); $event = new MailEvent(['message' => $message, 'isSuccessful' => $isSuccessful]);
$this->trigger(self::EVENT_AFTER_SEND, $event); $this->trigger(self::EVENT_AFTER_SEND, $event);
} }
} }
...@@ -82,4 +82,3 @@ class Fixture extends Component ...@@ -82,4 +82,3 @@ class Fixture extends Component
{ {
} }
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
namespace yii\validators; namespace yii\validators;
use yii\web\AssetBundle; use yii\web\AssetBundle;
/** /**
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
namespace yii\validators; namespace yii\validators;
use yii\web\AssetBundle; use yii\web\AssetBundle;
/** /**
......
...@@ -82,7 +82,7 @@ class AssetConverter extends Component implements AssetConverterInterface ...@@ -82,7 +82,7 @@ class AssetConverter extends Component implements AssetConverterInterface
$proc = proc_open($command, $descriptor, $pipes, $basePath); $proc = proc_open($command, $descriptor, $pipes, $basePath);
$stdout = stream_get_contents($pipes[1]); $stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]); $stderr = stream_get_contents($pipes[2]);
foreach($pipes as $pipe) { foreach ($pipes as $pipe) {
fclose($pipe); fclose($pipe);
} }
$status = proc_close($proc); $status = proc_close($proc);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
namespace yii\widgets; namespace yii\widgets;
use yii\web\AssetBundle; use yii\web\AssetBundle;
/** /**
......
...@@ -128,7 +128,7 @@ class LinkPager extends Widget ...@@ -128,7 +128,7 @@ class LinkPager extends Widget
protected function registerLinkTags() protected function registerLinkTags()
{ {
$view = $this->getView(); $view = $this->getView();
foreach($this->pagination->getLinks() as $rel => $href) { foreach ($this->pagination->getLinks() as $rel => $href) {
$view->registerLinkTag(['rel' => $rel, 'href' => $href], $rel); $view->registerLinkTag(['rel' => $rel, 'href' => $href], $rel);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment