Skip to content

Many code fixes, optimazations, cleanup, refactoring and commenting. #21

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 26 commits into from
Jan 23, 2020
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9700db7
raise version number
JBlond Dec 3, 2019
4352698
Preperation for local developement.
DigiLive Dec 19, 2019
e6cd9e0
Code commenting.
DigiLive Dec 19, 2019
0d8c872
Code Optimization, cleanup, refactoring and commenting.
DigiLive Dec 19, 2019
122a72c
PHPUnit test added for diff-view renderers.
DigiLive Dec 19, 2019
0c5e1a4
HTML Unified Renderer added, Code optimization, cleanup and commenting.
DigiLive Dec 20, 2019
611dc21
PHPUnit test for HTML Unified Renderer added.
DigiLive Dec 20, 2019
71b63a1
Code cleanup, bumped required PHP version to >= 7.2 and updated readme.
DigiLive Dec 20, 2019
5e7ddf3
Code Style Fixes.
DigiLive Dec 28, 2019
6bc3f7c
Code Optimization, cleanup, refactoring and commenting.
DigiLive Jan 10, 2020
d1c724c
Code Fixes.
DigiLive Jan 10, 2020
42b1ace
valid html can have no white space before the first tag
JBlond Jan 10, 2020
7c75b07
PSR12.Files.DeclareStatement
JBlond Jan 10, 2020
2a01869
PSR12 fixes
JBlond Jan 10, 2020
6bfc5e7
Correct paths for composer run-script phpunit
JBlond Jan 10, 2020
ec0e0a6
ignore composer lock file
JBlond Jan 10, 2020
e227356
PSR12 fixes
DigiLive Jan 14, 2020
c984365
Code Optimization, cleanup, refactoring and commenting.
DigiLive Jan 14, 2020
3b2c367
Update PHPUnit tests
DigiLive Jan 14, 2020
795fe20
fix notation
JBlond Jan 14, 2020
c017af5
Code Optimization, cleanup, refactoring and commenting.
DigiLive Jan 15, 2020
3a1c258
Code reformatting and minor optimization, Typo fixes
DigiLive Jan 16, 2020
7f87ce3
Code reformatting and minor optimization, Typo fixes
DigiLive Jan 16, 2020
7748252
Code Optimization, cleanup, refactoring and commenting.
DigiLive Jan 22, 2020
f5f11a3
Merge branch 'DigiLive' of https://github.com/JBlond/php-diff into Di…
DigiLive Jan 22, 2020
78a1658
Code Fixes, Optimization, cleanup, refactoring and commenting.
DigiLive Jan 23, 2020
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
Prev Previous commit
Next Next commit
Code Optimization, cleanup, refactoring and commenting.
  • Loading branch information
DigiLive committed Jan 14, 2020
commit c984365c5f03ca3eef5bcd3668e89b8c6545df13
157 changes: 96 additions & 61 deletions lib/jblond/Diff/Renderer/Html/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,124 +19,159 @@
class Inline extends HtmlArray
{
/**
* Render a and return diff with changes between the two sequences
* displayed inline (under each other)
* Render a and return diff-view with changes between the two sequences displayed side by side. (under each other)
*
* @return string The generated inline diff.
* @return string The generated inline diff-view.
*/
public function render(): string
{
$changes = parent::render();

return parent::renderHtml($changes, $this);
}


/**
* Generates a string representation of a predefined table and its head with
* titles from options.
* Generates a string representation of the opening of a predefined table and its header with titles from options.
*
* @return string Html code representation of the table's header.
* @return string HTML code representation of a table's header.
*/
public function generateTableHeader(): string
{
$html = '<table class="Differences DifferencesInline">';
$html .= '<thead>';
$html .= '<tr>';
$html .= '<th>Old</th>';
$html .= '<th>New</th>';
$html .= '<th>Differences</th>';
$html .= '</tr>';
$html .= '</thead>';
return $html;
return <<<HTML
<table class="Differences DifferencesInline">
<thead>
<tr>
<th>{$this->options['title_a']}</th>
<th>{$this->options['title_b']}</th>
<th>Differences</th>
</tr>
</thead>
HTML;
}

/**
* Generates a string representation of one or more rows of a table of lines of text with no difference.
* Generates a string representation of table rows showing text with no difference.
*
* @param array $change Contains the op-codes about the changes between two blocks.
*
* @param array &$change Array with data about changes.
* @return string Html code representing one or more rows of text with no difference.
* @return string HTML code representing table rows showing text with no difference.
*/
public function generateTableRowsEqual(array &$change): string
public function generateTableRowsEqual(array $change): string
{
$html = "";
$html = '';

foreach ($change['base']['lines'] as $no => $line) {
$fromLine = $change['base']['offset'] + $no + 1;
$toLine = $change['changed']['offset'] + $no + 1;
$html .= '<tr>';
$html .= '<th>' . $fromLine . '</th>';
$html .= '<th>' . $toLine . '</th>';
$html .= '<td class="Left">' . $line . '</td>';
$html .= '</tr>';
$fromLine = $change['base']['offset'] + $no + 1;
$toLine = $change['changed']['offset'] + $no + 1;

$html .= <<<HTML
<tr>
<th>$fromLine</th>
<th>$toLine</th>
<td class="Left">$line</td>
</tr>
HTML;
}

return $html;
}

/**
* Generates a string representation of one or more rows of a table of lines, where new text was added.
* Generates a string representation of table rows showing added text.
*
* @param array &$change Array with data about changes.
* @return string Html code representing one or more rows of added text.
* @param array $change Contains the op-codes about the changes between two blocks of text.
*
* @return string HTML code representing table rows showing with added text.
*/
public function generateTableRowsInsert(array &$change): string
public function generateTableRowsInsert(array $change): string
{
$html = "";
$html = '';

foreach ($change['changed']['lines'] as $no => $line) {
$toLine = $change['changed']['offset'] + $no + 1;
$html .= '<tr>';
$html .= '<th>&#xA0;</th>';
$html .= '<th>' . $toLine . '</th>';
$html .= '<td class="Right"><ins>' . $line . '</ins>&#xA0;</td>';
$html .= '</tr>';

$html .= <<<HTML
<tr>
<th>&#xA0;</th>
<th>$toLine</th>
<td class="Right">
<ins>$line</ins>
&#xA0;
</td>
</tr>
HTML;
}

return $html;
}

/**
* Generates a string representation of one or more rows of a table of lines, where text was removed.
* Generates a string representation of table rows showing removed text.
*
* @param array $change Contains the op-codes about the changes between two blocks of text.
*
* @param array &$change Array with data about changes.
* @return string Html code representing one or more rows of removed text.
* @return string HTML code representing table rows showing removed text.
*/
public function generateTableRowsDelete(array &$change): string
public function generateTableRowsDelete(array $change): string
{
$html = "";
$html = '';

foreach ($change['base']['lines'] as $no => $line) {
$fromLine = $change['base']['offset'] + $no + 1;
$html .= '<tr>';
$html .= '<th>' . $fromLine . '</th>';
$html .= '<th>&#xA0;</th>';
$html .= '<td class="Left"><del>' . $line . '</del>&#xA0;</td>';
$html .= '</tr>';

$html .= <<<HTML
<tr>
<th>$fromLine</th>
<th>&#xA0;</th>
<td class="Left">
<del>$line</del>
&#xA0;
</td>
</tr>
HTML;
}

return $html;
}

/**
* Generates a string representation of one or more rows of a table of lines, where text was partially modified.
* Generates a string representation of table rows showing partialy modified text.
*
* @param array $change Contains the op-codes about the changes between two blocks of text.
*
* @param array &$change Array with data about changes.
* @return string Html code representing one or more rows of modified.
* @return string Html code representing table rows showing modified text.
*/
public function generateTableRowsReplace(array &$change): string
{
$html = "";
$html = '';

foreach ($change['base']['lines'] as $no => $line) {
$fromLine = $change['base']['offset'] + $no + 1;
$html .= '<tr>';
$html .= '<th>' . $fromLine . '</th>';
$html .= '<th>&#xA0;</th>';
$html .= '<td class="Left"><span>' . $line . '</span></td>';
$html .= '</tr>';

$html .= <<<HTML
<tr>
<th>$fromLine</th>
<th>&#xA0;</th>
<td class="Left">
<span>$line</span>
</td>
</tr>
HTML;
}

foreach ($change['changed']['lines'] as $no => $line) {
$toLine = $change['changed']['offset'] + $no + 1;
$html .= '<tr>';
$html .= '<th>&#xA0;</th>';
$html .= '<th>' . $toLine . '</th>';
$html .= '<td class="Right"><span>' . $line . '</span></td>';
$html .= '</tr>';

$html .= <<<HTML
<tr>
<th>&#xA0;</th>
<th>$toLine</th>
<td class="Right">
<span>$line</span>
</td>
</tr>
HTML;
}

return $html;
Expand Down