Skip to content

Commit 7f87ce3

Browse files
committed
Code reformatting and minor optimization, Typo fixes
1 parent c017af5 commit 7f87ce3

File tree

11 files changed

+60
-48
lines changed

11 files changed

+60
-48
lines changed

example/example.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
use jblond\Autoloader;
34
use jblond\Diff;
45
use jblond\Diff\Renderer\Html\Inline;

example/styles.css

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
body {
2-
background: #FFFFFF;
3-
font-family: Arial;
4-
font-size: 12px;
2+
background: #FFFFFF;
3+
font-family: Arial, serif;
4+
font-size: 12px;
55
}
66

77
pre {
8-
width: 100%;
8+
width: 100%;
99
overflow: auto;
1010
}
1111

@@ -14,18 +14,18 @@ pre {
1414
*/
1515

1616
.Differences {
17-
width: 100%;
18-
border-collapse: collapse;
19-
border-spacing: 0;
20-
empty-cells: show;
17+
width: 100%;
18+
border-collapse: collapse;
19+
border-spacing: 0;
20+
empty-cells: show;
2121
}
2222

2323
.Differences thead th {
24-
text-align: left;
25-
border-bottom: 1px solid #000000;
26-
background: #AAAAAA;
27-
color: #000000;
28-
padding: 4px;
24+
text-align: left;
25+
border-bottom: 1px solid #000000;
26+
background: #AAAAAA;
27+
color: #000000;
28+
padding: 4px;
2929
}
3030

3131
.Differences tbody th {
@@ -39,9 +39,9 @@ pre {
3939
}
4040

4141
.Differences td {
42-
padding: 1px 2px;
43-
font-family: Consolas, monospace;
44-
font-size: 13px;
42+
padding: 1px 2px;
43+
font-family: Consolas, monospace;
44+
font-size: 13px;
4545
}
4646

4747
.Differences .Skipped {
@@ -129,11 +129,13 @@ pre {
129129
.DifferencesUnified .ChangeReplace .Left:first-child:before {
130130
content: "\250C \00a0";
131131
}
132+
132133
.DifferencesUnified .ChangeReplace .Left:before {
133134
content: "\251C \00a0";
134135
}
136+
135137
.DifferencesUnified .ChangeReplace .Left {
136-
background: #fe9;
138+
background: #FFEE99;
137139
}
138140

139141
/* Line in new replaced line in old */
@@ -159,7 +161,7 @@ pre {
159161
background: #99EE99;
160162
}
161163

162-
/* Chararcter removed from line in old */
164+
/* Character removed from line in old */
163165
.DifferencesUnified .ChangeReplace del {
164-
background: #EE9999;
166+
background: #EE9999;
165167
}

lib/Autoloader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Autoloader
2222
/**
2323
* Constructor.
2424
*
25-
* A function is registered as an __autoload() implementation to include and evaluate the class file whan this class
25+
* A function is registered as an __autoload() implementation to include and evaluate the class file when this class
2626
* is called.
2727
*/
2828
public function __construct()

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ private function getChangeExtent(string $oldString, string $newString): array
216216
* This involves replacing tab characters with spaces, making the HTML safe for output by ensuring that double
217217
* spaces are replaced with &nbsp; etc.
218218
*
219-
* @param array $lines Array of strings to format.
219+
* @param array $strings Array of strings to format.
220220
*
221221
* @return array Array of formatted strings.
222222
*/

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function generateTableRowsDelete(array $change): string
136136
}
137137

138138
/**
139-
* Generates a string representation of table rows showing partialy modified text.
139+
* Generates a string representation of table rows showing partially modified text.
140140
*
141141
* @param array $change Contains the op-codes about the changes between two blocks of text.
142142
*

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function generateTableRowsInsert(array $change): string
112112
*
113113
* @return string HTML code representing table rows showing removed text.
114114
*/
115-
public function generateTableRowsDelete(array &$change): string
115+
public function generateTableRowsDelete(array $change): string
116116
{
117117
$html = '';
118118

@@ -136,7 +136,7 @@ public function generateTableRowsDelete(array &$change): string
136136
}
137137

138138
/**
139-
* Generates a string representation of table rows showing partialy modified text.
139+
* Generates a string representation of table rows showing partially modified text.
140140
*
141141
* @param array $change Contains the op-codes about the changes between two blocks of text.
142142
*

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

+21-17
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,32 @@
2121
class Context extends RendererAbstract
2222
{
2323
/**
24-
* @var array Array of the different op code tags and how they map to the context diff equivalent.
24+
* @var array Array of the different op-code tags and how they map to the context diff-view equivalent.
2525
*/
26-
private $tagMap = array(
27-
'insert' => '+',
28-
'delete' => '-',
29-
'replace' => '!',
30-
'equal' => ' '
31-
);
26+
private $tagMap = [
27+
'insert' => '+',
28+
'delete' => '-',
29+
'replace' => '!',
30+
'equal' => ' '
31+
];
3232

3333
/**
34-
* Render and return a context formatted (old school!) diff file.
34+
* Render and return a context formatted (old school!) diff-view.
3535
*
36-
* @return string The generated context diff.
36+
* @return string The generated context diff-view.
3737
*/
3838
public function render(): string
3939
{
40-
$diff = '';
41-
$opCodes = $this->diff->getGroupedOpcodes();
40+
$diff = '';
41+
$opCodes = $this->diff->getGroupedOpcodes();
42+
4243
foreach ($opCodes as $group) {
43-
$diff .= "***************\n";
44-
$lastItem = count($group) - 1;
45-
$i1 = $group['0']['1'];
46-
$i2 = $group[$lastItem]['2'];
47-
$j1 = $group['0']['3'];
48-
$j2 = $group[$lastItem]['4'];
44+
$diff .= "***************\n";
45+
$lastItem = count($group) - 1;
46+
$i1 = $group['0']['1'];
47+
$i2 = $group[$lastItem]['2'];
48+
$j1 = $group['0']['3'];
49+
$j2 = $group[$lastItem]['4'];
4950

5051
if ($i2 - $i1 >= 2) {
5152
$diff .= '*** ' . ($group['0']['1'] + 1) . ',' . $i2 . " ****\n";
@@ -60,6 +61,7 @@ public function render(): string
6061
}
6162

6263
$hasVisible = false;
64+
6365
foreach ($group as $code) {
6466
if ($code['0'] == 'replace' || $code['0'] == 'delete') {
6567
$hasVisible = true;
@@ -82,6 +84,7 @@ public function render(): string
8284
}
8385

8486
$hasVisible = false;
87+
8588
foreach ($group as $code) {
8689
if ($code['0'] == 'replace' || $code['0'] == 'insert') {
8790
$hasVisible = true;
@@ -105,6 +108,7 @@ public function render(): string
105108
}
106109
}
107110
}
111+
108112
return $diff;
109113
}
110114
}

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ public function render(): string
4949
foreach ($group as $code) {
5050
list($tag, $i1, $i2, $j1, $j2) = $code;
5151
if ($tag == 'equal') {
52-
$diff .= ' ' . implode("\n ", $this->diff->getArrayRange($this->diff->getOld(), $i1, $i2)) . "\n";
52+
$diff .= ' ' .
53+
implode(
54+
"\n ",
55+
$this->diff->getArrayRange($this->diff->getOld(), $i1, $i2)
56+
) . "\n";
5357
} else {
5458
if ($tag == 'replace' || $tag == 'delete') {
5559
$diff .= '-' .

tests/Diff/Renderer/Html/HtmlArrayTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
namespace Tests\Diff\Renderer\Html;
66

7-
use PHPUnit\Framework\TestCase;
7+
use jblond\Diff;
88
use jblond\Diff\Renderer\Html\HtmlArray;
9+
use PHPUnit\Framework\TestCase;
910

1011
/**
1112
* Class HtmlArrayTest
@@ -32,7 +33,7 @@ public function __construct($name = null, array $data = [], $dataName = '')
3233
public function testRenderSimpleDelete()
3334
{
3435
$htmlRenderer = new HtmlArray();
35-
$htmlRenderer->diff = new \jblond\Diff(
36+
$htmlRenderer->diff = new Diff(
3637
array('a'),
3738
array()
3839
);
@@ -62,7 +63,7 @@ public function testRenderSimpleDelete()
6263
public function testRenderFixesSpaces()
6364
{
6465
$htmlRenderer = new HtmlArray();
65-
$htmlRenderer->diff = new \jblond\Diff(
66+
$htmlRenderer->diff = new Diff(
6667
array(' a'),
6768
array('a')
6869
);

tests/Diff/Renderer/Html/HtmlRenderersTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace Tests\Diff\Renderer\Html;
66

7-
use PHPUnit\Framework\TestCase;
87
use jblond\Diff;
98
use jblond\Diff\Renderer\Html\Inline;
109
use jblond\Diff\Renderer\Html\SideBySide;
1110
use jblond\Diff\Renderer\Html\Unified;
11+
use PHPUnit\Framework\TestCase;
1212

1313
/**
1414
* Class HtmlRendererTest

tests/Diff/Renderer/Text/TextRenderersTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
namespace Tests\Diff\Renderer\Text;
66

7-
use PHPUnit\Framework\TestCase;
87
use jblond\Diff;
98
use jblond\Diff\Renderer\Text\Context;
109
use jblond\Diff\Renderer\Text\Unified;
10+
use PHPUnit\Framework\TestCase;
1111

1212
/**
1313
* Class TextRendererTest
1414
*
15-
* PHPunit tests to verify the output of the text renderers hasn't change by code changes.
15+
* PHPUnit tests to verify the output of the text renderers hasn't change by code changes.
1616
*
1717
* @package Tests\Diff\Renderer\Text
1818
*/

0 commit comments

Comments
 (0)