Skip to content

Commit c52b6ed

Browse files
committed
Code review feedback
1 parent e67fe56 commit c52b6ed

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

src/Standards/PSR12/Sniffs/ControlStructures/ControlStructureSpacingSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ public function process(File $phpcsFile, $stackPtr)
104104
$phpcsFile->fixer->beginChangeset();
105105
if ($tokens[$next]['line'] > ($tokens[$parenOpener]['line'] + 1)) {
106106
for ($i = ($parenOpener + 1); $i < $next; $i++) {
107+
if ($tokens[$next]['line'] === $tokens[$i]['line']) {
108+
break;
109+
}
110+
107111
$phpcsFile->fixer->replaceToken($i, '');
108112
}
109113
}

src/Standards/PSR12/Tests/ControlStructures/ControlStructureSpacingUnitTest.inc

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,35 @@ $expr2 &&
9999
// structure body
100100
};
101101

102-
// Ensure the sniff handles too many newlines (not just too few). This was copied from src/Standards/Squiz/Tests/ControlStructures/ForLoopDeclarationUnitTest.1.inc
102+
// Ensure the sniff handles too many newlines (not just too few).
103103
for (
104104

105105

106-
$i = 0
106+
$i = 0;
107+
$i < 10;
108+
$i++
107109

108110

109-
;
111+
) {}
110112

113+
// Ensure the sniff does not remove indentation whitespace when comments are involved.
114+
for (
111115

112-
$i < 10
113116

117+
// comment.
118+
$i = 0;
119+
$i < 10;
120+
$i++
121+
) {}
114122

115-
;
123+
// The sniff treats a comment (ie non-whitespace) as content, but only at the
124+
// start / end of the control structure. So the inner-whitespace here is
125+
// intentionally ignored by this sniff. Additionally, the comment is not indented
126+
// by this sniff when fixing.
127+
for (// comment.
116128

117129

130+
$i = 0;
131+
$i < 10;
118132
$i++
119-
120-
121133
) {}

src/Standards/PSR12/Tests/ControlStructures/ControlStructureSpacingUnitTest.inc.fixed

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,30 @@ match (
102102
// structure body
103103
};
104104

105-
// Ensure the sniff handles too many newlines (not just too few). This was copied from src/Standards/Squiz/Tests/ControlStructures/ForLoopDeclarationUnitTest.1.inc
105+
// Ensure the sniff handles too many newlines (not just too few).
106106
for (
107-
$i = 0
108-
109-
110-
;
111-
112-
113-
$i < 10
107+
$i = 0;
108+
$i < 10;
109+
$i++
110+
) {}
114111

112+
// Ensure the sniff does not remove indentation whitespace when comments are involved.
113+
for (
114+
// comment.
115+
$i = 0;
116+
$i < 10;
117+
$i++
118+
) {}
115119

116-
;
120+
// The sniff treats a comment (ie non-whitespace) as content, but only at the
121+
// start / end of the control structure. So the inner-whitespace here is
122+
// intentionally ignored by this sniff. Additionally, the comment is not indented
123+
// by this sniff when fixing.
124+
for (
125+
// comment.
117126

118127

128+
$i = 0;
129+
$i < 10;
119130
$i++
120131
) {}

src/Standards/PSR12/Tests/ControlStructures/ControlStructureSpacingUnitTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public function getErrorList()
5151
97 => 1,
5252
98 => 2,
5353
106 => 1,
54-
121 => 1,
54+
111 => 1,
55+
117 => 1,
56+
127 => 1,
5557
];
5658

5759
}//end getErrorList()

0 commit comments

Comments
 (0)