File tree Expand file tree Collapse file tree 3 files changed +91
-0
lines changed
coder_sniffer/Drupal/Sniffs/NamingConventions
tests/Drupal/NamingConventions Expand file tree Collapse file tree 3 files changed +91
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Enum case upper camel case sniff.
4+ *
5+ * @category PHP
6+ * @package PHP_CodeSniffer
7+ * @link http://pear.php.net/package/PHP_CodeSniffer
8+ */
9+
10+ namespace Drupal \Sniffs \NamingConventions ;
11+
12+ /**
13+ * Checks that enum case definitions are in upper camel case.
14+ *
15+ * @category PHP
16+ * @package PHP_CodeSniffer
17+ * @link http://pear.php.net/package/PHP_CodeSniffer
18+ */
19+ class ValidEnumCaseSniff extends ValidClassNameSniff
20+ {
21+
22+
23+ /**
24+ * Returns an array of tokens this test wants to listen for.
25+ *
26+ * @return array<int|string>
27+ */
28+ public function register ()
29+ {
30+ return [T_ENUM_CASE ];
31+
32+ }//end register()
33+
34+
35+ }//end class
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ enum Test: int {
4+ // Must not start with lower case.
5+ case one = 1 ;
6+ // Must not contain underscores.
7+ case TWO_TEST = 2 ;
8+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Drupal \Test \NamingConventions ;
4+
5+ use Drupal \Test \CoderSniffUnitTest ;
6+
7+ class ValidEnumCaseUnitTest extends CoderSniffUnitTest
8+ {
9+
10+
11+ /**
12+ * Returns the lines where errors should occur.
13+ *
14+ * The key of the array should represent the line number and the value
15+ * should represent the number of errors that should occur on that line.
16+ *
17+ * @param string $testFile The name of the file being tested.
18+ *
19+ * @return array<int, int>
20+ */
21+ protected function getErrorList (string $ testFile ): array
22+ {
23+ return [
24+ 5 => 1 ,
25+ 7 => 1 ,
26+ ];
27+
28+ }//end getErrorList()
29+
30+
31+ /**
32+ * Returns the lines where warnings should occur.
33+ *
34+ * The key of the array should represent the line number and the value
35+ * should represent the number of warnings that should occur on that line.
36+ *
37+ * @param string $testFile The name of the file being tested.
38+ *
39+ * @return array<int, int>
40+ */
41+ protected function getWarningList (string $ testFile ): array
42+ {
43+ return [];
44+
45+ }//end getWarningList()
46+
47+
48+ }//end class
You can’t perform that action at this time.
0 commit comments