PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.6
Kubio AI Page Builder v2.8.6
2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / vendor / sebastian / diff / src / Output / DiffOnlyOutputBuilder.php
kubio / vendor / sebastian / diff / src / Output Last commit date
AbstractChunkOutputBuilder.php 1 year ago DiffOnlyOutputBuilder.php 1 year ago DiffOutputBuilderInterface.php 1 year ago StrictUnifiedDiffOutputBuilder.php 1 year ago UnifiedDiffOutputBuilder.php 1 year ago
DiffOnlyOutputBuilder.php
73 lines
1 <?php declare(strict_types=1);
2 /*
3 * This file is part of sebastian/diff.
4 *
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10 namespace SebastianBergmann\Diff\Output;
11
12 use function fclose;
13 use function fopen;
14 use function fwrite;
15 use function stream_get_contents;
16 use function substr;
17 use SebastianBergmann\Diff\Differ;
18
19 /**
20 * Builds a diff string representation in a loose unified diff format
21 * listing only changes lines. Does not include line numbers.
22 */
23 final class DiffOnlyOutputBuilder implements DiffOutputBuilderInterface
24 {
25 /**
26 * @var string
27 */
28 private $header;
29
30 public function __construct(string $header = "--- Original\n+++ New\n")
31 {
32 $this->header = $header;
33 }
34
35 public function getDiff(array $diff): string
36 {
37 $buffer = fopen('php://memory', 'r+b');
38
39 if ('' !== $this->header) {
40 fwrite($buffer, $this->header);
41
42 if ("\n" !== substr($this->header, -1, 1)) {
43 fwrite($buffer, "\n");
44 }
45 }
46
47 foreach ($diff as $diffEntry) {
48 if ($diffEntry[1] === Differ::ADDED) {
49 fwrite($buffer, '+' . $diffEntry[0]);
50 } elseif ($diffEntry[1] === Differ::REMOVED) {
51 fwrite($buffer, '-' . $diffEntry[0]);
52 } elseif ($diffEntry[1] === Differ::DIFF_LINE_END_WARNING) {
53 fwrite($buffer, ' ' . $diffEntry[0]);
54
55 continue; // Warnings should not be tested for line break, it will always be there
56 } else { /* Not changed (old) 0 */
57 continue; // we didn't write the non changs line, so do not add a line break either
58 }
59
60 $lc = substr($diffEntry[0], -1);
61
62 if ($lc !== "\n" && $lc !== "\r") {
63 fwrite($buffer, "\n"); // \No newline at end of file
64 }
65 }
66
67 $diff = stream_get_contents($buffer, -1, 0);
68 fclose($buffer);
69
70 return $diff;
71 }
72 }
73