Skip to content

Commit 6cf5ca9

Browse files
Fix CS/WS issues
1 parent 787946f commit 6cf5ca9

File tree

6 files changed

+25
-10
lines changed

6 files changed

+25
-10
lines changed

src/Differ.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ private function getLinebreak($line): string
272272
}
273273

274274
$lc = \substr($line, -1);
275+
275276
if ("\r" === $lc) {
276277
return "\r";
277278
}

src/Output/DiffOnlyOutputBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function getDiff(array $diff): string
3434

3535
if ('' !== $this->header) {
3636
\fwrite($buffer, $this->header);
37+
3738
if ("\n" !== \substr($this->header, -1, 1)) {
3839
\fwrite($buffer, "\n");
3940
}
@@ -53,6 +54,7 @@ public function getDiff(array $diff): string
5354
}
5455

5556
$lc = \substr($diffEntry[0], -1);
57+
5658
if ($lc !== "\n" && $lc !== "\r") {
5759
\fwrite($buffer, "\n"); // \No newline at end of file
5860
}

src/Output/StrictUnifiedDiffOutputBuilder.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
*/
2121
final class StrictUnifiedDiffOutputBuilder implements DiffOutputBuilderInterface
2222
{
23+
private static $default = [
24+
'collapseRanges' => true, // ranges of length one are rendered with the trailing `,1`
25+
'commonLineThreshold' => 6, // number of same lines before ending a new hunk and creating a new one (if needed)
26+
'contextLines' => 3, // like `diff: -u, -U NUM, --unified[=NUM]`, for patch/git apply compatibility best to keep at least @ 3
27+
'fromFile' => null,
28+
'fromFileDate' => null,
29+
'toFile' => null,
30+
'toFileDate' => null,
31+
];
2332
/**
2433
* @var bool
2534
*/
@@ -45,16 +54,6 @@ final class StrictUnifiedDiffOutputBuilder implements DiffOutputBuilderInterface
4554
*/
4655
private $contextLines;
4756

48-
private static $default = [
49-
'collapseRanges' => true, // ranges of length one are rendered with the trailing `,1`
50-
'commonLineThreshold' => 6, // number of same lines before ending a new hunk and creating a new one (if needed)
51-
'contextLines' => 3, // like `diff: -u, -U NUM, --unified[=NUM]`, for patch/git apply compatibility best to keep at least @ 3
52-
'fromFile' => null,
53-
'fromFileDate' => null,
54-
'toFile' => null,
55-
'toFileDate' => null,
56-
];
57-
5857
public function __construct(array $options = [])
5958
{
6059
$options = \array_merge(self::$default, $options);
@@ -137,17 +136,20 @@ private function writeDiffHunks($output, array $diff): void
137136

138137
if (0 === $diff[$upperLimit - 1][1]) {
139138
$lc = \substr($diff[$upperLimit - 1][0], -1);
139+
140140
if ("\n" !== $lc) {
141141
\array_splice($diff, $upperLimit, 0, [["\n\\ No newline at end of file\n", Differ::NO_LINE_END_EOF_WARNING]]);
142142
}
143143
} else {
144144
// search back for the last `+` and `-` line,
145145
// check if has trailing linebreak, else add under it warning under it
146146
$toFind = [1 => true, 2 => true];
147+
147148
for ($i = $upperLimit - 1; $i >= 0; --$i) {
148149
if (isset($toFind[$diff[$i][1]])) {
149150
unset($toFind[$diff[$i][1]]);
150151
$lc = \substr($diff[$i][0], -1);
152+
151153
if ("\n" !== $lc) {
152154
\array_splice($diff, $i + 1, 0, [["\n\\ No newline at end of file\n", Differ::NO_LINE_END_EOF_WARNING]]);
153155
}
@@ -286,6 +288,7 @@ private function writeHunk(
286288
}
287289

288290
\fwrite($output, ' +' . $toStart);
291+
289292
if (!$this->collapseRanges || 1 !== $toRange) {
290293
\fwrite($output, ',' . $toRange);
291294
}

src/Output/UnifiedDiffOutputBuilder.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function getDiff(array $diff): string
5454

5555
if ('' !== $this->header) {
5656
\fwrite($buffer, $this->header);
57+
5758
if ("\n" !== \substr($this->header, -1, 1)) {
5859
\fwrite($buffer, "\n");
5960
}
@@ -85,17 +86,20 @@ private function writeDiffHunks($output, array $diff): void
8586

8687
if (0 === $diff[$upperLimit - 1][1]) {
8788
$lc = \substr($diff[$upperLimit - 1][0], -1);
89+
8890
if ("\n" !== $lc) {
8991
\array_splice($diff, $upperLimit, 0, [["\n\\ No newline at end of file\n", Differ::NO_LINE_END_EOF_WARNING]]);
9092
}
9193
} else {
9294
// search back for the last `+` and `-` line,
9395
// check if has trailing linebreak, else add under it warning under it
9496
$toFind = [1 => true, 2 => true];
97+
9598
for ($i = $upperLimit - 1; $i >= 0; --$i) {
9699
if (isset($toFind[$diff[$i][1]])) {
97100
unset($toFind[$diff[$i][1]]);
98101
$lc = \substr($diff[$i][0], -1);
102+
99103
if ("\n" !== $lc) {
100104
\array_splice($diff, $i + 1, 0, [["\n\\ No newline at end of file\n", Differ::NO_LINE_END_EOF_WARNING]]);
101105
}
@@ -233,6 +237,7 @@ private function writeHunk(
233237
}
234238

235239
\fwrite($output, ' +' . $toStart);
240+
236241
if (!$this->collapseRanges || 1 !== $toRange) {
237242
\fwrite($output, ',' . $toRange);
238243
}

tests/Utils/FileUtils.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ final class FileUtils
1515
public static function getFileContent(string $file): string
1616
{
1717
$content = @\file_get_contents($file);
18+
1819
if (false === $content) {
1920
$error = \error_get_last();
2021

tests/Utils/UnifiedDiffAssertTrait.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function assertValidUnifiedDiffFormat(string $diff): void
2727

2828
// test diff ends with a line break
2929
$last = \substr($diff, -1);
30+
3031
if ("\n" !== $last && "\r" !== $last) {
3132
throw new \UnexpectedValueException(\sprintf('Expected diff to end with a line break, got "%s".', $last));
3233
}
@@ -130,6 +131,7 @@ public function assertValidUnifiedDiffFormat(string $diff): void
130131
}
131132

132133
$previousType = $this->unifiedDiffAssertLinePrefix($lines[$lineNumber - 2], \sprintf('Preceding line of "\\ No newline at end of file" of unexpected format. Line %d.', $lineNumber));
134+
133135
if (isset($endOfLineTypes[$previousType])) {
134136
throw new \UnexpectedValueException(\sprintf('Unexpected "\\ No newline at end of file", "%s" was already closed. Line %d.', $type, $lineNumber));
135137
}
@@ -190,6 +192,7 @@ private function unifiedDiffAssertLinePrefix(string $line, string $message): str
190192
private function unifiedDiffAssertStrLength(string $line, int $min, string $message): void
191193
{
192194
$length = \strlen($line);
195+
193196
if ($length < $min) {
194197
throw new \UnexpectedValueException(\sprintf('Expected string length of minimal %d, got %d. %s', $min, $length, $message));
195198
}

0 commit comments

Comments
 (0)