Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. StringContains.php

function StringContains::matches

Evaluates the constraint for parameter $other. Returns true if the constraint is met, false otherwise.

Overrides Constraint::matches

File

vendor/phpunit/phpunit/src/Framework/Constraint/String/StringContains.php, line 83

Class

StringContains
@no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit

Namespace

PHPUnit\Framework\Constraint

Code

protected function matches(mixed $other) : bool {
    $haystack = $other;
    if ('' === $this->needle) {
        return true;
    }
    if (!is_string($haystack)) {
        return false;
    }
    if ($this->ignoreLineEndings) {
        $haystack = $this->normalizeLineEndings($haystack);
    }
    if ($this->ignoreCase) {
        
        /*
         * We must use the multibyte-safe version, so we can accurately compare non-latin uppercase characters with
         * their lowercase equivalents.
         */
        return mb_stripos($haystack, $this->needle, 0, 'UTF-8') !== false;
    }
    
    /*
     * Use the non-multibyte safe functions to see if the string is contained in $other.
     *
     * This function is very fast, and we don't care about the character position in the string.
     *
     * Additionally, we want this method to be binary safe, so we can check if some binary data is in other binary
     * data.
     */
    return str_contains($haystack, $this->needle);
}
RSS feed
Powered by Drupal