Commit 07f01bcf by Alexander Makarov

Used substr_compare instead of substr when we don't care about result

parent 5c767e5d
......@@ -170,7 +170,7 @@ class PhpDocController extends Controller
$namespaceLine = '';
$contentAfterNamespace = false;
foreach($lines as $i => $line) {
if (substr(trim($line), 0, 9) === 'namespace') {
if (substr_compare(trim($line), 'namespace', 0, 9) === 0) {
$namespace = $i;
$namespaceLine = trim($line);
} elseif ($namespace !== false && trim($line) !== '') {
......@@ -275,13 +275,13 @@ class PhpDocController extends Controller
// TODO move these checks to different action
$lines = explode("\n", $newDoc);
if (trim($lines[1]) == '*' || substr(trim($lines[1]), 0, 3) == '* @') {
if (trim($lines[1]) == '*' || substr_compare(trim($lines[1]), '* @', 0, 3) === 0) {
$this->stderr("[WARN] Class $className has no short description.\n", Console::FG_YELLOW, Console::BOLD);
}
foreach ($lines as $line) {
if (substr(trim($line), 0, 9) == '* @since ') {
if (substr_compare(trim($line), '* @since ', 0, 9) === 0) {
$seenSince = true;
} elseif (substr(trim($line), 0, 10) == '* @author ') {
} elseif (substr_compare(trim($line), '* @author ', 0, 10) === 0) {
$seenAuthor = true;
}
}
......@@ -350,13 +350,13 @@ class PhpDocController extends Controller
$propertyPart = false;
$propertyPosition = false;
foreach ($lines as $i => $line) {
if (substr(trim($line), 0, 12) == '* @property ') {
if (substr_compare(trim($line), '* @property ', 0, 12) === 0) {
$propertyPart = true;
} elseif ($propertyPart && trim($line) == '*') {
$propertyPosition = $i;
$propertyPart = false;
}
if (substr(trim($line), 0, 10) == '* @author ' && $propertyPosition === false) {
if (substr_compare(trim($line), '* @author ', 0, 10) === 0 && $propertyPosition === false) {
$propertyPosition = $i - 1;
$propertyPart = false;
}
......
......@@ -46,7 +46,7 @@ class TypeDoc extends BaseDoc
}
}
}
if (substr($subjectName, -2, 2) == '()') {
if (substr_compare($subjectName, '()', -2, 2) === 0) {
return null;
}
if ($this->properties === null) {
......
......@@ -72,7 +72,7 @@ abstract class BaseRenderer extends Component
foreach ($types as $type) {
$postfix = '';
if (!is_object($type)) {
if (substr($type, -2, 2) == '[]') {
if (substr_compare($type, '[]', -2, 2) === 0) {
$postfix = '[]';
$type = substr($type, 0, -2);
}
......
......@@ -23,7 +23,7 @@ if (empty($see)) {
} else {
echo '<p>See also:</p><ul>';
foreach ($see as $ref) {
if (substr($ref, -1, 1) != '>') {
if (substr_compare($ref, '>', -1, 1)) {
$ref .= '.';
}
echo "<li>$ref</li>";
......
......@@ -349,7 +349,7 @@ class OAuth1 extends BaseOAuth
$headerParams[] = 'realm="' . rawurlencode($realm) . '"';
}
foreach ($params as $key => $value) {
if (substr($key, 0, 5) != 'oauth') {
if (substr_compare($key, 'oauth', 0, 5)) {
continue;
}
$headerParams[] = rawurlencode($key) . '="' . rawurlencode($value) . '"';
......
......@@ -761,7 +761,7 @@ class OpenId extends BaseClient implements ClientInterface
} else {
// 'ax' prefix is either undefined, or points to another extension, so we search for another prefix
foreach ($this->data as $key => $value) {
if (substr($key, 0, strlen('openid_ns_')) == 'openid_ns_' && $value == 'http://openid.net/srv/ax/1.0') {
if (substr_compare($key, 'openid_ns_', 0, 10) === 0 && $value == 'http://openid.net/srv/ax/1.0') {
$alias = substr($key, strlen('openid_ns_'));
break;
}
......@@ -775,7 +775,7 @@ class OpenId extends BaseClient implements ClientInterface
$attributes = [];
foreach ($this->data as $key => $value) {
$keyMatch = 'openid_' . $alias . '_value_';
if (substr($key, 0, strlen($keyMatch)) != $keyMatch) {
if (substr_compare($key, $keyMatch, 0, strlen($keyMatch))) {
continue;
}
$key = substr($key, strlen($keyMatch));
......@@ -802,7 +802,7 @@ class OpenId extends BaseClient implements ClientInterface
$sregToAx = array_flip($this->axToSregMap);
foreach ($this->data as $key => $value) {
$keyMatch = 'openid_sreg_';
if (substr($key, 0, strlen($keyMatch)) != $keyMatch) {
if (substr_compare($key, $keyMatch, 0, strlen($keyMatch))) {
continue;
}
$key = substr($key, strlen($keyMatch));
......
......@@ -478,7 +478,7 @@ class Generator extends \yii\gii\Generator
if ($this->isReservedKeyword($this->modelClass)) {
$this->addError('modelClass', 'Class name cannot be a reserved PHP keyword.');
}
if (substr($this->tableName, -1) !== '*' && $this->modelClass == '') {
if (substr_compare($this->tableName, '*', -1) && $this->modelClass == '') {
$this->addError('modelClass', 'Model Class cannot be blank if table name does not end with asterisk.');
}
}
......
......@@ -146,7 +146,7 @@ EOD;
if (strpos($this->moduleClass, '\\') === false || Yii::getAlias('@' . str_replace('\\', '/', $this->moduleClass), false) === false) {
$this->addError('moduleClass', 'Module class must be properly namespaced.');
}
if (substr($this->moduleClass, -1, 1) == '\\') {
if (substr_compare($this->moduleClass, '\\', -1, 1) === 0) {
$this->addError('moduleClass', 'Module class name must not be empty. Please enter a fully qualified class name. e.g. "app\\modules\\admin\\Module".');
}
}
......
......@@ -266,7 +266,7 @@ class Generator extends \yii\gii\Generator
if ($this->isReservedKeyword($this->modelClass)) {
$this->addError('modelClass', 'Class name cannot be a reserved PHP keyword.');
}
if (substr($this->indexName, -1) !== '*' && $this->modelClass == '') {
if (substr_compare($this->indexName, '*', -1) && $this->modelClass == '') {
$this->addError('modelClass', 'Model Class cannot be blank if table name does not end with asterisk.');
}
}
......
......@@ -333,7 +333,7 @@ class MessageController extends Controller
ksort($translated);
foreach ($translated as $message => $translation) {
if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeUnused) {
if (substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') {
if (substr_compare($translation, '@@', 0, 2) === 0 && substr_compare($translation, '@@', -2) === 0) {
$todo[$message] = $translation;
} else {
$todo[$message] = '@@' . $translation . '@@';
......
......@@ -63,7 +63,7 @@ class CheckboxColumn extends Column
if (empty($this->name)) {
throw new InvalidConfigException('The "name" property must be set.');
}
if (substr($this->name, -2) !== '[]') {
if (substr_compare($this->name, '[]', -2)) {
$this->name .= '[]';
}
}
......
......@@ -803,7 +803,7 @@ class BaseHtml
$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($name, -2) === '[]') {
if (substr_compare($name, '[]', -2) === 0) {
$name = substr($name, 0, -2);
}
$hidden = static::hiddenInput($name, $options['unselect']);
......
......@@ -238,7 +238,7 @@ class UrlManager extends Component
$suffix = (string) $this->suffix;
if ($suffix !== '' && $pathInfo !== '') {
$n = strlen($this->suffix);
if (substr($pathInfo, -$n) === $this->suffix) {
if (substr_compare($pathInfo, $this->suffix, -$n) === 0) {
$pathInfo = substr($pathInfo, 0, -$n);
if ($pathInfo === '') {
// suffix alone is not allowed
......
......@@ -215,7 +215,7 @@ class UrlRule extends Object implements UrlRuleInterface
$suffix = (string) ($this->suffix === null ? $manager->suffix : $this->suffix);
if ($suffix !== '' && $pathInfo !== '') {
$n = strlen($suffix);
if (substr($pathInfo, -$n) === $suffix) {
if (substr_compare($pathInfo, $suffix, -$n) === 0) {
$pathInfo = substr($pathInfo, 0, -$n);
if ($pathInfo === '') {
// suffix alone is not allowed
......
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