Skip to content

Commit 177146e

Browse files
committed
Rename Diff to Differ
Signed-off-by: Jack Cherng <jfcherng@gmail.com>
1 parent 0a30b27 commit 177146e

File tree

11 files changed

+70
-69
lines changed

11 files changed

+70
-69
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ See [example/demo.php](https://github.com/jfcherng/php-diff/blob/master/example/
3939

4040
include __DIR__ . '/vendor/autoload.php';
4141

42-
use Jfcherng\Diff\Diff;
42+
use Jfcherng\Diff\Differ;
4343
use Jfcherng\Diff\DiffHelper;
4444
use Jfcherng\Diff\Factory\RendererFactory;
4545

@@ -53,7 +53,7 @@ $new = 'And this is the new one.';
5353
$template = 'Unified';
5454

5555
// the Diff class options
56-
$diffOptions = [
56+
$differOptions = [
5757
// show how many neighbor lines
5858
'context' => 3,
5959
// ignore case difference
@@ -82,16 +82,16 @@ $templateOptions = [
8282
];
8383

8484
// one-line simply compare two files
85-
$result = DiffHelper::calculateFiles($oldFile, $newFile, $diffOptions, $templateOptions);
85+
$result = DiffHelper::calculateFiles($oldFile, $newFile, $differOptions, $templateOptions);
8686
// one-line simply compare two strings
87-
$result = DiffHelper::calculate($old, $new, $template, $diffOptions, $templateOptions);
87+
$result = DiffHelper::calculate($old, $new, $template, $differOptions, $templateOptions);
8888
// or even shorter if you are happy with default options
8989
$result = DiffHelper::calculate($old, $new, $template);
9090

9191
// custom usage
92-
$diff = new Diff(explode("\n", $old), explode("\n", $new), $diffOptions);
92+
$differ = new Differ(explode("\n", $old), explode("\n", $new), $differOptions);
9393
$renderer = RendererFactory::make($template, $templateOptions); // or your own renderers
94-
$result = $renderer->render($diff);
94+
$result = $renderer->render($differ);
9595
```
9696

9797

UPGRADING/UPGRADING_v6.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
## Upgrading to v6
22

3-
- Now `Renderer` has `::render()` API, but a `Diff` does not.
3+
- `Diff` has been renamed to `Differ`.
4+
- Now a `Renderer` has `render()` API, but a `Differ` does not.
45
If you are only using the `DiffHelper`, there should be nothing changed for you.
56
But if you combine those classes by yourself, it should be wrote like below.
67

78
```php
8-
use Jfcherng\Diff\Diff;
9+
use Jfcherng\Diff\Differ;
910
use Jfcherng\Diff\Factory\RendererFactory;
1011

11-
$diff = new Diff(explode("\n", $old), explode("\n", $new), $diffOptions);
12+
$differ = new Differ(explode("\n", $old), explode("\n", $new), $diffOptions);
1213
$renderer = RendererFactory::make($template, $templateOptions);
13-
$result = $renderer->render($diff); // <-- this has been changed
14+
$result = $renderer->render($differ); // <-- this has been changed
1415
```

src/DiffHelper.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public static function getStyleSheet(): string
116116
* @param string|string[] $old the old string (or array of lines)
117117
* @param string|string[] $new the new string (or array of lines)
118118
* @param string $template the template name
119-
* @param array $diffOptions the options for Diff object
119+
* @param array $differOptions the options for Differ object
120120
* @param array $templateOptions the options for template object
121121
*
122122
* @return string the rendered differences
@@ -125,7 +125,7 @@ public static function calculate(
125125
$old,
126126
$new,
127127
string $template = 'Unified',
128-
array $diffOptions = [],
128+
array $differOptions = [],
129129
array $templateOptions = []
130130
): string {
131131
// always convert into array form
@@ -135,9 +135,9 @@ public static function calculate(
135135
return RendererFactory::getInstance($template)
136136
->setOptions($templateOptions)
137137
->render(
138-
Diff::getInstance()
138+
Differ::getInstance()
139139
->setOldNew($old, $new)
140-
->setOptions($diffOptions)
140+
->setOptions($differOptions)
141141
);
142142
}
143143

@@ -147,7 +147,7 @@ public static function calculate(
147147
* @param string $old the path of the old file
148148
* @param string $new the path of the new file
149149
* @param string $template the template name
150-
* @param array $diffOptions the options for Diff object
150+
* @param array $differOptions the options for Differ object
151151
* @param array $templateOptions the options for template object
152152
*
153153
* @throws \LogicException path is a directory
@@ -159,7 +159,7 @@ public static function calculateFiles(
159159
string $old,
160160
string $new,
161161
string $template = 'Unified',
162-
array $diffOptions = [],
162+
array $differOptions = [],
163163
array $templateOptions = []
164164
): string {
165165
// we want to leave the line-ending problem to static::calculate()
@@ -172,7 +172,7 @@ public static function calculateFiles(
172172
$oldFile->fread($oldFile->getSize()),
173173
$newFile->fread($newFile->getSize()),
174174
$template,
175-
$diffOptions,
175+
$differOptions,
176176
$templateOptions
177177
);
178178
}

src/Diff.php renamed to src/Differ.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* @see http://github.com/chrisboulton/php-diff
1717
*/
18-
final class Diff
18+
final class Differ
1919
{
2020
/**
2121
* @var array cached properties and their default values
@@ -61,7 +61,7 @@ final class Diff
6161
private $groupedCodes = [];
6262

6363
/**
64-
* @var array associative array of the default options available for the diff class and their default value
64+
* @var array associative array of the default options available for the Differ class and their default value
6565
*/
6666
private static $defaultOptions = [
6767
// show how many neighbor lines
@@ -218,7 +218,7 @@ public static function getInstance(): self
218218
* Generate a list of the compiled and grouped opcodes for the differences between the
219219
* two strings. Generally called by the renderer, this class instantiates the sequence
220220
* matcher and performs the actual diff generation and return an array of the opcodes
221-
* for it. Once generated, the results are cached in the diff class instance.
221+
* for it. Once generated, the results are cached in the Differ class instance.
222222
*
223223
* @return array[] array of the grouped opcodes for the generated diff
224224
*/

src/Renderer/AbstractRenderer.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Jfcherng\Diff\Renderer;
66

7-
use Jfcherng\Diff\Diff;
7+
use Jfcherng\Diff\Differ;
88
use Jfcherng\Diff\Utility\Language;
99

1010
/**
@@ -26,9 +26,9 @@ abstract class AbstractRenderer implements RendererInterface
2626
const IS_HTML_TEMPLATE = true;
2727

2828
/**
29-
* @var Diff the instance of the diff class that this renderer is generating the rendered diff for
29+
* @var Differ the instance of the Differ class that this renderer is generating the rendered diff for
3030
*/
31-
protected $diff;
31+
protected $differ;
3232

3333
/**
3434
* @var Language the language translation object
@@ -73,15 +73,15 @@ public function __construct(array $options = [])
7373
}
7474

7575
/**
76-
* Set the diff object.
76+
* Set the Differ object.
7777
*
78-
* @param Diff $diff the diff object
78+
* @param Differ $differ the Differ object
7979
*
8080
* @return self
8181
*/
82-
public function setDiff(Diff $diff): self
82+
public function setDiff(Differ $differ): self
8383
{
84-
$this->diff = $diff;
84+
$this->differ = $differ;
8585

8686
return $this;
8787
}
@@ -107,13 +107,13 @@ public function setOptions(array $options): self
107107
}
108108

109109
/**
110-
* Get the diff object.
110+
* Get the Differ object.
111111
*
112-
* @return Diff the diff object
112+
* @return Differ the Differ object
113113
*/
114-
public function getDiff(): Diff
114+
public function getDiffer(): Differ
115115
{
116-
return $this->diff;
116+
return $this->differ;
117117
}
118118

119119
/**
@@ -139,12 +139,12 @@ public static function getIdenticalResult(): string
139139
/**
140140
* {@inheritdoc}
141141
*/
142-
public function render(Diff $diff): string
142+
public function render(Differ $differ): string
143143
{
144-
$this->diff = $diff->finalize();
144+
$this->differ = $differ->finalize();
145145

146146
// the "no difference" situation may happen frequently
147-
return $this->diff->getOldNewComparison() === 0
147+
return $this->differ->getOldNewComparison() === 0
148148
? static::getIdenticalResult()
149149
: $this->renderWoker();
150150
}

src/Renderer/Html/AbstractHtml.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ public function getChanges(): array
4242
{
4343
$lineRenderer = LineRendererFactory::make(
4444
$this->options['detailLevel'],
45-
$this->diff->getOptions(),
45+
$this->differ->getOptions(),
4646
$this->options
4747
);
4848

4949
// As we'll be modifying old & new to include our change markers,
5050
// we need to get the contents and store them here. That way
5151
// we're not going to destroy the original data
52-
$old = $this->diff->getOld();
53-
$new = $this->diff->getNew();
52+
$old = $this->differ->getOld();
53+
$new = $this->differ->getNew();
5454

5555
$changes = [];
5656

57-
foreach ($this->diff->getGroupedOpcodes() as $opcodes) {
57+
foreach ($this->differ->getGroupedOpcodes() as $opcodes) {
5858
$blocks = [];
5959
$lastTag = SequenceMatcher::OP_NOP;
6060
$lastBlock = 0;

src/Renderer/Html/LineRenderer/AbstractLineRenderer.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ abstract class AbstractLineRenderer implements LineRendererInterface
1717
protected $sequenceMatcher;
1818

1919
/**
20-
* @var array the diff options
20+
* @var array the differ options
2121
*/
22-
protected $diffOptions = [];
22+
protected $differOptions = [];
2323

2424
/**
2525
* @var array the template options
@@ -29,29 +29,29 @@ abstract class AbstractLineRenderer implements LineRendererInterface
2929
/**
3030
* The constructor.
3131
*
32-
* @param array $diffOptions the diff options
32+
* @param array $differOptions the differ options
3333
* @param array $templateOptions the template options
3434
*/
35-
public function __construct(array $diffOptions, array $templateOptions)
35+
public function __construct(array $differOptions, array $templateOptions)
3636
{
3737
$this->sequenceMatcher = new SequenceMatcher([], []);
3838

3939
$this
40-
->setDiffOptions($diffOptions)
40+
->setDifferOptions($differOptions)
4141
->setTemplateOptions($templateOptions);
4242
}
4343

4444
/**
45-
* Set the diff options.
45+
* Set the differ options.
4646
*
47-
* @param array $diffOptions the diff options
47+
* @param array $differOptions the differ options
4848
*
4949
* @return self
5050
*/
51-
public function setDiffOptions(array $diffOptions): self
51+
public function setDifferOptions(array $differOptions): self
5252
{
53-
$this->diffOptions = $diffOptions;
54-
$this->sequenceMatcher->setOptions($diffOptions);
53+
$this->differOptions = $differOptions;
54+
$this->sequenceMatcher->setOptions($differOptions);
5555

5656
return $this;
5757
}
@@ -71,13 +71,13 @@ public function setTemplateOptions(array $templateOptions): self
7171
}
7272

7373
/**
74-
* Gets the diff options.
74+
* Gets the differ options.
7575
*
76-
* @return array the diff options
76+
* @return array the differ options
7777
*/
78-
public function getDiffOptions(): array
78+
public function getDifferOptions(): array
7979
{
80-
return $this->diffOptions;
80+
return $this->differOptions;
8181
}
8282

8383
/**

src/Renderer/RendererInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44

55
namespace Jfcherng\Diff\Renderer;
66

7-
use Jfcherng\Diff\Diff;
7+
use Jfcherng\Diff\Differ;
88

99
/**
1010
* Renderer Interface.
1111
*/
1212
interface RendererInterface
1313
{
1414
/**
15-
* Render and return diff.
15+
* Render the differ and return the result.
1616
*
17-
* @param Diff $diff the diff object to be rendered
17+
* @param Differ $differ the Differ object to be rendered
1818
*
1919
* @return string
2020
*/
21-
public function render(Diff $diff): string;
21+
public function render(Differ $differ): string;
2222
}

src/Renderer/Text/Context.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function renderWoker(): string
3838
{
3939
$ret = '';
4040

41-
foreach ($this->diff->getGroupedOpcodes() as $opcodes) {
41+
foreach ($this->differ->getGroupedOpcodes() as $opcodes) {
4242
$lastItem = \count($opcodes) - 1;
4343

4444
$i1 = $opcodes[0][1];
@@ -92,7 +92,7 @@ protected function renderBlockOld(array $opcodes): string
9292

9393
$ret .= $this->renderContext(
9494
self::TAG_MAP[$tag],
95-
$this->diff->getOld($i1, $i2)
95+
$this->differ->getOld($i1, $i2)
9696
);
9797
}
9898

@@ -117,7 +117,7 @@ protected function renderBlockNew(array $opcodes): string
117117

118118
$ret .= $this->renderContext(
119119
self::TAG_MAP[$tag],
120-
$this->diff->getNew($j1, $j2)
120+
$this->differ->getNew($j1, $j2)
121121
);
122122
}
123123

src/Renderer/Text/Unified.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function renderWoker(): string
2828
{
2929
$ret = '';
3030

31-
foreach ($this->diff->getGroupedOpcodes() as $opcodes) {
31+
foreach ($this->differ->getGroupedOpcodes() as $opcodes) {
3232
$lastItem = \count($opcodes) - 1;
3333

3434
$i1 = $opcodes[0][1];
@@ -44,17 +44,17 @@ protected function renderWoker(): string
4444

4545
foreach ($opcodes as [$tag, $i1, $i2, $j1, $j2]) {
4646
if ($tag === SequenceMatcher::OP_EQ) {
47-
$ret .= $this->renderContext(' ', $this->diff->getOld($i1, $i2));
47+
$ret .= $this->renderContext(' ', $this->differ->getOld($i1, $i2));
4848

4949
continue;
5050
}
5151

5252
if ($tag & (SequenceMatcher::OP_REP | SequenceMatcher::OP_DEL)) {
53-
$ret .= $this->renderContext('-', $this->diff->getOld($i1, $i2));
53+
$ret .= $this->renderContext('-', $this->differ->getOld($i1, $i2));
5454
}
5555

5656
if ($tag & (SequenceMatcher::OP_REP | SequenceMatcher::OP_INS)) {
57-
$ret .= $this->renderContext('+', $this->diff->getNew($j1, $j2));
57+
$ret .= $this->renderContext('+', $this->differ->getNew($j1, $j2));
5858
}
5959
}
6060
}

0 commit comments

Comments
 (0)