Skip to content

Commit 6af04a1

Browse files
Simplify
1 parent 7da63ab commit 6af04a1

File tree

1 file changed

+7
-64
lines changed

1 file changed

+7
-64
lines changed

README.md

+7-64
Original file line numberDiff line numberDiff line change
@@ -46,73 +46,16 @@ The code above yields the output below:
4646
+bar
4747
```
4848

49-
There are three output builders available in this package:
49+
The `UnifiedDiffOutputBuilder` used in the example above generates output in "unified diff"
50+
format and is used by PHPUnit, for example.
5051

51-
#### UnifiedDiffOutputBuilder
52+
The `StrictUnifiedDiffOutputBuilder` generates output in "strict unified diff" format with
53+
hunks, similar to `diff -u` and compatible with `patch` or `git apply`.
5254

53-
This is default builder, which generates the output close to udiff and is used by PHPUnit.
55+
The `DiffOnlyOutputBuilder` generates output that only contains the lines that differ.
5456

55-
```php
56-
<?php
57-
58-
use SebastianBergmann\Diff\Differ;
59-
use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
60-
61-
$builder = new UnifiedDiffOutputBuilder(
62-
"--- Original\n+++ New\n", // custom header
63-
false // do not add line numbers to the diff
64-
);
65-
66-
$differ = new Differ($builder);
67-
print $differ->diff('foo', 'bar');
68-
```
69-
70-
#### StrictUnifiedDiffOutputBuilder
71-
72-
Generates (strict) Unified diff's (unidiffs) with hunks,
73-
similar to `diff -u` and compatible with `patch` and `git apply`.
74-
75-
```php
76-
<?php
77-
78-
use SebastianBergmann\Diff\Differ;
79-
use SebastianBergmann\Diff\Output\StrictUnifiedDiffOutputBuilder;
80-
81-
$builder = new StrictUnifiedDiffOutputBuilder([
82-
'collapseRanges' => true, // ranges of length one are rendered with the trailing `,1`
83-
'commonLineThreshold' => 6, // number of same lines before ending a new hunk and creating a new one (if needed)
84-
'contextLines' => 3, // like `diff: -u, -U NUM, --unified[=NUM]`, for patch/git apply compatibility best to keep at least @ 3
85-
'fromFile' => '',
86-
'fromFileDate' => null,
87-
'toFile' => '',
88-
'toFileDate' => null,
89-
]);
90-
91-
$differ = new Differ($builder);
92-
print $differ->diff('foo', 'bar');
93-
```
94-
95-
#### DiffOnlyOutputBuilder
96-
97-
Output only the lines that differ.
98-
99-
```php
100-
<?php
101-
102-
use SebastianBergmann\Diff\Differ;
103-
use SebastianBergmann\Diff\Output\DiffOnlyOutputBuilder;
104-
105-
$builder = new DiffOnlyOutputBuilder(
106-
"--- Original\n+++ New\n"
107-
);
108-
109-
$differ = new Differ($builder);
110-
print $differ->diff('foo', 'bar');
111-
```
112-
113-
#### DiffOutputBuilderInterface
114-
115-
You can pass any output builder to the `Differ` class as longs as it implements the `DiffOutputBuilderInterface`.
57+
If none of these three output builders match your use case then you can implement
58+
`DiffOutputBuilderInterface` to generate custom output.
11659

11760
#### Parsing diff
11861

0 commit comments

Comments
 (0)