Skip to content

feat(ValidEnumCase): Add UpperCamel name sniff for enum cases #254

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

Merged
merged 1 commit into from
Jan 4, 2025
Merged
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
@@ -0,0 +1,35 @@
<?php
/**
* Enum case upper camel case sniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/

namespace Drupal\Sniffs\NamingConventions;

/**
* Checks that enum case definitions are in upper camel case.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class ValidEnumCaseSniff extends ValidClassNameSniff
{


/**
* Returns an array of tokens this test wants to listen for.
*
* @return array<int|string>
*/
public function register()
{
return [T_ENUM_CASE];

}//end register()


}//end class
8 changes: 8 additions & 0 deletions tests/Drupal/NamingConventions/ValidEnumCaseUnitTest.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

enum Test: int {
// Must not start with lower case.
case one = 1;
// Must not contain underscores.
case TWO_TEST = 2;
}
48 changes: 48 additions & 0 deletions tests/Drupal/NamingConventions/ValidEnumCaseUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Drupal\Test\NamingConventions;

use Drupal\Test\CoderSniffUnitTest;

class ValidEnumCaseUnitTest extends CoderSniffUnitTest
{


/**
* Returns the lines where errors should occur.
*
* 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 file being tested.
*
* @return array<int, int>
*/
protected function getErrorList(string $testFile): array
{
return [
5 => 1,
7 => 1,
];

}//end getErrorList()


/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
protected function getWarningList(string $testFile): array
{
return [];

}//end getWarningList()


}//end class
Loading