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