mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-25 03:01:21 +08:00
Improved checks where substr_compare is used, replaced more substr + comapre cases with substr_compare
This commit is contained in:
@@ -156,7 +156,7 @@ class HelpController extends Controller
|
||||
if (is_dir($controllerPath)) {
|
||||
$files = scandir($controllerPath);
|
||||
foreach ($files as $file) {
|
||||
if (strcmp(substr($file, -14), 'Controller.php') === 0) {
|
||||
if (!empty($file) && substr_compare($file, 'Controller.php', -14) === 0) {
|
||||
$controllerClass = $module->controllerNamespace . '\\' . substr(basename($file), 0, -4);
|
||||
if ($this->validateControllerClass($controllerClass)) {
|
||||
$commands[] = $prefix . Inflector::camel2id(substr(basename($file), 0, -14));
|
||||
|
||||
@@ -331,7 +331,7 @@ class MessageController extends Controller
|
||||
ksort($existingMessages);
|
||||
foreach ($existingMessages as $message => $translation) {
|
||||
if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeUnused) {
|
||||
if (mb_strlen($translation, Yii::$app->charset) >= 2 && substr_compare($translation, '@@', 0, 2) === 0 && substr_compare($translation, '@@', -2) === 0) {
|
||||
if (!empty($translation) && substr_compare($translation, '@@', 0, 2) === 0 && substr_compare($translation, '@@', -2) === 0) {
|
||||
$todo[$message] = $translation;
|
||||
} else {
|
||||
$todo[$message] = '@@' . $translation . '@@';
|
||||
@@ -445,7 +445,7 @@ EOD;
|
||||
// add obsolete unused messages
|
||||
foreach ($existingMessages as $message => $translation) {
|
||||
if (!isset($merged[$category . chr(4) . $message]) && !isset($todos[$category . chr(4) . $message]) && !$removeUnused) {
|
||||
if (mb_strlen($translation, Yii::$app->charset) >= 2 && substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') {
|
||||
if (!empty($translation) && substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') {
|
||||
$todos[$category . chr(4) . $message] = $translation;
|
||||
} else {
|
||||
$todos[$category . chr(4) . $message] = '@@' . $translation . '@@';
|
||||
|
||||
@@ -797,13 +797,13 @@ class BaseHtml
|
||||
if (!array_key_exists('size', $options)) {
|
||||
$options['size'] = 4;
|
||||
}
|
||||
if (!empty($options['multiple']) && substr($name, -2) !== '[]') {
|
||||
if (!empty($options['multiple']) && !empty($name) && substr_compare($name, '[]', -2)) {
|
||||
$name .= '[]';
|
||||
}
|
||||
$options['name'] = $name;
|
||||
if (isset($options['unselect'])) {
|
||||
// add a hidden field so that if the list box has no option being selected, it still submits a value
|
||||
if (substr_compare($name, '[]', -2) === 0) {
|
||||
if (!empty($name) && substr_compare($name, '[]', -2) === 0) {
|
||||
$name = substr($name, 0, -2);
|
||||
}
|
||||
$hidden = static::hiddenInput($name, $options['unselect']);
|
||||
|
||||
@@ -107,7 +107,8 @@ class GettextMoFile extends GettextFile
|
||||
$id = $this->readString($fileHandle, $sourceLengths[$i], $sourceOffsets[$i]);
|
||||
$separatorPosition = strpos($id, chr(4));
|
||||
|
||||
if (($context && $separatorPosition !== false && substr($id, 0, $separatorPosition) === $context) ||
|
||||
|
||||
if (($context && $separatorPosition !== false && !empty($id) && substr_compare($id, $context, 0, $separatorPosition) === 0) ||
|
||||
(!$context && $separatorPosition === false)) {
|
||||
if ($separatorPosition !== false) {
|
||||
$id = substr($id, $separatorPosition+1);
|
||||
|
||||
@@ -390,7 +390,8 @@ class MessageFormatter extends Component
|
||||
return false;
|
||||
}
|
||||
$selector = trim($plural[$i++]);
|
||||
if ($i == 1 && substr($selector, 0, 7) == 'offset:') {
|
||||
|
||||
if ($i == 1 && !empty($selector) && substr_compare($selector, 'offset:', 0, 7) === 0) {
|
||||
$offset = (int) trim(mb_substr($selector, 7, ($pos = mb_strpos(str_replace(["\n", "\r", "\t"], ' ', $selector), ' ', 7)) - 7));
|
||||
$selector = trim(mb_substr($selector, $pos + 1));
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ abstract class Target extends Component
|
||||
|
||||
$matched = empty($categories);
|
||||
foreach ($categories as $category) {
|
||||
if ($message[2] === $category || substr($category, -1) === '*' && strpos($message[2], rtrim($category, '*')) === 0) {
|
||||
if ($message[2] === $category || !empty($category) && substr_compare($category, '*', -1) === 0 && strpos($message[2], rtrim($category, '*')) === 0) {
|
||||
$matched = true;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user