diff --git a/src/Files/File.php b/src/Files/File.php index e00ba7117b..5c86faa918 100644 --- a/src/Files/File.php +++ b/src/Files/File.php @@ -1223,7 +1223,7 @@ public function getFilename() /** - * Returns the declaration names for classes, interfaces, traits, and functions. + * Returns the declaration name for classes, interfaces, traits, enums, and functions. * * @param int $stackPtr The position of the declaration token which * declared the class, interface, trait, or function. diff --git a/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.1.inc b/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.1.inc index 38ddef181e..91ab9d3975 100644 --- a/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.1.inc +++ b/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.1.inc @@ -4,8 +4,9 @@ class YourClass {} interface MyInterface {} interface YourInterface {} trait MyTrait {} -enum MyEnum {} trait YourTrait {} +enum MyEnum {} +enum YourEnum {} class MyClass {} interface MyInterface {} trait MyTrait {} diff --git a/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.2.inc b/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.2.inc index e6f92eb130..6829748a5f 100644 --- a/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.2.inc +++ b/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.2.inc @@ -2,4 +2,5 @@ class MyClass {} interface MyInterface {} trait MyTrait {} +enum MyEnum {} ?> \ No newline at end of file diff --git a/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.php b/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.php index 6caaf873c3..05546e7052 100644 --- a/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.php +++ b/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.php @@ -45,10 +45,10 @@ public function getWarningList($testFile='') switch ($testFile) { case 'DuplicateClassNameUnitTest.1.inc': return [ - 9 => 1, 10 => 1, 11 => 1, 12 => 1, + 13 => 1, ]; break; case 'DuplicateClassNameUnitTest.2.inc': @@ -56,6 +56,7 @@ public function getWarningList($testFile='') 2 => 1, 3 => 1, 4 => 1, + 5 => 1, ]; break; case 'DuplicateClassNameUnitTest.5.inc': diff --git a/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.inc b/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.inc index f9a9885b3a..8441060d27 100644 --- a/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.inc +++ b/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.inc @@ -166,7 +166,20 @@ abstract class My_Class { public function _MY_CLASS() {} } -enum My_Enum { - public function my_class() {} - public function _MY_CLASS() {} +enum Suit: string implements Colorful, CardGame { + // Magic methods. + function __call($name, $args) {} + static function __callStatic($name, $args) {} + function __invoke() {} + + // Valid Method Name. + public function getSomeValue() {} + + // Double underscore non-magic methods not allowed. + function __myFunction() {} + function __my_function() {} + + // Non-camelcase. + public function parseMyDSN() {} + public function get_some_value() {} } diff --git a/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.php b/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.php index 839c30243e..3d0320c3ae 100644 --- a/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.php +++ b/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.php @@ -63,8 +63,10 @@ public function getErrorList() 147 => 2, 158 => 1, 159 => 1, - 170 => 1, - 171 => 1, + 179 => 1, + 180 => 2, + 183 => 1, + 184 => 1, ]; return $errors; diff --git a/src/Standards/PEAR/Tests/NamingConventions/ValidClassNameUnitTest.inc b/src/Standards/PEAR/Tests/NamingConventions/ValidClassNameUnitTest.inc index bc0e92a1d5..053a4fee2f 100644 --- a/src/Standards/PEAR/Tests/NamingConventions/ValidClassNameUnitTest.inc +++ b/src/Standards/PEAR/Tests/NamingConventions/ValidClassNameUnitTest.inc @@ -67,19 +67,19 @@ trait ___ {} trait Invalid__Name {} -enum Valid_Name {} +enum Valid_Name: string {} -enum invalid_Name {} +enum invalid_Name : String {} enum invalid_name {} -enum Invalid_name {} +enum Invalid_name: Int {} enum VALID_Name {} enum VALID_NAME {} -enum VALID_Name {} +enum VALID_Name : int {} enum ValidName {} diff --git a/src/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.inc b/src/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.inc index e89aea6078..18b1a48176 100644 --- a/src/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.inc +++ b/src/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.inc @@ -221,7 +221,23 @@ abstract class My_Class { public function _MY_CLASS() {} } -enum My_Enum { - public function my_class() {} - public function _MY_CLASS() {} +enum Suit: string implements Colorful, CardGame { + // Magic methods. + function __call($name, $args) {} + static function __callStatic($name, $args) {} + function __invoke() {} + + // Valid Method Name. + public function parseMyDSN() {} + private function _getAnotherValue() {} + + // Double underscore non-magic methods not allowed. + function __myFunction() {} + function __my_function() {} + + // Non-camelcase. + public function get_some_value() {} + + // Private without underscore prefix. + private function getMe() {} } diff --git a/src/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.php b/src/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.php index 26f9775bcb..4639a1e2ab 100644 --- a/src/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.php +++ b/src/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.php @@ -122,8 +122,10 @@ public function getErrorList() 212 => 1, 213 => 1, 214 => 1, - 225 => 1, - 226 => 2, + 235 => 1, + 236 => 2, + 239 => 1, + 242 => 1, ]; }//end getErrorList() diff --git a/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.inc b/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.inc index c3cc6348a1..c8ad746a73 100644 --- a/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.inc +++ b/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.inc @@ -215,6 +215,7 @@ enum SomeEnum1 enum SomeEnum2 { - use FirstTrait; + + use FirstTrait; } diff --git a/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.php b/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.php index 196fbc49c7..797a2912e7 100644 --- a/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.php +++ b/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.php @@ -47,7 +47,7 @@ public function getErrorList() 165 => 1, 170 => 1, 208 => 1, - 218 => 1, + 219 => 3, ]; }//end getErrorList() diff --git a/src/Standards/Squiz/Sniffs/Classes/ValidClassNameSniff.php b/src/Standards/Squiz/Sniffs/Classes/ValidClassNameSniff.php index 8d45c86e0c..ffddd2cde7 100644 --- a/src/Standards/Squiz/Sniffs/Classes/ValidClassNameSniff.php +++ b/src/Standards/Squiz/Sniffs/Classes/ValidClassNameSniff.php @@ -59,7 +59,7 @@ public function process(File $phpcsFile, $stackPtr) // starting with the number will be multiple tokens. $opener = $tokens[$stackPtr]['scope_opener']; $nameStart = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), $opener, true); - $nameEnd = $phpcsFile->findNext(T_WHITESPACE, $nameStart, $opener); + $nameEnd = $phpcsFile->findNext([T_WHITESPACE, T_COLON], $nameStart, $opener); if ($nameEnd === false) { $name = $tokens[$nameStart]['content']; } else { diff --git a/src/Standards/Squiz/Tests/Classes/ClassFileNameUnitTest.inc b/src/Standards/Squiz/Tests/Classes/ClassFileNameUnitTest.inc index 204374f396..8b5a5aa708 100644 --- a/src/Standards/Squiz/Tests/Classes/ClassFileNameUnitTest.inc +++ b/src/Standards/Squiz/Tests/Classes/ClassFileNameUnitTest.inc @@ -6,7 +6,7 @@ class ClassFileNameUnitTest {} interface ClassFileNameUnitTest {} trait ClassFileNameUnitTest {} enum ClassFileNameUnitTest {} - +enum ClassFileNameUnitTest: int {} // Invalid filename matching class name (case sensitive). class classFileNameUnitTest {} diff --git a/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.inc b/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.inc index 758fcaf2a8..ea8cd89ec5 100644 --- a/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.inc +++ b/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.inc @@ -3,7 +3,7 @@ Abstract Class MyClass Extends MyClass {} Final Class MyClass Implements MyInterface {} Interface MyInterface {} Trait MyTrait {} -Enum MyEnum {} +Enum MyEnum IMPLEMENTS Colorful {} class MyClass { diff --git a/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.inc.fixed b/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.inc.fixed index fad6c7c5a2..f573905217 100644 --- a/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.inc.fixed +++ b/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.inc.fixed @@ -3,7 +3,7 @@ abstract class MyClass extends MyClass {} final class MyClass implements MyInterface {} interface MyInterface {} trait MyTrait {} -enum MyEnum {} +enum MyEnum implements Colorful {} class MyClass { diff --git a/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.php b/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.php index 47e4b3da4f..8c4d10c79a 100644 --- a/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.php +++ b/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.php @@ -30,7 +30,7 @@ public function getErrorList() 3 => 3, 4 => 1, 5 => 1, - 6 => 1, + 6 => 2, 10 => 1, 11 => 1, 14 => 1, diff --git a/src/Standards/Squiz/Tests/Classes/ValidClassNameUnitTest.inc b/src/Standards/Squiz/Tests/Classes/ValidClassNameUnitTest.inc index 62a769a034..3fe39435b4 100644 --- a/src/Standards/Squiz/Tests/Classes/ValidClassNameUnitTest.inc +++ b/src/Standards/Squiz/Tests/Classes/ValidClassNameUnitTest.inc @@ -138,7 +138,7 @@ trait Base } // Valid enum name. -enum ValidCamelCaseClass {} +enum ValidCamelCaseClass: string {} // Incorrect usage of camel case. @@ -147,22 +147,22 @@ enum Invalid_Camel_Case_Class_With_Underscores {} // All lowercase. -enum invalidlowercaseclass {} +enum invalidlowercaseclass: INT {} enum invalid_lowercase_class_with_underscores {} // All uppercase. -enum VALIDUPPERCASECLASS {} +enum VALIDUPPERCASECLASS: int {} enum INVALID_UPPERCASE_CLASS_WITH_UNDERSCORES {} // Mix camel case with uppercase. -enum ValidCamelCaseClassWithUPPERCASE {} +enum ValidCamelCaseClassWithUPPERCASE : string {} // Usage of numeric characters. enum ValidCamelCaseClassWith1Number {} -enum ValidCamelCaseClassWith12345Numbers {} +enum ValidCamelCaseClassWith12345Numbers : string {} enum ValidCamelCaseClassEndingWithNumber5 {} enum Testing{} diff --git a/src/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc b/src/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc index 081bd7fa8f..10a0b4b4c6 100644 --- a/src/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc +++ b/src/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc @@ -165,6 +165,14 @@ final class MyClass final public function test() {} } +/** + * Comment should be ignored. + * + */ +enum MyEnum { + +} + /* * N.B.: The below test line must be the last test in the file. * Testing that a new line after an inline comment when it's the last non-whitespace @@ -173,11 +181,3 @@ final class MyClass */ // For this test line having an empty line below it, is fine. - -/** - * Comment should be ignored. - * - */ -enum MyEnum { - -} diff --git a/src/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc.fixed b/src/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc.fixed index 07e6bf6240..97ae01490d 100644 --- a/src/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc.fixed +++ b/src/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc.fixed @@ -158,6 +158,14 @@ final class MyClass final public function test() {} } +/** + * Comment should be ignored. + * + */ +enum MyEnum { + +} + /* * N.B.: The below test line must be the last test in the file. * Testing that a new line after an inline comment when it's the last non-whitespace @@ -166,11 +174,3 @@ final class MyClass */ // For this test line having an empty line below it, is fine. - -/** - * Comment should be ignored. - * - */ -enum MyEnum { - -} diff --git a/src/Standards/Squiz/Tests/PHP/NonExecutableCodeUnitTest.2.inc b/src/Standards/Squiz/Tests/PHP/NonExecutableCodeUnitTest.2.inc index 6435bd0663..c9bf052f34 100644 --- a/src/Standards/Squiz/Tests/PHP/NonExecutableCodeUnitTest.2.inc +++ b/src/Standards/Squiz/Tests/PHP/NonExecutableCodeUnitTest.2.inc @@ -46,9 +46,9 @@ trait Something { } enum Something { - function getReturnType() { - echo 'no error'; - } + function getReturnType() { + echo 'no error'; + } } $a = new class { diff --git a/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.inc b/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.inc index 13bb44f1fe..dd6530e802 100644 --- a/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.inc +++ b/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.inc @@ -117,6 +117,10 @@ $b = new class() } enum MyEnum { + private function notStatic () { + $this->doSomething(); + } + public static function myFunc() { $this->doSomething(); } diff --git a/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.php b/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.php index 36d833903a..b1a5dd6afd 100644 --- a/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.php +++ b/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.php @@ -38,7 +38,7 @@ public function getErrorList() 80 => 1, 84 => 1, 99 => 1, - 121 => 1, + 125 => 1, ]; }//end getErrorList() diff --git a/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc b/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc index dbab24be1d..70abae434d 100644 --- a/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc +++ b/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc @@ -262,6 +262,8 @@ $expr = match( $foo ){ }; echo $expr; -enum SomeEnum -{ +if($true) { + + enum SomeEnum {} + } diff --git a/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc.fixed b/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc.fixed index 4a655dc916..c64de25e16 100644 --- a/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc.fixed +++ b/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc.fixed @@ -254,6 +254,8 @@ $expr = match($foo){ echo $expr; -enum SomeEnum -{ +if($true) { + + enum SomeEnum {} + }