Skip to content

Commit 039fab0

Browse files
committed
Use PSR 12
1 parent d883a00 commit 039fab0

File tree

12 files changed

+116
-87
lines changed

12 files changed

+116
-87
lines changed

composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
"jblond\\": "lib/jblond"
3131
}
3232
},
33+
"config": {
34+
"classmap-authoritative": true
35+
},
3336
"scripts": {
3437
"phpunit": "phpunit ./tests/",
3538
"php_src": "phpcs --standard=phpcs.xml -s -p --colors ./lib/",

lib/Autoloader.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace jblond;
34

45
/**

lib/jblond/Diff.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
2+
23
declare(strict_types=1);
4+
35
namespace jblond;
46

57
use jblond\Diff\SequenceMatcher;
@@ -44,7 +46,7 @@ class Diff
4446
'ignoreNewLines' => false,
4547
'ignoreWhitespace' => false,
4648
'ignoreCase' => false,
47-
'labelDifferences'=>'Differences'
49+
'labelDifferences' => 'Differences'
4850
);
4951

5052
/**
@@ -94,7 +96,7 @@ public function render($renderer)
9496
* @param int|null $end The ending number. If not supplied, only the item in $start will be returned.
9597
* @return array Array of all of the lines between the specified range.
9698
*/
97-
public function getOld(int $start = 0, $end = null) : array
99+
public function getOld(int $start = 0, $end = null): array
98100
{
99101
if ($start == 0 && $end === null) {
100102
return $this->old;
@@ -118,7 +120,7 @@ public function getOld(int $start = 0, $end = null) : array
118120
* @param int|null $end The ending number. If not supplied, only the item in $start will be returned.
119121
* @return array Array of all of the lines between the specified range.
120122
*/
121-
public function getNew(int $start = 0, $end = null) : array
123+
public function getNew(int $start = 0, $end = null): array
122124
{
123125
if ($start == 0 && $end === null) {
124126
return $this->new;
@@ -140,7 +142,7 @@ public function getNew(int $start = 0, $end = null) : array
140142
*
141143
* @return array Array of the grouped op codes for the generated diff.
142144
*/
143-
public function getGroupedOpcodes() : array
145+
public function getGroupedOpcodes(): array
144146
{
145147
if (!is_null($this->groupedCodes)) {
146148
return $this->groupedCodes;

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

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
2+
23
declare(strict_types=1);
4+
35
namespace jblond\Diff\Renderer\Html;
46

57
use jblond\Diff\Renderer\RendererAbstract;
@@ -50,7 +52,7 @@ public function renderHtml($changes, $object)
5052
}
5153

5254
foreach ($blocks as $change) {
53-
$html .= '<tbody class="Change'.ucfirst($change['tag']).'">';
55+
$html .= '<tbody class="Change' . ucfirst($change['tag']) . '">';
5456
switch ($change['tag']) {
5557
// Equal changes should be shown on both sides of the diff
5658
case 'equal':
@@ -125,7 +127,7 @@ public function render()
125127

126128
if ($tag != $lastTag) {
127129
$blocks[] = $this->getDefaultArray($tag, $i1, $j1);
128-
$lastBlock = count($blocks)-1;
130+
$lastBlock = count($blocks) - 1;
129131
}
130132

131133
$lastTag = $tag;
@@ -190,7 +192,7 @@ private function getChangeExtent(string $fromLine, string $toLine)
190192
* @param array $lines Array of lines to format.
191193
* @return array Array of the formatted lines.
192194
*/
193-
protected function formatLines(array $lines) : array
195+
protected function formatLines(array $lines): array
194196
{
195197
if ($this->options['tabSize'] !== false) {
196198
$lines = array_map(
@@ -218,7 +220,7 @@ function ($item) {
218220
* @param array $matches The string of spaces.
219221
* @return string The HTML representation of the string.
220222
*/
221-
protected function fixSpaces(array $matches) : string
223+
protected function fixSpaces(array $matches): string
222224
{
223225
$buffer = '';
224226
$count = 0;
@@ -229,12 +231,12 @@ protected function fixSpaces(array $matches) : string
229231
}
230232
$div = (int) ($count / 2);
231233
$mod = $count % 2;
232-
$buffer .= str_repeat('&#xA0; ', $div).str_repeat('&#xA0;', $mod);
234+
$buffer .= str_repeat('&#xA0; ', $div) . str_repeat('&#xA0;', $mod);
233235
}
234236

235237
$div = (int) ($count / 2);
236238
$mod = $count % 2;
237-
return str_repeat('&#xA0; ', $div).str_repeat('&#xA0;', $mod);
239+
return str_repeat('&#xA0; ', $div) . str_repeat('&#xA0;', $mod);
238240
}
239241

240242
/**
@@ -243,7 +245,7 @@ protected function fixSpaces(array $matches) : string
243245
* @param string $line The containing tabs to convert.
244246
* @return string The line with the tabs converted to spaces.
245247
*/
246-
private function expandTabs(string $line) : string
248+
private function expandTabs(string $line): string
247249
{
248250
$tabSize = $this->options['tabSize'];
249251
while (($pos = strpos($line, "\t")) !== false) {
@@ -262,7 +264,7 @@ private function expandTabs(string $line) : string
262264
* @param string $string The string.
263265
* @return string The string with the HTML characters replaced by entities.
264266
*/
265-
private function htmlSafe(string $string) : string
267+
private function htmlSafe(string $string): string
266268
{
267269
return htmlspecialchars($string, ENT_NOQUOTES, 'UTF-8');
268270
}
@@ -273,7 +275,7 @@ private function htmlSafe(string $string) : string
273275
* @param integer $j1
274276
* @return array
275277
*/
276-
private function getDefaultArray(string $tag, int $i1, int $j1) : array
278+
private function getDefaultArray(string $tag, int $i1, int $j1): array
277279
{
278280
return array
279281
(

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

+20-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
2+
23
declare(strict_types=1);
4+
35
namespace jblond\Diff\Renderer\Html;
46

57
/**
@@ -22,7 +24,7 @@ class Inline extends HtmlArray
2224
*
2325
* @return string The generated inline diff.
2426
*/
25-
public function render() : string
27+
public function render(): string
2628
{
2729
$changes = parent::render();
2830
return parent::renderHtml($changes, $this);
@@ -35,7 +37,7 @@ public function render() : string
3537
*
3638
* @return string Html code representation of the table's header.
3739
*/
38-
public function generateTableHeader() : string
40+
public function generateTableHeader(): string
3941
{
4042
$html = '<table class="Differences DifferencesInline">';
4143
$html .= '<thead>';
@@ -53,7 +55,7 @@ public function generateTableHeader() : string
5355
*
5456
* @return string Html code representing empty table body.
5557
*/
56-
public function generateSkippedTable() : string
58+
public function generateSkippedTable(): string
5759
{
5860
$html = '<tbody class="Skipped">';
5961
$html .= '<th>&hellip;</th>';
@@ -69,16 +71,16 @@ public function generateSkippedTable() : string
6971
* @param array &$change Array with data about changes.
7072
* @return string Html code representing one or more rows of text with no difference.
7173
*/
72-
public function generateTableRowsEqual(array &$change) : string
74+
public function generateTableRowsEqual(array &$change): string
7375
{
7476
$html = "";
7577
foreach ($change['base']['lines'] as $no => $line) {
7678
$fromLine = $change['base']['offset'] + $no + 1;
7779
$toLine = $change['changed']['offset'] + $no + 1;
7880
$html .= '<tr>';
79-
$html .= '<th>'.$fromLine.'</th>';
80-
$html .= '<th>'.$toLine.'</th>';
81-
$html .= '<td class="Left">'.$line.'</td>';
81+
$html .= '<th>' . $fromLine . '</th>';
82+
$html .= '<th>' . $toLine . '</th>';
83+
$html .= '<td class="Left">' . $line . '</td>';
8284
$html .= '</tr>';
8385
}
8486
return $html;
@@ -90,15 +92,15 @@ public function generateTableRowsEqual(array &$change) : string
9092
* @param array &$change Array with data about changes.
9193
* @return string Html code representing one or more rows of added text.
9294
*/
93-
public function generateTableRowsInsert(array &$change) : string
95+
public function generateTableRowsInsert(array &$change): string
9496
{
9597
$html = "";
9698
foreach ($change['changed']['lines'] as $no => $line) {
9799
$toLine = $change['changed']['offset'] + $no + 1;
98100
$html .= '<tr>';
99101
$html .= '<th>&#xA0;</th>';
100-
$html .= '<th>'.$toLine.'</th>';
101-
$html .= '<td class="Right"><ins>'.$line.'</ins>&#xA0;</td>';
102+
$html .= '<th>' . $toLine . '</th>';
103+
$html .= '<td class="Right"><ins>' . $line . '</ins>&#xA0;</td>';
102104
$html .= '</tr>';
103105
}
104106
return $html;
@@ -110,15 +112,15 @@ public function generateTableRowsInsert(array &$change) : string
110112
* @param array &$change Array with data about changes.
111113
* @return string Html code representing one or more rows of removed text.
112114
*/
113-
public function generateTableRowsDelete(array &$change) : string
115+
public function generateTableRowsDelete(array &$change): string
114116
{
115117
$html = "";
116118
foreach ($change['base']['lines'] as $no => $line) {
117119
$fromLine = $change['base']['offset'] + $no + 1;
118120
$html .= '<tr>';
119-
$html .= '<th>'.$fromLine.'</th>';
121+
$html .= '<th>' . $fromLine . '</th>';
120122
$html .= '<th>&#xA0;</th>';
121-
$html .= '<td class="Left"><del>'.$line.'</del>&#xA0;</td>';
123+
$html .= '<td class="Left"><del>' . $line . '</del>&#xA0;</td>';
122124
$html .= '</tr>';
123125
}
124126
return $html;
@@ -130,25 +132,25 @@ public function generateTableRowsDelete(array &$change) : string
130132
* @param array &$change Array with data about changes.
131133
* @return string Html code representing one or more rows of modified.
132134
*/
133-
public function generateTableRowsReplace(array &$change) : string
135+
public function generateTableRowsReplace(array &$change): string
134136
{
135137
$html = "";
136138

137139
foreach ($change['base']['lines'] as $no => $line) {
138140
$fromLine = $change['base']['offset'] + $no + 1;
139141
$html .= '<tr>';
140-
$html .= '<th>'.$fromLine.'</th>';
142+
$html .= '<th>' . $fromLine . '</th>';
141143
$html .= '<th>&#xA0;</th>';
142-
$html .= '<td class="Left"><span>'.$line.'</span></td>';
144+
$html .= '<td class="Left"><span>' . $line . '</span></td>';
143145
$html .= '</tr>';
144146
}
145147

146148
foreach ($change['changed']['lines'] as $no => $line) {
147149
$toLine = $change['changed']['offset'] + $no + 1;
148150
$html .= '<tr>';
149151
$html .= '<th>&#xA0;</th>';
150-
$html .= '<th>'.$toLine.'</th>';
151-
$html .= '<td class="Right"><span>'.$line.'</span></td>';
152+
$html .= '<th>' . $toLine . '</th>';
153+
$html .= '<td class="Right"><span>' . $line . '</span></td>';
152154
$html .= '</tr>';
153155
}
154156

0 commit comments

Comments
 (0)