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

Breadcrumb

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

function StrictUnifiedDiffOutputBuilder::getDiff

Overrides DiffOutputBuilderInterface::getDiff

File

vendor/sebastian/diff/src/Output/StrictUnifiedDiffOutputBuilder.php, line 93

Class

StrictUnifiedDiffOutputBuilder
Strict Unified diff output builder.

Namespace

SebastianBergmann\Diff\Output

Code

public function getDiff(array $diff) : string {
    if (0 === count($diff)) {
        return '';
    }
    $this->changed = false;
    $buffer = fopen('php://memory', 'r+b');
    fwrite($buffer, $this->header);
    $this->writeDiffHunks($buffer, $diff);
    if (!$this->changed) {
        fclose($buffer);
        return '';
    }
    $diff = stream_get_contents($buffer, -1, 0);
    fclose($buffer);
    // If the last char is not a linebreak: add it.
    // This might happen when both the `from` and `to` do not have a trailing linebreak
    $last = substr($diff, -1);
    return "\n" !== $last && "\r" !== $last ? $diff . "\n" : $diff;
}
RSS feed
Powered by Drupal