Skip to content

Commit d59edc4

Browse files
rodrigoprimojrfnl
authored andcommitted
Generic/CamelCapsFunctionName: improve code coverage and remove unnecessary return
The `return;` is unnecessary as the last statement in a method. Test improvements: * Add separate test case files with live coding/parse error tests. * Add tests verifying sand safeguarding that the name of methods in interfaces is also checked. * Add tests covering the public `strict` property which can be toggled from within rulesets.
1 parent afcb7a2 commit d59edc4

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

src/Standards/Generic/Sniffs/NamingConventions/CamelCapsFunctionNameSniff.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
168168
}
169169

170170
$phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'no');
171-
return;
172171
} else {
173172
$phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes');
174173
}

src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.1.inc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,22 @@ enum Suit: string implements Colorful, CardGame {
183183
public function parseMyDSN() {}
184184
public function get_some_value() {}
185185
}
186+
187+
interface MyInterface {
188+
public function getSomeValue();
189+
public function get_some_value();
190+
}
191+
192+
class MyClass {
193+
// phpcs:set Generic.NamingConventions.CamelCapsFunctionName strict false
194+
function strictFOrmatDIsabled() {} // Ok.
195+
// phpcs:set Generic.NamingConventions.CamelCapsFunctionName strict true
196+
197+
function strictFOrmatIsENabled() {} // Not ok.
198+
}
199+
200+
// phpcs:set Generic.NamingConventions.CamelCapsFunctionName strict false
201+
function strictFOrmatDIsabled() {} // Ok.
202+
// phpcs:set Generic.NamingConventions.CamelCapsFunctionName strict true
203+
204+
function strictFOrmatIsENabled() {} // Not ok.
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+
class My_Class {
8+
public function {}
9+
}
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).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
7+
function

src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public function getErrorList($testFile='')
7676
180 => 2,
7777
183 => 1,
7878
184 => 1,
79+
189 => 1,
80+
197 => 1,
81+
204 => 1,
7982
];
8083
default:
8184
return [];

0 commit comments

Comments
 (0)