Skip to content

Commit e7830fd

Browse files
committed
follow PSR2 rules
except tabs vs space
1 parent e0cc8c3 commit e7830fd

File tree

8 files changed

+188
-182
lines changed

8 files changed

+188
-182
lines changed

lib/Autoloader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private function __autoload($class)
2323
{
2424
$class = str_replace('\\', '/', $class); // revert path for old PHP on Linux
2525
$dir = str_replace('\\', '/', __DIR__);
26-
if(file_exists($dir . '/' . $class . '.php')) {
26+
if (file_exists($dir . '/' . $class . '.php')) {
2727
/** @noinspection PhpIncludeInspection */
2828
require $dir . '/' . $class . '.php';
2929
}

lib/jblond/Diff.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,16 @@ class Diff
8686
* @param array $b Array containing the lines for the second string to compare.
8787
* @param array $options Array for the options
8888
*/
89-
public function __construct($a, $b, $options=array())
89+
public function __construct($a, $b, $options = array())
9090
{
9191
$this->a = $a;
9292
$this->b = $b;
9393

94-
if (is_array($options))
94+
if (is_array($options)) {
9595
$this->options = array_merge($this->defaultOptions, $options);
96-
else
96+
} else {
9797
$this->options = $this->defaultOptions;
98+
}
9899
}
99100

100101

@@ -120,21 +121,19 @@ public function render($renderer)
120121
* @param int $end The ending number. If not supplied, only the item in $start will be returned.
121122
* @return array Array of all of the lines between the specified range.
122123
*/
123-
public function getA($start=0, $end=null)
124+
public function getA($start = 0, $end = null)
124125
{
125-
if($start == 0 && $end === null) {
126+
if ($start == 0 && $end === null) {
126127
return $this->a;
127128
}
128129

129-
if($end === null) {
130+
if ($end === null) {
130131
$length = 1;
131-
}
132-
else {
132+
} else {
133133
$length = $end - $start;
134134
}
135135

136136
return array_slice($this->a, $start, $length);
137-
138137
}
139138

140139
/**
@@ -147,16 +146,15 @@ public function getA($start=0, $end=null)
147146
* @param int $end The ending number. If not supplied, only the item in $start will be returned.
148147
* @return array Array of all of the lines between the specified range.
149148
*/
150-
public function getB($start=0, $end=null)
149+
public function getB($start = 0, $end = null)
151150
{
152-
if($start == 0 && $end === null) {
151+
if ($start == 0 && $end === null) {
153152
return $this->b;
154153
}
155154

156-
if($end === null) {
155+
if ($end === null) {
157156
$length = 1;
158-
}
159-
else {
157+
} else {
160158
$length = $end - $start;
161159
}
162160

@@ -173,7 +171,7 @@ public function getB($start=0, $end=null)
173171
*/
174172
public function getGroupedOpcodes()
175173
{
176-
if(!is_null($this->groupedCodes)) {
174+
if (!is_null($this->groupedCodes)) {
177175
return $this->groupedCodes;
178176
}
179177

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

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -71,38 +71,43 @@ class HtmlArray extends RendererAbstract
7171
* into string at the given start offset.
7272
* @return string|array The result string is returned. If string is an array then array is returned.
7373
*/
74-
public function mb_substr_replace($string, $replacement, $start, $length=NULL) {
74+
public function mbSubstrReplace($string, $replacement, $start, $length = null)
75+
{
7576
if (is_array($string)) {
7677
$num = count($string);
7778
// $replacement
78-
$replacement = is_array($replacement) ? array_slice($replacement, 0, $num) : array_pad(array($replacement), $num, $replacement);
79+
if (is_array($replacement)) {
80+
$replacement = array_slice($replacement, 0, $num);
81+
} else {
82+
$replacement = array_pad(array($replacement), $num, $replacement);
83+
}
84+
7985
// $start
8086
if (is_array($start)) {
8187
$start = array_slice($start, 0, $num);
8288
foreach ($start as $key => $value)
8389
$start[$key] = is_int($value) ? $value : 0;
84-
}
85-
else {
90+
} else {
8691
$start = array_pad(array($start), $num, $start);
8792
}
8893
// $length
8994
if (!isset($length)) {
9095
$length = array_fill(0, $num, 0);
91-
}
92-
elseif (is_array($length)) {
96+
} elseif (is_array($length)) {
9397
$length = array_slice($length, 0, $num);
9498
foreach ($length as $key => $value)
9599
$length[$key] = isset($value) ? (is_int($value) ? $value : $num) : 0;
96-
}
97-
else {
100+
} else {
98101
$length = array_pad(array($length), $num, $length);
99102
}
100103
// Recursive call
101-
return array_map(array($this, 'mb_substr_replace'), $string, $replacement, $start, $length);
104+
return array_map(array($this, 'mbSubstrReplace'), $string, $replacement, $start, $length);
102105
}
103106
preg_match_all('/./us', (string)$string, $smatches);
104107
preg_match_all('/./us', (string)$replacement, $rmatches);
105-
if ($length === NULL) $length = mb_strlen($string);
108+
if ($length === null) {
109+
$length = mb_strlen($string);
110+
}
106111
array_splice($smatches['0'], $start, $length, $rmatches[0]);
107112
return join($smatches['0']);
108113
}
@@ -124,20 +129,20 @@ public function render()
124129

125130
$changes = array();
126131
$opCodes = $this->diff->getGroupedOpcodes();
127-
foreach($opCodes as $group) {
132+
foreach ($opCodes as $group) {
128133
$blocks = array();
129134
$lastTag = null;
130135
$lastBlock = 0;
131-
foreach($group as $code) {
136+
foreach ($group as $code) {
132137
list($tag, $i1, $i2, $j1, $j2) = $code;
133138

134-
if($tag == 'replace' && $i2 - $i1 == $j2 - $j1) {
135-
for($i = 0; $i < ($i2 - $i1); ++$i) {
139+
if ($tag == 'replace' && $i2 - $i1 == $j2 - $j1) {
140+
for ($i = 0; $i < ($i2 - $i1); ++$i) {
136141
$fromLine = $a[$i1 + $i];
137142
$toLine = $b[$j1 + $i];
138143

139144
list($start, $end) = $this->getChangeExtent($fromLine, $toLine);
140-
if($start != 0 || $end != 0) {
145+
if ($start != 0 || $end != 0) {
141146
$realEnd = mb_strlen($fromLine) + $end;
142147

143148
$fromLine = mb_substr($fromLine, 0, $start) . "\0" .
@@ -155,28 +160,27 @@ public function render()
155160
}
156161
}
157162

158-
if($tag != $lastTag) {
163+
if ($tag != $lastTag) {
159164
$blocks[] = $this->getDefaultArray($tag, $i1, $j1);
160165
$lastBlock = count($blocks)-1;
161166
}
162167

163168
$lastTag = $tag;
164169

165-
if($tag == 'equal') {
170+
if ($tag == 'equal') {
166171
$lines = array_slice($a, $i1, ($i2 - $i1));
167172
$blocks[$lastBlock]['base']['lines'] += $this->formatLines($lines);
168173
$lines = array_slice($b, $j1, ($j2 - $j1));
169174
$blocks[$lastBlock]['changed']['lines'] += $this->formatLines($lines);
170-
}
171-
else {
172-
if($tag == 'replace' || $tag == 'delete') {
175+
} else {
176+
if ($tag == 'replace' || $tag == 'delete') {
173177
$lines = array_slice($a, $i1, ($i2 - $i1));
174178
$lines = $this->formatLines($lines);
175179
$lines = str_replace(array("\0", "\1"), array('<del>', '</del>'), $lines);
176180
$blocks[$lastBlock]['base']['lines'] += $lines;
177181
}
178182

179-
if($tag == 'replace' || $tag == 'insert') {
183+
if ($tag == 'replace' || $tag == 'insert') {
180184
$lines = array_slice($b, $j1, ($j2 - $j1));
181185
$lines = $this->formatLines($lines);
182186
$lines = str_replace(array("\0", "\1"), array('<ins>', '</ins>'), $lines);
@@ -201,12 +205,12 @@ private function getChangeExtent($fromLine, $toLine)
201205
{
202206
$start = 0;
203207
$limit = min(mb_strlen($fromLine), mb_strlen($toLine));
204-
while($start < $limit && mb_substr($fromLine, $start, 1) == mb_substr($toLine, $start, 1)) {
208+
while ($start < $limit && mb_substr($fromLine, $start, 1) == mb_substr($toLine, $start, 1)) {
205209
++$start;
206210
}
207211
$end = -1;
208212
$limit = $limit - $start;
209-
while(-$end <= $limit && mb_substr($fromLine, $end, 1) == mb_substr($toLine, $end, 1)) {
213+
while (-$end <= $limit && mb_substr($fromLine, $end, 1) == mb_substr($toLine, $end, 1)) {
210214
--$end;
211215
}
212216
return array(
@@ -229,7 +233,7 @@ protected function formatLines($lines)
229233
$lines = array_map(array($this, 'ExpandTabs'), $lines);
230234
}
231235
$lines = array_map(array($this, 'HtmlSafe'), $lines);
232-
foreach($lines as &$line) {
236+
foreach ($lines as &$line) {
233237
$line = preg_replace_callback('# ( +)|^ #', array($this, 'fixSpaces'), $line);
234238
}
235239
return $lines;
@@ -245,9 +249,9 @@ protected function fixSpaces($matches)
245249
{
246250
$buffer = '';
247251
$count = 0;
248-
foreach($matches as $spaces){
252+
foreach ($matches as $spaces) {
249253
$count = strlen($spaces);
250-
if($count == 0) {
254+
if ($count == 0) {
251255
continue;
252256
}
253257
$div = (int) floor($count / 2);
@@ -269,12 +273,12 @@ protected function fixSpaces($matches)
269273
private function expandTabs($line)
270274
{
271275
$tabSize = $this->options['tabSize'];
272-
while(($pos = strpos($line, "\t")) !== FALSE){
276+
while (($pos = strpos($line, "\t")) !== false) {
273277
$left = substr($line, 0, $pos);
274278
$right = substr($line, $pos + 1);
275279
$length = $tabSize - ($pos % $tabSize);
276280
$spaces = str_repeat(' ', $length);
277-
$line = $left.$spaces.$right;
281+
$line = $left . $spaces . $right;
278282
}
279283
return $line;
280284
}
@@ -296,8 +300,10 @@ private function htmlSafe($string)
296300
* @param integer $j1
297301
* @return array
298302
*/
299-
private function getDefaultArray($tag, $i1, $j1){
300-
return array(
303+
private function getDefaultArray($tag, $i1, $j1)
304+
{
305+
return array
306+
(
301307
'tag' => $tag,
302308
'base' => array(
303309
'offset' => $i1,

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,23 @@ public function render()
5757
{
5858
$changes = parent::render();
5959
$html = '';
60-
if(empty($changes)) {
60+
if (empty($changes)) {
6161
return $html;
6262
}
6363

6464
$html .= $this->generateTableHeader();
6565

66-
foreach($changes as $i => $blocks) {
66+
foreach ($changes as $i => $blocks) {
6767
// If this is a separate block, we're condensing code so output ...,
6868
// indicating a significant portion of the code has been collapsed as
6969
// it is the same
70-
if($i > 0) {
70+
if ($i > 0) {
7171
$html .= $this->generateSkippedTable();
7272
}
7373

74-
foreach($blocks as $change) {
74+
foreach ($blocks as $change) {
7575
$html .= '<tbody class="Change'.ucfirst($change['tag']).'">';
76-
switch ($change['tag']){
76+
switch ($change['tag']) {
7777
// Equal changes should be shown on both sides of the diff
7878
case 'equal':
7979
$html .= $this->generateTableRowsEqual($change);
@@ -142,7 +142,7 @@ private function generateSkippedTable()
142142
private function generateTableRowsEqual(&$change)
143143
{
144144
$html = "";
145-
foreach($change['base']['lines'] as $no => $line) {
145+
foreach ($change['base']['lines'] as $no => $line) {
146146
$fromLine = $change['base']['offset'] + $no + 1;
147147
$toLine = $change['changed']['offset'] + $no + 1;
148148
$html .= '<tr>';
@@ -163,7 +163,7 @@ private function generateTableRowsEqual(&$change)
163163
private function generateTableRowsInsert(&$change)
164164
{
165165
$html = "";
166-
foreach($change['changed']['lines'] as $no => $line) {
166+
foreach ($change['changed']['lines'] as $no => $line) {
167167
$toLine = $change['changed']['offset'] + $no + 1;
168168
$html .= '<tr>';
169169
$html .= '<th>&#xA0;</th>';
@@ -183,7 +183,7 @@ private function generateTableRowsInsert(&$change)
183183
private function generateTableRowsDelete(&$change)
184184
{
185185
$html = "";
186-
foreach($change['base']['lines'] as $no => $line) {
186+
foreach ($change['base']['lines'] as $no => $line) {
187187
$fromLine = $change['base']['offset'] + $no + 1;
188188
$html .= '<tr>';
189189
$html .= '<th>'.$fromLine.'</th>';
@@ -204,7 +204,7 @@ private function generateTableRowsReplace(&$change)
204204
{
205205
$html = "";
206206

207-
foreach($change['base']['lines'] as $no => $line) {
207+
foreach ($change['base']['lines'] as $no => $line) {
208208
$fromLine = $change['base']['offset'] + $no + 1;
209209
$html .= '<tr>';
210210
$html .= '<th>'.$fromLine.'</th>';
@@ -213,7 +213,7 @@ private function generateTableRowsReplace(&$change)
213213
$html .= '</tr>';
214214
}
215215

216-
foreach($change['changed']['lines'] as $no => $line) {
216+
foreach ($change['changed']['lines'] as $no => $line) {
217217
$toLine = $change['changed']['offset'] + $no + 1;
218218
$html .= '<tr>';
219219
$html .= '<th>&#xA0;</th>';

0 commit comments

Comments
 (0)