Skip to content

Commit 6a1b8ad

Browse files
SpacePossumsebastianbergmann
authored andcommitted
Fix psalm warning
1 parent 2ccf1a7 commit 6a1b8ad

File tree

5 files changed

+23
-56
lines changed

5 files changed

+23
-56
lines changed

.psalm/baseline.xml

Lines changed: 0 additions & 44 deletions
This file was deleted.

.psalm/config.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<psalm
33
totallyTyped="false"
44
cacheDirectory=".psalm/cache"
5-
errorBaseline=".psalm/baseline.xml"
65
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
76
xmlns="https://getpsalm.org/schema/config"
87
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"

src/Output/StrictUnifiedDiffOutputBuilder.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,10 @@ public function __construct(array $options = [])
7070
throw new ConfigurationException('commonLineThreshold', 'an int > 0', $options['commonLineThreshold']);
7171
}
7272

73-
foreach (['fromFile', 'toFile'] as $option) {
74-
if (!\is_string($options[$option])) {
75-
throw new ConfigurationException($option, 'a string', $options[$option]);
76-
}
77-
}
78-
79-
foreach (['fromFileDate', 'toFileDate'] as $option) {
80-
if (null !== $options[$option] && !\is_string($options[$option])) {
81-
throw new ConfigurationException($option, 'a string or <null>', $options[$option]);
82-
}
83-
}
73+
$this->assertString($options, 'fromFile');
74+
$this->assertString($options, 'toFile');
75+
$this->assertStringOrNull($options, 'fromFileDate');
76+
$this->assertStringOrNull($options, 'toFileDate');
8477

8578
$this->header = \sprintf(
8679
"--- %s%s\n+++ %s%s\n",
@@ -166,7 +159,9 @@ private function writeDiffHunks($output, array $diff): void
166159
$hunkCapture = false;
167160
$sameCount = $toRange = $fromRange = 0;
168161
$toStart = $fromStart = 1;
162+
$i = 0;
169163

164+
/** @var int $i */
170165
foreach ($diff as $i => $entry) {
171166
if (0 === $entry[1]) { // same
172167
if (false === $hunkCapture) {
@@ -312,4 +307,18 @@ private function writeHunk(
312307
//}
313308
}
314309
}
310+
311+
private function assertString(array $options, string $option): void
312+
{
313+
if (!is_string($options[$option])) {
314+
throw new ConfigurationException($option, 'a string', $options[$option]);
315+
}
316+
}
317+
318+
private function assertStringOrNull(array $options, string $option): void
319+
{
320+
if (null !== $options[$option] && !\is_string($options[$option])) {
321+
throw new ConfigurationException($option, 'a string or <null>', $options[$option]);
322+
}
323+
}
315324
}

src/Output/UnifiedDiffOutputBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ private function writeDiffHunks($output, array $diff): void
115115
$hunkCapture = false;
116116
$sameCount = $toRange = $fromRange = 0;
117117
$toStart = $fromStart = 1;
118+
$i = 0;
118119

120+
/** @var int $i */
119121
foreach ($diff as $i => $entry) {
120122
if (0 === $entry[1]) { // same
121123
if (false === $hunkCapture) {

src/Parser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ private function parseFileDiff(Diff $diff, array $lines): void
6565
{
6666
$chunks = [];
6767
$chunk = null;
68+
$diffLines = [];
6869

6970
foreach ($lines as $line) {
7071
if (\preg_match('/^@@\s+-(?P<start>\d+)(?:,\s*(?P<startrange>\d+))?\s+\+(?P<end>\d+)(?:,\s*(?P<endrange>\d+))?\s+@@/', $line, $match)) {

0 commit comments

Comments
 (0)