Skip to content

Commit c984365

Browse files
committed
Code Optimization, cleanup, refactoring and commenting.
1 parent e227356 commit c984365

File tree

1 file changed

+96
-61
lines changed

1 file changed

+96
-61
lines changed

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

Lines changed: 96 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -19,124 +19,159 @@
1919
class Inline extends HtmlArray
2020
{
2121
/**
22-
* Render a and return diff with changes between the two sequences
23-
* displayed inline (under each other)
22+
* Render a and return diff-view with changes between the two sequences displayed side by side. (under each other)
2423
*
25-
* @return string The generated inline diff.
24+
* @return string The generated inline diff-view.
2625
*/
2726
public function render(): string
2827
{
2928
$changes = parent::render();
29+
3030
return parent::renderHtml($changes, $this);
3131
}
3232

3333

3434
/**
35-
* Generates a string representation of a predefined table and its head with
36-
* titles from options.
35+
* Generates a string representation of the opening of a predefined table and its header with titles from options.
3736
*
38-
* @return string Html code representation of the table's header.
37+
* @return string HTML code representation of a table's header.
3938
*/
4039
public function generateTableHeader(): string
4140
{
42-
$html = '<table class="Differences DifferencesInline">';
43-
$html .= '<thead>';
44-
$html .= '<tr>';
45-
$html .= '<th>Old</th>';
46-
$html .= '<th>New</th>';
47-
$html .= '<th>Differences</th>';
48-
$html .= '</tr>';
49-
$html .= '</thead>';
50-
return $html;
41+
return <<<HTML
42+
<table class="Differences DifferencesInline">
43+
<thead>
44+
<tr>
45+
<th>{$this->options['title_a']}</th>
46+
<th>{$this->options['title_b']}</th>
47+
<th>Differences</th>
48+
</tr>
49+
</thead>
50+
HTML;
5151
}
5252

5353
/**
54-
* Generates a string representation of one or more rows of a table of lines of text with no difference.
54+
* Generates a string representation of table rows showing text with no difference.
55+
*
56+
* @param array $change Contains the op-codes about the changes between two blocks.
5557
*
56-
* @param array &$change Array with data about changes.
57-
* @return string Html code representing one or more rows of text with no difference.
58+
* @return string HTML code representing table rows showing text with no difference.
5859
*/
59-
public function generateTableRowsEqual(array &$change): string
60+
public function generateTableRowsEqual(array $change): string
6061
{
61-
$html = "";
62+
$html = '';
63+
6264
foreach ($change['base']['lines'] as $no => $line) {
63-
$fromLine = $change['base']['offset'] + $no + 1;
64-
$toLine = $change['changed']['offset'] + $no + 1;
65-
$html .= '<tr>';
66-
$html .= '<th>' . $fromLine . '</th>';
67-
$html .= '<th>' . $toLine . '</th>';
68-
$html .= '<td class="Left">' . $line . '</td>';
69-
$html .= '</tr>';
65+
$fromLine = $change['base']['offset'] + $no + 1;
66+
$toLine = $change['changed']['offset'] + $no + 1;
67+
68+
$html .= <<<HTML
69+
<tr>
70+
<th>$fromLine</th>
71+
<th>$toLine</th>
72+
<td class="Left">$line</td>
73+
</tr>
74+
HTML;
7075
}
76+
7177
return $html;
7278
}
7379

7480
/**
75-
* Generates a string representation of one or more rows of a table of lines, where new text was added.
81+
* Generates a string representation of table rows showing added text.
7682
*
77-
* @param array &$change Array with data about changes.
78-
* @return string Html code representing one or more rows of added text.
83+
* @param array $change Contains the op-codes about the changes between two blocks of text.
84+
*
85+
* @return string HTML code representing table rows showing with added text.
7986
*/
80-
public function generateTableRowsInsert(array &$change): string
87+
public function generateTableRowsInsert(array $change): string
8188
{
82-
$html = "";
89+
$html = '';
90+
8391
foreach ($change['changed']['lines'] as $no => $line) {
8492
$toLine = $change['changed']['offset'] + $no + 1;
85-
$html .= '<tr>';
86-
$html .= '<th>&#xA0;</th>';
87-
$html .= '<th>' . $toLine . '</th>';
88-
$html .= '<td class="Right"><ins>' . $line . '</ins>&#xA0;</td>';
89-
$html .= '</tr>';
93+
94+
$html .= <<<HTML
95+
<tr>
96+
<th>&#xA0;</th>
97+
<th>$toLine</th>
98+
<td class="Right">
99+
<ins>$line</ins>
100+
&#xA0;
101+
</td>
102+
</tr>
103+
HTML;
90104
}
105+
91106
return $html;
92107
}
93108

94109
/**
95-
* Generates a string representation of one or more rows of a table of lines, where text was removed.
110+
* Generates a string representation of table rows showing removed text.
111+
*
112+
* @param array $change Contains the op-codes about the changes between two blocks of text.
96113
*
97-
* @param array &$change Array with data about changes.
98-
* @return string Html code representing one or more rows of removed text.
114+
* @return string HTML code representing table rows showing removed text.
99115
*/
100-
public function generateTableRowsDelete(array &$change): string
116+
public function generateTableRowsDelete(array $change): string
101117
{
102-
$html = "";
118+
$html = '';
119+
103120
foreach ($change['base']['lines'] as $no => $line) {
104121
$fromLine = $change['base']['offset'] + $no + 1;
105-
$html .= '<tr>';
106-
$html .= '<th>' . $fromLine . '</th>';
107-
$html .= '<th>&#xA0;</th>';
108-
$html .= '<td class="Left"><del>' . $line . '</del>&#xA0;</td>';
109-
$html .= '</tr>';
122+
123+
$html .= <<<HTML
124+
<tr>
125+
<th>$fromLine</th>
126+
<th>&#xA0;</th>
127+
<td class="Left">
128+
<del>$line</del>
129+
&#xA0;
130+
</td>
131+
</tr>
132+
HTML;
110133
}
134+
111135
return $html;
112136
}
113137

114138
/**
115-
* Generates a string representation of one or more rows of a table of lines, where text was partially modified.
139+
* Generates a string representation of table rows showing partialy modified text.
140+
*
141+
* @param array $change Contains the op-codes about the changes between two blocks of text.
116142
*
117-
* @param array &$change Array with data about changes.
118-
* @return string Html code representing one or more rows of modified.
143+
* @return string Html code representing table rows showing modified text.
119144
*/
120145
public function generateTableRowsReplace(array &$change): string
121146
{
122-
$html = "";
147+
$html = '';
123148

124149
foreach ($change['base']['lines'] as $no => $line) {
125150
$fromLine = $change['base']['offset'] + $no + 1;
126-
$html .= '<tr>';
127-
$html .= '<th>' . $fromLine . '</th>';
128-
$html .= '<th>&#xA0;</th>';
129-
$html .= '<td class="Left"><span>' . $line . '</span></td>';
130-
$html .= '</tr>';
151+
152+
$html .= <<<HTML
153+
<tr>
154+
<th>$fromLine</th>
155+
<th>&#xA0;</th>
156+
<td class="Left">
157+
<span>$line</span>
158+
</td>
159+
</tr>
160+
HTML;
131161
}
132162

133163
foreach ($change['changed']['lines'] as $no => $line) {
134164
$toLine = $change['changed']['offset'] + $no + 1;
135-
$html .= '<tr>';
136-
$html .= '<th>&#xA0;</th>';
137-
$html .= '<th>' . $toLine . '</th>';
138-
$html .= '<td class="Right"><span>' . $line . '</span></td>';
139-
$html .= '</tr>';
165+
166+
$html .= <<<HTML
167+
<tr>
168+
<th>&#xA0;</th>
169+
<th>$toLine</th>
170+
<td class="Right">
171+
<span>$line</span>
172+
</td>
173+
</tr>
174+
HTML;
140175
}
141176

142177
return $html;

0 commit comments

Comments
 (0)