Skip to content

Commit 30a5eb0

Browse files
committed
Merge branch 'master' into 3.0
2 parents cb2b5bf + 71945d9 commit 30a5eb0

File tree

7 files changed

+89
-12
lines changed

7 files changed

+89
-12
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
104104
-- Thanks to Jason McCreary for the patch
105105
- Fixed bug #1101 : Incorrect indent errors when breaking out of PHP inside an IF statement
106106
- Fixed bug #1102 : Squiz.Formatting.OperatorBracket.MissingBrackets faulty bracketing fix
107+
- Fixed bug #1109 : Wrong scope indent reported in anonymous class
107108
- Fixed bug #1112 : File docblock not recognized when require_once follows it
108109
</notes>
109110
<contents>

src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function register()
126126
*/
127127
public function process(File $phpcsFile, $stackPtr)
128128
{
129-
$debug = Config::getConfigData('scope_indentdebug');
129+
$debug = Config::getConfigData('scope_indent_debug');
130130
if ($debug !== null) {
131131
$this->debug = (bool) $debug;
132132
}
@@ -962,22 +962,24 @@ public function process(File $phpcsFile, $stackPtr)
962962
continue;
963963
}//end if
964964

965-
// Closures set the indent based on their own indent level.
966-
if ($tokens[$i]['code'] === T_CLOSURE) {
965+
// Anon classes and functions set the indent based on their own indent level.
966+
if ($tokens[$i]['code'] === T_CLOSURE || $tokens[$i]['code'] === T_ANON_CLASS) {
967967
$closer = $tokens[$i]['scope_closer'];
968968
if ($tokens[$i]['line'] === $tokens[$closer]['line']) {
969969
if ($this->debug === true) {
970+
$type = str_replace('_', ' ', strtolower(substr($tokens[$i]['type'], 2)));
970971
$line = $tokens[$i]['line'];
971-
echo "* ignoring single-line closure on line $line".PHP_EOL;
972+
echo "* ignoring single-line $type on line $line".PHP_EOL;
972973
}
973974

974975
$i = $closer;
975976
continue;
976977
}
977978

978979
if ($this->debug === true) {
980+
$type = str_replace('_', ' ', strtolower(substr($tokens[$i]['type'], 2)));
979981
$line = $tokens[$i]['line'];
980-
echo "Open closure on line $line".PHP_EOL;
982+
echo "Open $type on line $line".PHP_EOL;
981983
}
982984

983985
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $i, true);
@@ -1078,14 +1080,16 @@ public function process(File $phpcsFile, $stackPtr)
10781080
continue;
10791081
}//end if
10801082

1081-
// Closing a closure.
1083+
// Closing an anon class or function.
10821084
if (isset($tokens[$i]['scope_condition']) === true
10831085
&& $tokens[$i]['scope_closer'] === $i
1084-
&& $tokens[$tokens[$i]['scope_condition']]['code'] === T_CLOSURE
1086+
&& ($tokens[$tokens[$i]['scope_condition']]['code'] === T_CLOSURE
1087+
|| $tokens[$tokens[$i]['scope_condition']]['code'] === T_ANON_CLASS)
10851088
) {
10861089
if ($this->debug === true) {
1090+
$type = str_replace('_', ' ', strtolower(substr($tokens[$tokens[$i]['scope_condition']]['type'], 2)));
10871091
$line = $tokens[$i]['line'];
1088-
echo "Close closure on line $line".PHP_EOL;
1092+
echo "Close $type on line $line".PHP_EOL;
10891093
}
10901094

10911095
$prev = false;

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,24 @@ if (somethingIsTrue()) {
11171117
<?php
11181118
}
11191119

1120+
$foo = [
1121+
new class() implements Bar {
1122+
1123+
public static function foo(): string
1124+
{
1125+
return 'foo';
1126+
}
1127+
},
1128+
];
1129+
1130+
$foo = [
1131+
function () {
1132+
if ($foo) {
1133+
return 'foo';
1134+
}
1135+
},
1136+
];
1137+
11201138
$foo = foo(
11211139
function () {
11221140
$foo->debug(

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,24 @@ if (somethingIsTrue()) {
11171117
<?php
11181118
}
11191119

1120+
$foo = [
1121+
new class() implements Bar {
1122+
1123+
public static function foo(): string
1124+
{
1125+
return 'foo';
1126+
}
1127+
},
1128+
];
1129+
1130+
$foo = [
1131+
function () {
1132+
if ($foo) {
1133+
return 'foo';
1134+
}
1135+
},
1136+
];
1137+
11201138
$foo = foo(
11211139
function () {
11221140
$foo->debug(

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,24 @@ if (somethingIsTrue()) {
11171117
<?php
11181118
}
11191119

1120+
$foo = [
1121+
new class() implements Bar {
1122+
1123+
public static function foo(): string
1124+
{
1125+
return 'foo';
1126+
}
1127+
},
1128+
];
1129+
1130+
$foo = [
1131+
function () {
1132+
if ($foo) {
1133+
return 'foo';
1134+
}
1135+
},
1136+
];
1137+
11201138
$foo = foo(
11211139
function () {
11221140
$foo->debug(

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc.fixed

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,24 @@ if (somethingIsTrue()) {
11171117
<?php
11181118
}
11191119

1120+
$foo = [
1121+
new class() implements Bar {
1122+
1123+
public static function foo(): string
1124+
{
1125+
return 'foo';
1126+
}
1127+
},
1128+
];
1129+
1130+
$foo = [
1131+
function () {
1132+
if ($foo) {
1133+
return 'foo';
1134+
}
1135+
},
1136+
];
1137+
11201138
$foo = foo(
11211139
function () {
11221140
$foo->debug(

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc')
138138
823 => 1,
139139
858 => 1,
140140
879 => 1,
141-
1125 => 1,
142-
1133 => 1,
143-
1138 => 1,
144-
1140 => 1,
145141
1143 => 1,
142+
1151 => 1,
143+
1156 => 1,
144+
1158 => 1,
145+
1161 => 1,
146146
);
147147

148148
}//end getErrorList()

0 commit comments

Comments
 (0)