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

Breadcrumb

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

function LogicalNot::negate

1 call to LogicalNot::negate()
LogicalNot::transformString in vendor/phpunit/phpunit/src/Framework/Constraint/Operator/LogicalNot.php
Applies additional transformation to strings returned by toString() or failureDescription().

File

vendor/phpunit/phpunit/src/Framework/Constraint/Operator/LogicalNot.php, line 24

Class

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

Namespace

PHPUnit\Framework\Constraint

Code

public static function negate(string $string) : string {
    $positives = [
        'contains ',
        'exists',
        'has ',
        'is ',
        'are ',
        'matches ',
        'starts with ',
        'ends with ',
        'reference ',
        'not not ',
    ];
    $negatives = [
        'does not contain ',
        'does not exist',
        'does not have ',
        'is not ',
        'are not ',
        'does not match ',
        'starts not with ',
        'ends not with ',
        'don\'t reference ',
        'not ',
    ];
    preg_match('/(\'[\\w\\W]*\')([\\w\\W]*)("[\\w\\W]*")/i', $string, $matches);
    if (count($matches) === 0) {
        preg_match('/(\'[\\w\\W]*\')([\\w\\W]*)(\'[\\w\\W]*\')/i', $string, $matches);
    }
    $positives = array_map(static fn(string $s) => '/\\b' . preg_quote($s, '/') . '/', $positives);
    if (count($matches) > 0) {
        $nonInput = $matches[2];
        $negatedString = preg_replace('/' . preg_quote($nonInput, '/') . '/', preg_replace($positives, $negatives, $nonInput), $string);
    }
    else {
        $negatedString = preg_replace($positives, $negatives, $string);
    }
    return $negatedString;
}
RSS feed
Powered by Drupal