Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic/CamelCapsFunctionName: improve code coverage #642

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop

$methodName = $phpcsFile->getDeclarationName($stackPtr);
if ($methodName === null) {
// Ignore closures.
return;
}

Expand Down Expand Up @@ -150,7 +149,7 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
return;
}

// Ignore first underscore in methods prefixed with "_".
// Ignore leading underscores in the method name.
$methodName = ltrim($methodName, '_');

$methodProps = $phpcsFile->getMethodProperties($stackPtr);
Expand All @@ -168,7 +167,6 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
}

$phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'no');
return;
} else {
$phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes');
}
Expand All @@ -189,7 +187,6 @@ protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
{
$functionName = $phpcsFile->getDeclarationName($stackPtr);
if ($functionName === null) {
// Ignore closures.
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,22 @@ enum Suit: string implements Colorful, CardGame {
public function parseMyDSN() {}
public function get_some_value() {}
}

interface MyInterface {
function getSomeValue(); // Ok.
function get_some_value(); // Not ok.
}

class MyClass {
// phpcs:set Generic.NamingConventions.CamelCapsFunctionName strict false
function strictFOrmatDIsabled() {} // Ok.
// phpcs:set Generic.NamingConventions.CamelCapsFunctionName strict true

function strictFOrmatIsENabled() {} // Not ok.
}

// phpcs:set Generic.NamingConventions.CamelCapsFunctionName strict false
function strictFOrmatDIsabled() {} // Ok.
// phpcs:set Generic.NamingConventions.CamelCapsFunctionName strict true

function strictFOrmatIsENabled() {} // Not ok.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

// Intentional parse error (missing method name).
// This should be the only test in this file.
// Testing that the sniff is *not* triggered.

class My_Class {
public function {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Intentional parse error (missing function name).
// This should be the only test in this file.
// Testing that the sniff is *not* triggered.

function
Original file line number Diff line number Diff line change
Expand Up @@ -26,55 +26,63 @@ final class CamelCapsFunctionNameUnitTest extends AbstractSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @param string $testFile The name of the test file to process.
*
* @return array<int, int>
*/
public function getErrorList()
public function getErrorList($testFile='')
{
$errors = [
10 => 1,
11 => 1,
12 => 1,
13 => 1,
16 => 1,
17 => 1,
20 => 1,
21 => 1,
24 => 1,
25 => 1,
30 => 1,
31 => 1,
50 => 1,
52 => 1,
53 => 2,
57 => 1,
58 => 1,
59 => 1,
60 => 1,
61 => 1,
62 => 1,
63 => 1,
64 => 1,
65 => 1,
66 => 1,
67 => 1,
68 => 2,
69 => 1,
71 => 1,
72 => 1,
73 => 2,
118 => 1,
144 => 1,
146 => 1,
147 => 2,
158 => 1,
159 => 1,
179 => 1,
180 => 2,
183 => 1,
184 => 1,
];

return $errors;
switch ($testFile) {
case 'CamelCapsFunctionNameUnitTest.1.inc':
return[
10 => 1,
11 => 1,
12 => 1,
13 => 1,
16 => 1,
17 => 1,
20 => 1,
21 => 1,
24 => 1,
25 => 1,
30 => 1,
31 => 1,
50 => 1,
52 => 1,
53 => 2,
57 => 1,
58 => 1,
59 => 1,
60 => 1,
61 => 1,
62 => 1,
63 => 1,
64 => 1,
65 => 1,
66 => 1,
67 => 1,
68 => 2,
69 => 1,
71 => 1,
72 => 1,
73 => 2,
118 => 1,
144 => 1,
146 => 1,
147 => 2,
158 => 1,
159 => 1,
179 => 1,
180 => 2,
183 => 1,
184 => 1,
189 => 1,
197 => 1,
204 => 1,
];
default:
return [];
}//end switch

}//end getErrorList()

Expand Down