Verified Commit e5ce10b4 authored by quietone's avatar quietone
Browse files

Issue #3324560 by alexpott, mstrelan, dimitriskr, xjm, longwave, catch:...

Issue #3324560 by alexpott, mstrelan, dimitriskr, xjm, longwave, catch: Replace strpos/substr with str_starts_with() / str_contains() / str_ends_with()
parent 18cbe89f
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ public function addWords($words, $tag = '') {
        $this->_flushLine($tag);
        $word = mb_substr($word, 1);
      }
      assert(!strstr($word, "\n"));
      assert(!str_contains($word, "\n"));
      $this->group .= $word;
    }
  }
+2 −2
Original line number Diff line number Diff line
@@ -200,13 +200,13 @@ protected function match(array $condition, $value) {
          return array_search($value, $condition['value']) === FALSE;

        case 'STARTS_WITH':
          return strpos($value, $condition['value']) === 0;
          return str_starts_with($value, $condition['value']);

        case 'CONTAINS':
          return str_contains($value, $condition['value']);

        case 'ENDS_WITH':
          return substr($value, -strlen($condition['value'])) === (string) $condition['value'];
          return str_ends_with($value, $condition['value']);

        default:
          throw new QueryException('Invalid condition operator.');
+2 −2
Original line number Diff line number Diff line
@@ -203,7 +203,7 @@ protected function loadRecords() {
        case 'STARTS_WITH':
          $filter = static function ($name) use ($value, $prefix_length) {
            $id = substr($name, $prefix_length);
            return strpos($id, $value) === 0;
            return str_starts_with($id, $value);
          };
          break;

@@ -217,7 +217,7 @@ protected function loadRecords() {
        case 'ENDS_WITH':
          $filter = static function ($name) use ($value, $prefix_length) {
            $id = substr($name, $prefix_length);
            return strrpos($id, $value) === strlen($id) - strlen($value);
            return str_ends_with($id, $value);
          };
          break;
      }
+2 −2
Original line number Diff line number Diff line
@@ -116,13 +116,13 @@ protected function matchLabel($match, $match_operator, $label) {
        return array_search($label, $match) === FALSE;

      case 'STARTS_WITH':
        return strpos($label, $match) === 0;
        return str_starts_with($label, $match);

      case 'CONTAINS':
        return str_contains($label, $match);

      case 'ENDS_WITH':
        return mb_substr($label, -mb_strlen($match)) === (string) $match;
        return str_ends_with($label, $match);

      case 'IS NOT NULL':
        return TRUE;
+1 −1
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ public static function setLinkActiveClass($html_markup, $current_path, $is_front
    //    attribute.
    // 2. We are on the front page and a link has the special '<front>' value in
    //    its 'data-drupal-link-system-path' attribute.
    while (strpos($html_markup, $search_key_current_path, $offset) !== FALSE || ($is_front && strpos($html_markup, $search_key_front, $offset) !== FALSE)) {
    while (str_contains(substr($html_markup, $offset), $search_key_current_path) || ($is_front && str_contains(substr($html_markup, $offset), $search_key_front))) {
      $pos_current_path = strpos($html_markup, $search_key_current_path, $offset);
      // Only look for links with the special '<front>' system path if we are
      // actually on the front page.
Loading