File tree Expand file tree Collapse file tree
src/Fixer/ControlStructure
tests/Fixer/ControlStructure Expand file tree Collapse file tree Original file line number Diff line number Diff 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 /**
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments