Skip to content

Commit 40dd4b5

Browse files
committed
Various sniffs: add extra tests with live coding/parse errors
Includes fixing up some inline comments for sniffs which don't search for closures, but could encounter live coding. Includes one minor bug fix/defensive coding fix in the `Squiz.Commenting.ClosingDeclarationComment` sniff.
1 parent c455e1e commit 40dd4b5

26 files changed

+180
-5
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
// Intentional parse error (missing method name). This should be the only test in the file.
4+
5+
class Bar {
6+
function {
7+
parent::CallMe();
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
// Intentional parse error (missing method name).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
7+
$anon = class {
8+
public function {}
9+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
// Intentional parse error (missing method name when gathering list).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
7+
class LiveCoding {
8+
public function __construct() {}
9+
public function {}
10+
public function myMethod() {}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
// Intentional parse error (missing method name when gathering list).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
7+
$anon = class {
8+
public function __construct() {}
9+
public function {}
10+
public function myMethod() {}
11+
};

src/Standards/PEAR/Sniffs/NamingConventions/ValidFunctionNameSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
8484

8585
$methodName = $phpcsFile->getDeclarationName($stackPtr);
8686
if ($methodName === null) {
87-
// Ignore closures.
87+
// Ignore live coding.
8888
return;
8989
}
9090

@@ -182,7 +182,7 @@ protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
182182
{
183183
$functionName = $phpcsFile->getDeclarationName($stackPtr);
184184
if ($functionName === null) {
185-
// Ignore closures.
185+
// Ignore live coding.
186186
return;
187187
}
188188

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 interface name). This should be the only test in the file.
4+
5+
namespace Vendor\Package;
6+
7+
interface

src/Standards/PEAR/Tests/Commenting/ClassCommentUnitTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public function getErrorList($testFile='')
5858
163 => 1,
5959
];
6060

61+
case 'ClassCommentUnitTest.2.inc':
62+
return [
63+
7 => 1,
64+
];
65+
6166
default:
6267
return [];
6368
}//end switch
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 function name). This should be the only test in the file.
4+
5+
namespace Vendor\Package;
6+
7+
function
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
// Intentional parse error (missing method name). This should be the only test in the file.
4+
5+
namespace Vendor\Package;
6+
7+
class LiveCoding {
8+
/**
9+
* This test needs to hit the processReturn() method.
10+
*/
11+
function {
12+
return;
13+
}
14+
}

src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ public function getErrorList($testFile='')
9191
545 => 1,
9292
];
9393

94+
case 'FunctionCommentUnitTest.2.inc':
95+
return [
96+
7 => 1,
97+
];
98+
99+
case 'FunctionCommentUnitTest.3.inc':
100+
return [
101+
10 => 1,
102+
];
103+
94104
default:
95105
return [];
96106
}//end switch

0 commit comments

Comments
 (0)