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

Skip to content

Commit f507e1a

Browse files
committed
Merge branch '2.2' into 2.4
# Conflicts: # src/Fixer/Basic/BracesFixer.php # tests/Fixer/Basic/BracesFixerTest.php
2 parents 176e618 + 52b3831 commit f507e1a

2 files changed

Lines changed: 165 additions & 2 deletions

File tree

src/Fixer/Basic/BracesFixer.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ function ($item) {
370370
$nextLineCanBeIndented = false;
371371
if ($nestToken->equalsAny([';', '}'])) {
372372
$nextLineCanBeIndented = true;
373-
} elseif ($this->isCommentWithFixableIndendation($tokens, $nestIndex)) {
373+
} elseif ($this->isCommentWithFixableIndentation($tokens, $nestIndex)) {
374374
for ($i = $nestIndex; $i > $startBraceIndex; --$i) {
375375
if ($tokens[$i]->equalsAny([';', '}'])) {
376376
$nextLineCanBeIndented = true;
@@ -868,6 +868,16 @@ private function ensureWhitespaceAtIndexAndIndentMultilineComment(Tokens $tokens
868868

869869
$nextToken = $tokens[$nextTokenIndex];
870870
if ($nextToken->isComment()) {
871+
$previousToken = $tokens[$nextTokenIndex - 1];
872+
873+
// do not indent inline comments used to comment out unused code
874+
if (
875+
0 === strpos($nextToken->getContent(), '//'.$this->whitespacesConfig->getIndent())
876+
&& $previousToken->isWhitespace() && 1 === preg_match('/\R$/', $previousToken->getContent())
877+
) {
878+
return;
879+
}
880+
871881
$tokens[$nextTokenIndex] = new Token([
872882
$nextToken->getId(),
873883
preg_replace(
@@ -912,7 +922,7 @@ private function isMultilined(Tokens $tokens, $startParenthesisIndex, $endParent
912922
*
913923
* @return bool
914924
*/
915-
private function isCommentWithFixableIndendation(Tokens $tokens, $index)
925+
private function isCommentWithFixableIndentation(Tokens $tokens, $index)
916926
{
917927
if (!$tokens[$index]->isComment()) {
918928
return false;

tests/Fixer/Basic/BracesFixerTest.php

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,6 +2544,159 @@ function D() /**
25442544
}',
25452545
self::$configurationOopPositionSameLine,
25462546
],
2547+
[
2548+
'<?php
2549+
if ($foo) {
2550+
foo();
2551+
2552+
// if ($bar === \'bar\') {
2553+
// return [];
2554+
// }
2555+
} else {
2556+
bar();
2557+
}
2558+
',
2559+
],
2560+
[
2561+
'<?php
2562+
if ($foo) {
2563+
foo();
2564+
2565+
// if ($bar === \'bar\') {
2566+
// return [];
2567+
// }
2568+
} else {
2569+
bar();
2570+
}
2571+
',
2572+
],
2573+
[
2574+
'<?php
2575+
if ($foo) {
2576+
foo();
2577+
2578+
// if ($bar === \'bar\') {
2579+
// return [];
2580+
// }
2581+
'.'
2582+
$bar = \'bar\';
2583+
} else {
2584+
bar();
2585+
}
2586+
',
2587+
],
2588+
[
2589+
'<?php
2590+
if ($foo) {
2591+
foo();
2592+
2593+
// bar();
2594+
'.'
2595+
$bar = \'bar\';
2596+
} else {
2597+
bar();
2598+
}
2599+
',
2600+
],
2601+
[
2602+
'<?php
2603+
if ($foo) {
2604+
foo();
2605+
// bar();
2606+
'.'
2607+
$bar = \'bar\';
2608+
} else {
2609+
bar();
2610+
}
2611+
',
2612+
],
2613+
[
2614+
'<?php
2615+
if ($foo) {
2616+
foo();
2617+
'.'
2618+
// bar();
2619+
$bar = \'bar\';
2620+
} else {
2621+
bar();
2622+
}
2623+
',
2624+
],
2625+
[
2626+
'<?php
2627+
if ($foo) {
2628+
foo();
2629+
'.'
2630+
// bar();
2631+
} else {
2632+
bar();
2633+
}
2634+
',
2635+
],
2636+
[
2637+
'<?php
2638+
function foo()
2639+
{
2640+
$a = 1;
2641+
// we will return sth
2642+
return $a;
2643+
}
2644+
',
2645+
'<?php
2646+
function foo()
2647+
{
2648+
$a = 1;
2649+
// we will return sth
2650+
return $a;
2651+
}
2652+
',
2653+
],
2654+
[
2655+
'<?php
2656+
function foo()
2657+
{
2658+
$a = 1;
2659+
'.'
2660+
// bar();
2661+
// we will return sth
2662+
return $a;
2663+
}
2664+
',
2665+
'<?php
2666+
function foo()
2667+
{
2668+
$a = 1;
2669+
'.'
2670+
// bar();
2671+
// we will return sth
2672+
return $a;
2673+
}
2674+
',
2675+
],
2676+
[
2677+
'<?php
2678+
function foo()
2679+
{
2680+
$a = 1;
2681+
// if ($a === \'bar\') {
2682+
// return [];
2683+
// }
2684+
// we will return sth
2685+
return $a;
2686+
}
2687+
',
2688+
'<?php
2689+
function foo()
2690+
{
2691+
$a = 1;
2692+
// if ($a === \'bar\') {
2693+
// return [];
2694+
// }
2695+
// we will return sth
2696+
return $a;
2697+
}
2698+
',
2699+
],
25472700
];
25482701
}
25492702

0 commit comments

Comments
 (0)