Skip to content

Commit c0bd2bb

Browse files
jrfnlgsherwood
andauthored
Removed all parse error warnings from sniffs (#990)
* Removed all parse error warnings from sniffs Ref: * squizlabs/PHP_CodeSniffer 2455 --------- Co-authored-by: Greg Sherwood <[email protected]> Co-authored-by: jrfnl <[email protected]>
1 parent 97c10e9 commit c0bd2bb

20 files changed

+22
-55
lines changed

src/Standards/Generic/Sniffs/Classes/OpeningBraceSameLineSniff.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ public function process(File $phpcsFile, $stackPtr)
4949
$errorData = [strtolower($tokens[$stackPtr]['content']).' '.$tokens[$scopeIdentifier]['content']];
5050

5151
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
52-
$error = 'Possible parse error: %s missing opening or closing brace';
53-
$phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $errorData);
52+
// Parse error or live coding.
5453
return;
5554
}
5655

src/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Test_Class_Bad_H extends Test_Class_Bad_G {
4747
class Test_Class_Bad_I implements Test_Interface_Bad_C{
4848
}
4949

50-
// This one should be flagged as a potential parse error.
50+
// This one should be ignored as a potential parse error.
5151
class Test_Class_Bad_H
5252

5353
// This is OK.

src/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.inc.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Test_Class_Bad_H extends Test_Class_Bad_G {
4747
class Test_Class_Bad_I implements Test_Interface_Bad_C {
4848
}
4949

50-
// This one should be flagged as a potential parse error.
50+
// This one should be ignored as a potential parse error.
5151
class Test_Class_Bad_H
5252

5353
// This is OK.

src/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function getErrorList()
6060
*/
6161
public function getWarningList()
6262
{
63-
return [51 => 1];
63+
return [];
6464

6565
}//end getWarningList()
6666

src/Standards/PEAR/Sniffs/Classes/ClassDeclarationSniff.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ public function process(File $phpcsFile, $stackPtr)
4848
$errorData = [strtolower($tokens[$stackPtr]['content'])];
4949

5050
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
51-
$error = 'Possible parse error: %s missing opening or closing brace';
52-
$phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $errorData);
51+
// Parse error or live coding.
5352
return;
5453
}
5554

src/Standards/PEAR/Tests/Classes/ClassDeclarationUnitTest.2.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ if (!class_exists('ClassOpeningBraceTabIndented')) {
77
}
88

99

10-
// Needs to be last test in the file. Intentional parse error.
10+
// Needs to be last test in the file. Intentional parse error. Should be ignored.
1111
class MyParseError extends Exception

src/Standards/PEAR/Tests/Classes/ClassDeclarationUnitTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ public function getErrorList($testFile='')
8888
*/
8989
public function getWarningList($testFile='')
9090
{
91-
if ($testFile === 'ClassDeclarationUnitTest.2.inc') {
92-
return [11 => 1];
93-
}
94-
9591
return[];
9692

9793
}//end getWarningList()

src/Standards/Squiz/Sniffs/Classes/ValidClassNameSniff.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ public function process(File $phpcsFile, $stackPtr)
4949
$tokens = $phpcsFile->getTokens();
5050

5151
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
52-
$error = 'Possible parse error: %s missing opening or closing brace';
53-
$data = [$tokens[$stackPtr]['content']];
54-
$phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $data);
52+
// Parse error or live coding.
5553
return;
5654
}
5755

src/Standards/Squiz/Sniffs/Commenting/ClosingDeclarationCommentSniff.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ public function process(File $phpcsFile, $stackPtr)
6262
}
6363

6464
if (isset($tokens[$stackPtr]['scope_closer']) === false) {
65-
$error = 'Possible parse error: non-abstract method defined as abstract';
66-
$phpcsFile->addWarning($error, $stackPtr, 'Abstract');
65+
// Parse error or live coding.
6766
return;
6867
}
6968

@@ -80,9 +79,7 @@ public function process(File $phpcsFile, $stackPtr)
8079
}//end if
8180

8281
if (isset($tokens[$stackPtr]['scope_closer']) === false) {
83-
$error = 'Possible parse error: %s missing opening or closing brace';
84-
$data = [$tokens[$stackPtr]['content']];
85-
$phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $data);
82+
// Parse error or live coding.
8683
return;
8784
}
8885

src/Standards/Squiz/Sniffs/ControlStructures/ForEachLoopDeclarationSniff.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,12 @@ public function process(File $phpcsFile, $stackPtr)
5959

6060
$openingBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr);
6161
if ($openingBracket === false) {
62-
$error = 'Possible parse error: FOREACH has no opening parenthesis';
63-
$phpcsFile->addWarning($error, $stackPtr, 'MissingOpenParenthesis');
62+
// Parse error or live coding.
6463
return;
6564
}
6665

6766
if (isset($tokens[$openingBracket]['parenthesis_closer']) === false) {
68-
$error = 'Possible parse error: FOREACH has no closing parenthesis';
69-
$phpcsFile->addWarning($error, $stackPtr, 'MissingCloseParenthesis');
67+
// Parse error or live coding.
7068
return;
7169
}
7270

@@ -134,8 +132,7 @@ public function process(File $phpcsFile, $stackPtr)
134132

135133
$asToken = $phpcsFile->findNext(T_AS, $openingBracket);
136134
if ($asToken === false) {
137-
$error = 'Possible parse error: FOREACH has no AS statement';
138-
$phpcsFile->addWarning($error, $stackPtr, 'MissingAs');
135+
// Parse error or live coding.
139136
return;
140137
}
141138

src/Standards/Squiz/Sniffs/ControlStructures/ForLoopDeclarationSniff.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ public function process(File $phpcsFile, $stackPtr)
6767

6868
$openingBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr);
6969
if ($openingBracket === false || isset($tokens[$openingBracket]['parenthesis_closer']) === false) {
70-
$error = 'Possible parse error: no opening/closing parenthesis for FOR keyword';
71-
$phpcsFile->addWarning($error, $stackPtr, 'NoOpenBracket');
70+
// Parse error or live coding.
7271
return;
7372
}
7473

src/Standards/Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ public function process(File $phpcsFile, $stackPtr)
123123
}
124124

125125
if (isset($tokens[$nextCase]['scope_opener']) === false) {
126-
$error = 'Possible parse error: CASE missing opening colon';
127-
$phpcsFile->addWarning($error, $nextCase, 'MissingColon');
126+
// Parse error or live coding.
128127
continue;
129128
}
130129

src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.1.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ interface TestClass
6868

6969
class MyClass
7070
{
71-
public function myFunction();
71+
public function parseErrorMustBeIgnored();
7272
}//end class
7373

7474
// Closures don't need end comments.

src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.1.inc.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ interface TestClass
6868

6969
class MyClass
7070
{
71-
public function myFunction();
71+
public function parseErrorMustBeIgnored();
7272
}//end class
7373

7474
// Closures don't need end comments.

src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.2.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
// Intentional parse error (missing opening bracket).
44
// This should be the only test in this file.
5-
// Testing that the sniff is triggered.
5+
// Testing that the sniff stays silent.
66

77
class MissingOpeningBracket

src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.3.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
// Intentional parse error (missing closing bracket).
44
// This should be the only test in this file.
5-
// Testing that the sniff is triggered.
5+
// Testing that the sniff stays silent.
66

77
class MissingClosingBracket {

src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,7 @@ public function getErrorList($testFile='')
7878
*/
7979
public function getWarningList($testFile='')
8080
{
81-
switch ($testFile) {
82-
case 'ClosingDeclarationCommentUnitTest.1.inc':
83-
return [71 => 1];
84-
85-
case 'ClosingDeclarationCommentUnitTest.2.inc':
86-
case 'ClosingDeclarationCommentUnitTest.3.inc':
87-
return [7 => 1];
88-
89-
default:
90-
return [];
91-
}
81+
return [];
9282

9383
}//end getWarningList()
9484

src/Standards/Squiz/Tests/ControlStructures/ForLoopDeclarationUnitTest.2.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
// Parse error/live coding test (no parentheses).
44
// This test has to be the only test in the file!
5-
// Testing the "NoOpenBracket" warning.
5+
// This should be ignored.
66
for

src/Standards/Squiz/Tests/ControlStructures/ForLoopDeclarationUnitTest.3.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
// Parse error/live coding test (no close parenthesis).
44
// This test has to be the only test in the file!
5-
// Testing the "NoOpenBracket" warning.
5+
// This should be ignored.
66
for ($i = 10;

src/Standards/Squiz/Tests/ControlStructures/ForLoopDeclarationUnitTest.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,7 @@ public function getErrorList($testFile='')
8686
*/
8787
public function getWarningList($testFile='')
8888
{
89-
switch ($testFile) {
90-
case 'ForLoopDeclarationUnitTest.2.inc':
91-
case 'ForLoopDeclarationUnitTest.3.inc':
92-
return [6 => 1];
93-
94-
default:
95-
return [];
96-
}//end switch
89+
return [];
9790

9891
}//end getWarningList()
9992

0 commit comments

Comments
 (0)