Skip to content

Commit 6e5dc2c

Browse files
authored
Merge 9811fc5 into 0d969c9
2 parents 0d969c9 + 9811fc5 commit 6e5dc2c

File tree

5 files changed

+59
-25
lines changed

5 files changed

+59
-25
lines changed

src/Standards/Generic/Sniffs/Metrics/NestingLevelSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public function process(File $phpcsFile, $stackPtr)
5656
{
5757
$tokens = $phpcsFile->getTokens();
5858

59-
// Ignore abstract methods.
60-
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
59+
// Ignore abstract and interface methods. Bail early when live coding.
60+
if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) {
6161
return;
6262
}
6363

src/Standards/Generic/Tests/Metrics/NestingLevelUnitTest.inc renamed to src/Standards/Generic/Tests/Metrics/NestingLevelUnitTest.1.inc

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ function nestingFive()
2727
function nestingSix()
2828
{
2929
if ($condition) {
30-
echo 'hi';
31-
switch ($condition)
32-
{
30+
} else {
31+
switch ($condition) {
3332
case '1':
3433
if ($condition === '1') {
35-
if ($cond) {
34+
} elseif ($condition === '2') {
35+
do {
3636
foreach ($conds as $cond) {
3737
echo 'hi';
3838
}
39-
}
39+
} while ($cond > 5);
4040
}
4141
break;
4242
}
@@ -79,24 +79,30 @@ function nestingEleven()
7979
case '1':
8080
if ($condition === '1') {
8181
if ($cond) {
82-
switch ($cond) {
83-
case '1':
84-
if ($cond === '1') {
85-
foreach ($conds as $cond) {
86-
if ($cond === 'hi') {
87-
if ($cond !== 'bye') {
88-
echo 'hi';
89-
}
82+
try {
83+
if ( $cond === '1' ) {
84+
for ( $i = 0; $i < 10; $i ++ ) {
85+
while ($i < 5) {
86+
if ( $cond === 'hi' ) {
87+
match ( $cond ) {
88+
'hi' => 'something',
89+
};
9090
}
9191
}
9292
}
93-
break;
94-
}
93+
}
94+
} catch (Exception $e) {}
9595
}
9696
}
9797
break;
9898
}
9999
}
100100
}
101101

102-
?>
102+
abstract class AbstractClass {
103+
abstract public function sniffShouldIgnoreAbstractMethods();
104+
}
105+
106+
interface MyInterface {
107+
public function sniffShouldIgnoreInterfaceMethods();
108+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// Intentional parse error (missing opening curly bracket).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
7+
function sniffShouldBailMissingScopeOpener()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// Intentional parse error (missing closing curly bracket).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
7+
function sniffShouldBailMissingScopeCloser() {

src/Standards/Generic/Tests/Metrics/NestingLevelUnitTest.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,18 @@ final class NestingLevelUnitTest extends AbstractSniffUnitTest
2626
* The key of the array should represent the line number and the value
2727
* should represent the number of errors that should occur on that line.
2828
*
29+
* @param string $testFile The name of the test file to process.
30+
*
2931
* @return array<int, int>
3032
*/
31-
public function getErrorList()
33+
public function getErrorList($testFile='')
3234
{
33-
return [73 => 1];
35+
switch ($testFile) {
36+
case 'NestingLevelUnitTest.1.inc':
37+
return [73 => 1];
38+
default:
39+
return [];
40+
}
3441

3542
}//end getErrorList()
3643

@@ -41,14 +48,21 @@ public function getErrorList()
4148
* The key of the array should represent the line number and the value
4249
* should represent the number of warnings that should occur on that line.
4350
*
51+
* @param string $testFile The name of the test file to process.
52+
*
4453
* @return array<int, int>
4554
*/
46-
public function getWarningList()
55+
public function getWarningList($testFile='')
4756
{
48-
return [
49-
27 => 1,
50-
46 => 1,
51-
];
57+
switch ($testFile) {
58+
case 'NestingLevelUnitTest.1.inc':
59+
return [
60+
27 => 1,
61+
46 => 1,
62+
];
63+
default:
64+
return [];
65+
}
5266

5367
}//end getWarningList()
5468

0 commit comments

Comments
 (0)