Skip to content

Merge development into master #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ composer.phar
# composer.lock

### Eclipse ###
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
Expand All @@ -29,14 +27,6 @@ local.properties
# Locally stored "Eclipse launch configurations"
*.launch

# PyDev specific (Python IDE for Eclipse)
*.pydevproject

# CDT-specific (C/C++ Development Tooling)
.cproject

# CDT- autotools
.autotools

# Java annotation processor (APT)
.factorypath
Expand Down Expand Up @@ -79,31 +69,7 @@ local.properties

.sts4-cache/

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.gitignore.io/api/windows,eclipse,composer
/composer.lock
18 changes: 13 additions & 5 deletions lib/jblond/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

namespace jblond;

use InvalidArgumentException;
use jblond\Diff\Renderer\Html\Inline;
use jblond\Diff\Renderer\Html\SideBySide;
use jblond\Diff\Renderer\Html\Unified as UnifiedHtml;
use jblond\Diff\Renderer\Text\Context;
use jblond\Diff\Renderer\Text\Unified;
use jblond\Diff\SequenceMatcher;
use OutOfRangeException;

/**
* Diff
Expand Down Expand Up @@ -126,7 +133,8 @@ public function getNew(): array
/**
* Render a diff-view using a rendering class and get its results.
*
* @param object $renderer An instance of the rendering object, used for generating the diff-view.
* @param object|Context|Unified|UnifiedHtml|Inline|SideBySide $renderer An instance of the rendering object,
* used for generating the diff-view.
*
* @return mixed The generated diff-view. The type of the return value depends on the applied rendereder.
*/
Expand All @@ -152,14 +160,14 @@ public function render(object $renderer)
* @param int|null $end The last element of the range to get.
* If not supplied, only the element at start will be returned.
*
* @throws \OutOfRangeException When the value of start or end are invalid to define a range.
* @throws OutOfRangeException When the value of start or end are invalid to define a range.
*
* @return array Array containing all of the elements of the specified range.
*/
public function getArrayRange(array $array, int $start = 0, $end = null): array
{
if ($start < 0 || $end < 0 || $end < $start) {
throw new \OutOfRangeException('Start parameter must be lower than End parameter while both are positive!');
throw new OutOfRangeException('Start parameter must be lower than End parameter while both are positive!');
}

if ($start == 0 && $end === null) {
Expand Down Expand Up @@ -187,7 +195,7 @@ public function getArrayRange(array $array, int $start = 0, $end = null): array
*
* @param mixed $var Variable to get type from.
*
* @throws \InvalidArgumentException When the type isn't 'array' or 'string'.
* @throws InvalidArgumentException When the type isn't 'array' or 'string'.
*
* @return int Number indicating the type of the variable. 0 for array type and 1 for string type.
*/
Expand All @@ -199,7 +207,7 @@ public function getArgumentType($var): int
case (is_string($var)):
return 1;
default:
throw new \InvalidArgumentException('Invalid argument type! Argument must be of type array or string.');
throw new InvalidArgumentException('Invalid argument type! Argument must be of type array or string.');
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/Renderer/Html/HtmlArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class HtmlArray extends RendererAbstract
* This method is called by the renderers which extends this class.
*
* @param array $changes Contains the op-codes about the differences between "old and "new".
* @param object $htmlRenderer Renderer which extends this class.
* @param object|Inline|SideBySide|Unified $htmlRenderer Renderer which extends this class.
*
* @return string HTML representation of the differences.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/Renderer/Html/SideBySide.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function generateTableRowsReplace(array $changes): string
{
$html = '';

//TODO: Is below comparison result ever false?
// Is below comparison result ever false?
if (count($changes['base']['lines']) >= count($changes['changed']['lines'])) {
foreach ($changes['base']['lines'] as $lineNo => $line) {
$fromLine = $changes['base']['offset'] + $lineNo + 1;
Expand Down
31 changes: 15 additions & 16 deletions lib/jblond/Diff/Renderer/Text/Unified.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,21 @@ public function render(): string
"\n ",
$this->diff->getArrayRange($this->diff->getOld(), $i1, $i2)
) . "\n";
} else {
if ($tag == 'replace' || $tag == 'delete') {
$diff .= '-' .
implode(
"\n-",
$this->diff->getArrayRange($this->diff->getOld(), $i1, $i2)
) . "\n";
}

if ($tag == 'replace' || $tag == 'insert') {
$diff .= '+' .
implode(
"\n+",
$this->diff->getArrayRange($this->diff->getNew(), $j1, $j2)
) . "\n";
}
continue;
}
if ($tag == 'replace' || $tag == 'delete') {
$diff .= '-' .
implode(
"\n-",
$this->diff->getArrayRange($this->diff->getOld(), $i1, $i2)
) . "\n";
}
if ($tag == 'replace' || $tag == 'insert') {
$diff .= '+' .
implode(
"\n+",
$this->diff->getArrayRange($this->diff->getNew(), $j1, $j2)
) . "\n";
}
}
}
Expand Down