Skip to content

Commit 9d7136b

Browse files
authored
Merge pull request #25 from JBlond/development
Merge development into master
2 parents 0b4970c + 55a4eba commit 9d7136b

File tree

5 files changed

+30
-57
lines changed

5 files changed

+30
-57
lines changed

.gitignore

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ composer.phar
1111
# composer.lock
1212

1313
### Eclipse ###
14-
.metadata
1514
bin/
1615
tmp/
1716
*.tmp
1817
*.bak
19-
*.swp
2018
*~.nib
2119
local.properties
2220
.settings/
@@ -29,14 +27,6 @@ local.properties
2927
# Locally stored "Eclipse launch configurations"
3028
*.launch
3129

32-
# PyDev specific (Python IDE for Eclipse)
33-
*.pydevproject
34-
35-
# CDT-specific (C/C++ Development Tooling)
36-
.cproject
37-
38-
# CDT- autotools
39-
.autotools
4030

4131
# Java annotation processor (APT)
4232
.factorypath
@@ -79,31 +69,7 @@ local.properties
7969

8070
.sts4-cache/
8171

82-
### Windows ###
83-
# Windows thumbnail cache files
84-
Thumbs.db
85-
Thumbs.db:encryptable
86-
ehthumbs.db
87-
ehthumbs_vista.db
88-
89-
# Dump file
90-
*.stackdump
91-
92-
# Folder config file
93-
[Dd]esktop.ini
94-
95-
# Recycle Bin used on file shares
96-
$RECYCLE.BIN/
97-
98-
# Windows Installer files
99-
*.cab
100-
*.msi
101-
*.msix
102-
*.msm
103-
*.msp
10472

105-
# Windows shortcuts
106-
*.lnk
10773

10874
# End of https://www.gitignore.io/api/windows,eclipse,composer
10975
/composer.lock

lib/jblond/Diff.php

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

55
namespace jblond;
66

7+
use InvalidArgumentException;
8+
use jblond\Diff\Renderer\Html\Inline;
9+
use jblond\Diff\Renderer\Html\SideBySide;
10+
use jblond\Diff\Renderer\Html\Unified as UnifiedHtml;
11+
use jblond\Diff\Renderer\Text\Context;
12+
use jblond\Diff\Renderer\Text\Unified;
713
use jblond\Diff\SequenceMatcher;
14+
use OutOfRangeException;
815

916
/**
1017
* Diff
@@ -126,7 +133,8 @@ public function getNew(): array
126133
/**
127134
* Render a diff-view using a rendering class and get its results.
128135
*
129-
* @param object $renderer An instance of the rendering object, used for generating the diff-view.
136+
* @param object|Context|Unified|UnifiedHtml|Inline|SideBySide $renderer An instance of the rendering object,
137+
* used for generating the diff-view.
130138
*
131139
* @return mixed The generated diff-view. The type of the return value depends on the applied rendereder.
132140
*/
@@ -152,14 +160,14 @@ public function render(object $renderer)
152160
* @param int|null $end The last element of the range to get.
153161
* If not supplied, only the element at start will be returned.
154162
*
155-
* @throws \OutOfRangeException When the value of start or end are invalid to define a range.
163+
* @throws OutOfRangeException When the value of start or end are invalid to define a range.
156164
*
157165
* @return array Array containing all of the elements of the specified range.
158166
*/
159167
public function getArrayRange(array $array, int $start = 0, $end = null): array
160168
{
161169
if ($start < 0 || $end < 0 || $end < $start) {
162-
throw new \OutOfRangeException('Start parameter must be lower than End parameter while both are positive!');
170+
throw new OutOfRangeException('Start parameter must be lower than End parameter while both are positive!');
163171
}
164172

165173
if ($start == 0 && $end === null) {
@@ -187,7 +195,7 @@ public function getArrayRange(array $array, int $start = 0, $end = null): array
187195
*
188196
* @param mixed $var Variable to get type from.
189197
*
190-
* @throws \InvalidArgumentException When the type isn't 'array' or 'string'.
198+
* @throws InvalidArgumentException When the type isn't 'array' or 'string'.
191199
*
192200
* @return int Number indicating the type of the variable. 0 for array type and 1 for string type.
193201
*/
@@ -199,7 +207,7 @@ public function getArgumentType($var): int
199207
case (is_string($var)):
200208
return 1;
201209
default:
202-
throw new \InvalidArgumentException('Invalid argument type! Argument must be of type array or string.');
210+
throw new InvalidArgumentException('Invalid argument type! Argument must be of type array or string.');
203211
}
204212
}
205213

lib/jblond/Diff/Renderer/Html/HtmlArray.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class HtmlArray extends RendererAbstract
4545
* This method is called by the renderers which extends this class.
4646
*
4747
* @param array $changes Contains the op-codes about the differences between "old and "new".
48-
* @param object $htmlRenderer Renderer which extends this class.
48+
* @param object|Inline|SideBySide|Unified $htmlRenderer Renderer which extends this class.
4949
*
5050
* @return string HTML representation of the differences.
5151
*/

lib/jblond/Diff/Renderer/Html/SideBySide.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function generateTableRowsReplace(array $changes): string
166166
{
167167
$html = '';
168168

169-
//TODO: Is below comparison result ever false?
169+
// Is below comparison result ever false?
170170
if (count($changes['base']['lines']) >= count($changes['changed']['lines'])) {
171171
foreach ($changes['base']['lines'] as $lineNo => $line) {
172172
$fromLine = $changes['base']['offset'] + $lineNo + 1;

lib/jblond/Diff/Renderer/Text/Unified.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,21 @@ public function render(): string
5353
"\n ",
5454
$this->diff->getArrayRange($this->diff->getOld(), $i1, $i2)
5555
) . "\n";
56-
} else {
57-
if ($tag == 'replace' || $tag == 'delete') {
58-
$diff .= '-' .
59-
implode(
60-
"\n-",
61-
$this->diff->getArrayRange($this->diff->getOld(), $i1, $i2)
62-
) . "\n";
63-
}
64-
65-
if ($tag == 'replace' || $tag == 'insert') {
66-
$diff .= '+' .
67-
implode(
68-
"\n+",
69-
$this->diff->getArrayRange($this->diff->getNew(), $j1, $j2)
70-
) . "\n";
71-
}
56+
continue;
57+
}
58+
if ($tag == 'replace' || $tag == 'delete') {
59+
$diff .= '-' .
60+
implode(
61+
"\n-",
62+
$this->diff->getArrayRange($this->diff->getOld(), $i1, $i2)
63+
) . "\n";
64+
}
65+
if ($tag == 'replace' || $tag == 'insert') {
66+
$diff .= '+' .
67+
implode(
68+
"\n+",
69+
$this->diff->getArrayRange($this->diff->getNew(), $j1, $j2)
70+
) . "\n";
7271
}
7372
}
7473
}

0 commit comments

Comments
 (0)