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

Breadcrumb

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

function Differ::detectUnmatchedLineEndings

1 call to Differ::detectUnmatchedLineEndings()
Differ::diffToArray in vendor/sebastian/diff/src/Differ.php

File

vendor/sebastian/diff/src/Differ.php, line 139

Class

Differ

Namespace

SebastianBergmann\Diff

Code

private function detectUnmatchedLineEndings(array $diff) : bool {
    $newLineBreaks = [
        '' => true,
    ];
    $oldLineBreaks = [
        '' => true,
    ];
    foreach ($diff as $entry) {
        if (self::OLD === $entry[1]) {
            $ln = $this->getLinebreak($entry[0]);
            $oldLineBreaks[$ln] = true;
            $newLineBreaks[$ln] = true;
        }
        elseif (self::ADDED === $entry[1]) {
            $newLineBreaks[$this->getLinebreak($entry[0])] = true;
        }
        elseif (self::REMOVED === $entry[1]) {
            $oldLineBreaks[$this->getLinebreak($entry[0])] = true;
        }
    }
    // if either input or output is a single line without breaks than no warning should be raised
    if ([
        '' => true,
    ] === $newLineBreaks || [
        '' => true,
    ] === $oldLineBreaks) {
        return false;
    }
    // two-way compare
    foreach ($newLineBreaks as $break => $set) {
        if (!isset($oldLineBreaks[$break])) {
            return true;
        }
    }
    foreach ($oldLineBreaks as $break => $set) {
        if (!isset($newLineBreaks[$break])) {
            return true;
        }
    }
    return false;
}
RSS feed
Powered by Drupal