Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3fd0bda

Browse files
committed
bug #2954 NoBreakCommentFixer - Disable case sensitivity (julienfalque)
This PR was merged into the 2.4 branch. Discussion ---------- NoBreakCommentFixer - Disable case sensitivity Fixes #2948. Commits ------- fb19b7b Disable case sensitivity
2 parents 5cea194 + fb19b7b commit 3fd0bda

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

src/Fixer/ControlStructure/NoBreakCommentFixer.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ private function fixCase(Tokens $tokens, $casePosition)
133133
if (null === $commentPosition) {
134134
$this->insertCommentAt($tokens, $i);
135135
} else {
136+
$text = $this->configuration['comment_text'];
137+
138+
$tokens[$commentPosition] = new Token([
139+
$tokens[$commentPosition]->getId(),
140+
str_ireplace($text, $text, $tokens[$commentPosition]->getContent()),
141+
]);
142+
136143
$this->ensureNewLineAt($tokens, $commentPosition);
137144
}
138145
} elseif (null !== $commentPosition) {
@@ -161,7 +168,7 @@ private function isNoBreakComment(Token $token)
161168

162169
$text = $this->configuration['comment_text'];
163170

164-
return preg_match("~^((//|#)\s*$text\s*)|(/\*\*?\s*$text\s*\*/)$~", $token->getContent());
171+
return preg_match("~^((//|#)\s*$text\s*)|(/\*\*?\s*$text\s*\*/)$~i", $token->getContent());
165172
}
166173

167174
/**

tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,24 @@ public function provideTestFixCases()
834834
?>
835835
<?php }',
836836
],
837+
[
838+
'<?php
839+
switch ($foo) {
840+
case 1:
841+
foo();
842+
// no break
843+
case 2:
844+
bar();
845+
}',
846+
'<?php
847+
switch ($foo) {
848+
case 1:
849+
foo();
850+
// No break
851+
case 2:
852+
bar();
853+
}',
854+
],
837855
];
838856
}
839857

@@ -935,10 +953,17 @@ public function provideTestFixWithDifferentCommentTextCases()
935953
{
936954
$cases = $this->provideTestFixCases();
937955

956+
$replaceCommentText = function ($php) {
957+
return strtr($php, [
958+
'No break' => 'Fall-through case!',
959+
'no break' => 'fall-through case!',
960+
]);
961+
};
962+
938963
foreach ($cases as &$case) {
939-
$case[0] = str_replace('no break', 'fall-through case!', $case[0]);
964+
$case[0] = $replaceCommentText($case[0]);
940965
if (isset($case[1])) {
941-
$case[1] = str_replace('no break', 'fall-through case!', $case[1]);
966+
$case[1] = $replaceCommentText($case[1]);
942967
}
943968
}
944969

0 commit comments

Comments
 (0)