Skip to content

Commit 2277a98

Browse files
committed
Improve type docs and variable naming
Signed-off-by: Jack Cherng <[email protected]>
1 parent d212f41 commit 2277a98

14 files changed

+94
-81
lines changed

src/Differ.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public static function getInstance(): self
211211
* matcher and performs the actual diff generation and return an array of the opcodes
212212
* for it. Once generated, the results are cached in the Differ class instance.
213213
*
214-
* @return array[] array of the grouped opcodes for the generated diff
214+
* @return int[][][] array of the grouped opcodes for the generated diff
215215
*/
216216
public function getGroupedOpcodes(): array
217217
{

src/Renderer/AbstractRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ abstract protected function renderWorker(Differ $differ): string;
161161
/**
162162
* The real worker for self::renderArray().
163163
*
164-
* @param array $differArray the differ array
164+
* @param array[][] $differArray the differ array
165165
*/
166166
abstract protected function renderArrayWorker(array $differArray): string;
167167

src/Renderer/Html/AbstractHtml.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function getResultForIdenticalsDefault(): string
4949
*
5050
* @param Differ $differ the differ object
5151
*
52-
* @return array generated changes, suitable for presentation in HTML
52+
* @return array[][] generated changes, suitable for presentation in HTML
5353
*/
5454
public function getChanges(Differ $differ): array
5555
{
@@ -62,14 +62,14 @@ public function getChanges(Differ $differ): array
6262
$old = $differ->getOld();
6363
$new = $differ->getNew();
6464

65-
$hunks = [];
65+
$changes = [];
6666

67-
foreach ($differ->getGroupedOpcodes() as $opcodes) {
68-
$hunk = [];
67+
foreach ($differ->getGroupedOpcodes() as $hunk) {
68+
$change = [];
6969
$lastOp = SequenceMatcher::OP_NOP;
7070
$lastBlock = 0;
7171

72-
foreach ($opcodes as [$op, $i1, $i2, $j1, $j2]) {
72+
foreach ($hunk as [$op, $i1, $i2, $j1, $j2]) {
7373
// if there are same amount of lines replaced
7474
// we can render the inner detailed changes with corresponding lines
7575
if ($op === SequenceMatcher::OP_REP && $i2 - $i1 === $j2 - $j1) {
@@ -79,8 +79,8 @@ public function getChanges(Differ $differ): array
7979
}
8080

8181
if ($op !== $lastOp) {
82-
$hunk[] = $this->getDefaultBlock($op, $i1, $j1);
83-
$lastBlock = \count($hunk) - 1;
82+
$change[] = $this->getDefaultBlock($op, $i1, $j1);
83+
$lastBlock = \count($change) - 1;
8484
}
8585

8686
$lastOp = $op;
@@ -90,9 +90,9 @@ public function getChanges(Differ $differ): array
9090
// the old and the new may not be exactly the same
9191
// because of ignoreCase, ignoreWhitespace, etc
9292
$lines = \array_slice($old, $i1, $i2 - $i1);
93-
$hunk[$lastBlock]['old']['lines'] = $this->formatLines($lines);
93+
$change[$lastBlock]['old']['lines'] = $this->formatLines($lines);
9494
$lines = \array_slice($new, $j1, $j2 - $j1);
95-
$hunk[$lastBlock]['new']['lines'] = $this->formatLines($lines);
95+
$change[$lastBlock]['new']['lines'] = $this->formatLines($lines);
9696

9797
continue;
9898
}
@@ -106,7 +106,7 @@ public function getChanges(Differ $differ): array
106106
$lines
107107
);
108108

109-
$hunk[$lastBlock]['old']['lines'] = $lines;
109+
$change[$lastBlock]['old']['lines'] = $lines;
110110
}
111111

112112
if ($op & (SequenceMatcher::OP_REP | SequenceMatcher::OP_INS)) {
@@ -118,14 +118,14 @@ public function getChanges(Differ $differ): array
118118
$lines
119119
);
120120

121-
$hunk[$lastBlock]['new']['lines'] = $lines;
121+
$change[$lastBlock]['new']['lines'] = $lines;
122122
}
123123
}
124124

125-
$hunks[] = $hunk;
125+
$changes[] = $change;
126126
}
127127

128-
return $hunks;
128+
return $changes;
129129
}
130130

131131
/**
@@ -149,7 +149,7 @@ protected function renderArrayWorker(array $differArray): string
149149
/**
150150
* Render the array of changes.
151151
*
152-
* @param array $changes the changes
152+
* @param array[][] $changes the changes
153153
*
154154
* @todo rename typo to renderChanges() in v7
155155
*/
@@ -320,7 +320,7 @@ function (array $matches): string {
320320
*
321321
* Internally, we would like always int form for better performance.
322322
*
323-
* @param array $changes the changes
323+
* @param array[][] $changes the changes
324324
*/
325325
protected function ensureChangesUseIntTag(array &$changes): void
326326
{

src/Renderer/Html/Inline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected function renderTableSeparateBlock(): string
8282
/**
8383
* Renderer table hunks.
8484
*
85-
* @param array $hunks each hunk has many blocks
85+
* @param array[][] $hunks each hunk has many blocks
8686
*/
8787
protected function renderTableHunks(array $hunks): string
8888
{

src/Renderer/Html/Json.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function redererChanges(array $changes): string
5050
/**
5151
* Convert tags of changes to their string form for better readability.
5252
*
53-
* @param array $changes the changes
53+
* @param array[][] $changes the changes
5454
*/
5555
protected function convertTagToString(array &$changes): void
5656
{

src/Renderer/Html/LineRenderer/AbstractLineRenderer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ public function getRendererOptions(): array
9393
/**
9494
* Get the changed extent segments.
9595
*
96-
* @param array $old the old array
97-
* @param array $new the new array
96+
* @param string[] $old the old array
97+
* @param string[] $new the new array
9898
*
99-
* @return array the changed extent segments
99+
* @return int[][] the changed extent segments
100100
*/
101101
protected function getChangedExtentSegments(array $old, array $new): array
102102
{

src/Renderer/Html/LineRenderer/Char.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ final class Char extends AbstractLineRenderer
1818
*/
1919
public function render(MbString $mbOld, MbString $mbNew): LineRendererInterface
2020
{
21-
$opcodes = $this->getChangedExtentSegments($mbOld->toArray(), $mbNew->toArray());
21+
$hunk = $this->getChangedExtentSegments($mbOld->toArray(), $mbNew->toArray());
2222

23-
// reversely iterate opcodes
24-
foreach (ReverseIterator::fromArray($opcodes) as [$op, $i1, $i2, $j1, $j2]) {
23+
// reversely iterate hunk
24+
foreach (ReverseIterator::fromArray($hunk) as [$op, $i1, $i2, $j1, $j2]) {
2525
switch ($op) {
2626
case SequenceMatcher::OP_DEL:
2727
$mbOld->str_enclose_i(RendererConstant::HTML_CLOSURES, $i1, $i2 - $i1);

src/Renderer/Html/LineRenderer/Line.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function render(MbString $mbOld, MbString $mbNew): LineRendererInterface
4545
* @param MbString $mbOld the old megabytes line
4646
* @param MbString $mbNew the new megabytes line
4747
*
48-
* @return array Array containing the starting position (non-negative) and the ending position (negative)
48+
* @return int[] Array containing the starting position (non-negative) and the ending position (negative)
4949
* [0, 0] if two strings are the same
5050
*/
5151
protected function getChangedExtentRegion(MbString $mbOld, MbString $mbNew): array

src/Renderer/Html/LineRenderer/Word.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public function render(MbString $mbOld, MbString $mbNew): LineRendererInterface
2323
$oldWords = $mbOld->toArraySplit($splitRegex, -1, \PREG_SPLIT_DELIM_CAPTURE);
2424
$newWords = $mbNew->toArraySplit($splitRegex, -1, \PREG_SPLIT_DELIM_CAPTURE);
2525

26-
$opcodes = $this->getChangedExtentSegments($oldWords, $newWords);
26+
$hunk = $this->getChangedExtentSegments($oldWords, $newWords);
2727

28-
// reversely iterate opcodes
29-
foreach (ReverseIterator::fromArray($opcodes) as [$op, $i1, $i2, $j1, $j2]) {
28+
// reversely iterate hunk
29+
foreach (ReverseIterator::fromArray($hunk) as [$op, $i1, $i2, $j1, $j2]) {
3030
switch ($op) {
3131
case SequenceMatcher::OP_DEL:
3232
$oldWords[$i1] = RendererConstant::HTML_CLOSURES[0] . $oldWords[$i1];

src/Renderer/Html/SideBySide.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected function renderTableSeparateBlock(): string
7474
/**
7575
* Renderer table hunks.
7676
*
77-
* @param array $hunks each hunk has many blocks
77+
* @param array[][] $hunks each hunk has many blocks
7878
*/
7979
protected function renderTableHunks(array $hunks): string
8080
{

0 commit comments

Comments
 (0)