diff --git a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidEnumCaseSniff.php b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidEnumCaseSniff.php new file mode 100644 index 0000000000000000000000000000000000000000..7eca94a711cacc98e2d1c66b40c76e09323bbf0a --- /dev/null +++ b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidEnumCaseSniff.php @@ -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 diff --git a/tests/Drupal/NamingConventions/ValidEnumCaseUnitTest.inc b/tests/Drupal/NamingConventions/ValidEnumCaseUnitTest.inc new file mode 100644 index 0000000000000000000000000000000000000000..d1819d99d1d2295f9f1471f4bf2ab71107467708 --- /dev/null +++ b/tests/Drupal/NamingConventions/ValidEnumCaseUnitTest.inc @@ -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; +} diff --git a/tests/Drupal/NamingConventions/ValidEnumCaseUnitTest.php b/tests/Drupal/NamingConventions/ValidEnumCaseUnitTest.php new file mode 100644 index 0000000000000000000000000000000000000000..eea3216c331193c0ea88e6ca930cbbbebb96c561 --- /dev/null +++ b/tests/Drupal/NamingConventions/ValidEnumCaseUnitTest.php @@ -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