Skip to content
Snippets Groups Projects
Unverified Commit 338469ee authored by Klaus Purer's avatar Klaus Purer Committed by GitHub
Browse files

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

parent bba74b37
No related branches found
No related tags found
No related merge requests found
<?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
<?php
enum Test: int {
// Must not start with lower case.
case one = 1;
// Must not contain underscores.
case TWO_TEST = 2;
}
<?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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment