Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
93e703a
PHP 8.1: Squiz/ValidVariableName - Added tests for enums support
kukulich Nov 20, 2021
be50d27
PHP 8.1: Zend/ValidVariableName - Added tests for enums support
kukulich Nov 20, 2021
c47ca1d
PHP 8.1: Squiz/MemberVarSpacing - Added test for enums support
kukulich Nov 20, 2021
2d59398
PHP 8.1: Squiz/MethodScope - Added tests for enums support
kukulich Nov 20, 2021
45d953a
PHP 8.1: Squiz/NonExecutableCode - Added test for enums support
kukulich Nov 20, 2021
e3b93c5
PHP 8.1: Squiz/LowercaseClassKeywords - Added test for enums support
kukulich Nov 20, 2021
bbe14b0
PHP 8.1: PSR2/MethodDeclaration - Added tests for enums support
kukulich Nov 20, 2021
1e8d2b5
PHP 8.1: PSR12/UseDeclaration - Added tests for enums support
kukulich Nov 20, 2021
2df2ae2
PHP 8.1: PSR12/ConstantVisibility - Added tests for enums support
kukulich Nov 20, 2021
b8b3a5b
PHP 8.1: PSR12/ImportStatement - Added test for enums support
kukulich Nov 20, 2021
3fe3fc1
PHP 8.1: File::getDeclarationName() supports enums
kukulich Nov 20, 2021
8f4a6cf
PHP 8.1: PEAR/ValidFunctionName - Added tests for enums support
kukulich Nov 20, 2021
7e0d1e9
PHP 8.1: Generic/CamelCapsFunctionName - Added tests for enums support
kukulich Nov 20, 2021
7bd83af
PHP 8.1: Generic/DuplicateClassName - Added support for enums
kukulich Nov 20, 2021
8a74610
PHP 8.1: Generic/OpeningBraceSameLine - Added support for enums
kukulich Nov 20, 2021
ef2172b
PHP 8.1: Generic/OneObjectStructurePerFile - Added support for enums
kukulich Nov 20, 2021
c9e0144
PHP 8.1: Generic/LowerCaseKeyword - Added support for enums
kukulich Nov 20, 2021
6a32382
PHP 8.1: PEAR/ClassDeclaration - Added support for enums
kukulich Nov 20, 2021
209d417
PHP 8.1: PEAR/ClassComment - Added support for enums
kukulich Nov 20, 2021
ad369a1
PHP 8.1: PEAR/FileComment - Added support for enums
kukulich Nov 20, 2021
bc00f4c
PHP 8.1: PEAR/ValidClassName - Added support for enums
kukulich Nov 20, 2021
6c96e55
PHP 8.1: PSR12/ClosingBrace - Added support for enums
kukulich Nov 20, 2021
7beba37
PHP 8.1: PSR1/ClassDeclaration - Added support for enums
kukulich Nov 20, 2021
10d5cce
PHP 8.1: PSR1/SideEffects - Added support for enums
kukulich Nov 20, 2021
b2b38ed
PHP 8.1: PSR2/UseDeclaration - Added support for enums
kukulich Nov 20, 2021
313d9db
PHP 8.1: Squiz/ClassFileName - Added support for enums
kukulich Nov 20, 2021
ed1e5a8
PHP 8.1: Squiz/ValidClassName - Added support for enums
kukulich Nov 20, 2021
25318a9
PHP 8.1: Squiz/BlockComment - Enums should be ignored
kukulich Nov 20, 2021
18d03c4
PHP 8.1: Squiz/FileComment - Added support for enums
kukulich Nov 20, 2021
4010b60
PHP 8.1: Squiz/InlineComment - Enums should be ignored
kukulich Nov 20, 2021
a34b500
PHP 8.1: Squiz/FileExtension - Added support for enums
kukulich Nov 20, 2021
718f390
PHP 8.1: Squiz/ControlStructureSpacing - Enums should be ignored
kukulich Nov 20, 2021
b520d4b
PHP 8.1: Squiz/StaticThisUsage - Added support for enums
kukulich Nov 20, 2021
fc2c525
File::getDeclarationName(): tweak method description
jrfnl Jan 18, 2022
024c47d
Generic/DuplicateClassName: improve enum tests
jrfnl Jan 18, 2022
16d8ee6
Generic/CamelCapsFunctionName: improve enum tests
jrfnl Jan 18, 2022
d2c86ab
Generic/ValidFunctionName: improve enum tests
jrfnl Jan 18, 2022
2632099
PEAR/ValidClassName: improve enum tests
jrfnl Jan 18, 2022
37bc4e0
PSR12/UseDeclaration: improve enum tests
jrfnl Jan 18, 2022
19b5775
Squiz/InlineComment: fix enum test
jrfnl Jan 18, 2022
b1ae480
Squiz/ClassFileName: improve enum tests
jrfnl Jan 18, 2022
7494c3d
Squiz/LowercaseClassKeywords: improve enum tests
jrfnl Jan 18, 2022
32f3832
Squiz/ValidClassName: improve enum tests + bugfix
jrfnl Jan 18, 2022
b0b4add
Squiz/NonExecutableCode: minor test tweak
jrfnl Jan 18, 2022
5629985
Squiz/StaticThisUsage: improve enum tests
jrfnl Jan 18, 2022
15a0b4e
Squiz/ControlStructureSpacing: fix the enum test
jrfnl Jan 18, 2022
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
4 changes: 4 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file baseinstalldir="PHP/CodeSniffer" name="ClassCommentUnitTest.php" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.1.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.2.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.3.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.php" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FunctionCommentUnitTest.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FunctionCommentUnitTest.inc.fixed" role="test" />
Expand Down Expand Up @@ -1100,6 +1101,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<dir name="Classes">
<file baseinstalldir="PHP/CodeSniffer" name="ClassDeclarationUnitTest.1.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="ClassDeclarationUnitTest.2.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="ClassDeclarationUnitTest.3.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="ClassDeclarationUnitTest.php" role="test" />
</dir>
<dir name="Files">
Expand Down Expand Up @@ -1651,6 +1653,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.6.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.7.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.8.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.9.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.1.js" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.1.js.fixed" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.2.js" role="test" />
Expand Down Expand Up @@ -1768,6 +1771,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file baseinstalldir="PHP/CodeSniffer" name="FileExtensionUnitTest.2.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileExtensionUnitTest.3.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileExtensionUnitTest.4.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileExtensionUnitTest.5.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileExtensionUnitTest.php" role="test" />
</dir>
<dir name="Formatting">
Expand Down
7 changes: 4 additions & 3 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -1232,7 +1232,7 @@ public function getFilename()
* or NULL if the function or class is anonymous.
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified token is not of type
* T_FUNCTION, T_CLASS, T_ANON_CLASS,
* T_CLOSURE, T_TRAIT, or T_INTERFACE.
* T_CLOSURE, T_TRAIT, T_ENUM, or T_INTERFACE.
*/
public function getDeclarationName($stackPtr)
{
Expand All @@ -1246,8 +1246,9 @@ public function getDeclarationName($stackPtr)
&& $tokenCode !== T_CLASS
&& $tokenCode !== T_INTERFACE
&& $tokenCode !== T_TRAIT
&& $tokenCode !== T_ENUM
) {
throw new RuntimeException('Token type "'.$this->tokens[$stackPtr]['type'].'" is not T_FUNCTION, T_CLASS, T_INTERFACE or T_TRAIT');
throw new RuntimeException('Token type "'.$this->tokens[$stackPtr]['type'].'" is not T_FUNCTION, T_CLASS, T_INTERFACE, T_TRAIT or T_ENUM');
}

if ($tokenCode === T_FUNCTION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function process(File $phpcsFile, $stackPtr)
T_CLASS,
T_INTERFACE,
T_TRAIT,
T_ENUM,
T_NAMESPACE,
T_CLOSE_TAG,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function register()
T_CLASS,
T_INTERFACE,
T_TRAIT,
T_ENUM,
];

}//end register()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function register()
T_CLASS,
T_INTERFACE,
T_TRAIT,
T_ENUM,
];

}//end register()
Expand Down
1 change: 1 addition & 0 deletions src/Standards/Generic/Sniffs/PHP/LowerCaseKeywordSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function register()
T_ENDIF,
T_ENDSWITCH,
T_ENDWHILE,
T_ENUM,
T_EVAL,
T_EXIT,
T_EXTENDS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ interface MyInterface {}
interface YourInterface {}
trait MyTrait {}
trait YourTrait {}
enum MyEnum {}
enum YourEnum {}
class MyClass {}
interface MyInterface {}
trait MyTrait {}
?>
enum MyEnum {}
?>
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
class MyClass {}
interface MyInterface {}
trait MyTrait {}
enum MyEnum {}
?>
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ public function getWarningList($testFile='')
switch ($testFile) {
case 'DuplicateClassNameUnitTest.1.inc':
return [
8 => 1,
9 => 1,
10 => 1,
11 => 1,
12 => 1,
13 => 1,
];
break;
case 'DuplicateClassNameUnitTest.2.inc':
return [
2 => 1,
3 => 1,
4 => 1,
5 => 1,
];
break;
case 'DuplicateClassNameUnitTest.5.inc':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@ class Test_Class_Bad_G
/*some comment*/
{
}

enum Test_Enum
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@ class Test_Class_Bad_G
/*some comment*/ {

}

enum Test_Enum {

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function getErrorList()
70 => 1,
79 => 1,
90 => 1,
94 => 1,
];

}//end getErrorList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ class baz {
}

trait barTrait {

}

interface barInterface {

}
?>

enum barEnum {

}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function getErrorList()
10 => 1,
14 => 1,
18 => 1,
22 => 1,
];

}//end getErrorList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,21 @@ abstract class My_Class {
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() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public function getErrorList()
147 => 2,
158 => 1,
159 => 1,
179 => 1,
180 => 2,
183 => 1,
184 => 1,
];

return $errors;
Expand Down
3 changes: 3 additions & 0 deletions src/Standards/Generic/Tests/PHP/LowerCaseKeywordUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@ class Reading {
Public READOnly int $var;
}

EnuM Enum {
}

__HALT_COMPILER(); // An exception due to phar support.
function
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@ class Reading {
public readonly int $var;
}

enum Enum {
}

__HALT_COMPILER(); // An exception due to phar support.
function
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function getErrorList()
32 => 1,
35 => 1,
39 => 2,
42 => 1,
];

}//end getErrorList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function register()
T_CLASS,
T_INTERFACE,
T_TRAIT,
T_ENUM,
];

}//end register()
Expand Down
1 change: 1 addition & 0 deletions src/Standards/PEAR/Sniffs/Commenting/ClassCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function register()
T_CLASS,
T_INTERFACE,
T_TRAIT,
T_ENUM,
];

}//end register()
Expand Down
1 change: 1 addition & 0 deletions src/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public function process(File $phpcsFile, $stackPtr)
T_CLASS,
T_INTERFACE,
T_TRAIT,
T_ENUM,
T_FUNCTION,
T_CLOSURE,
T_PUBLIC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function register()
T_CLASS,
T_INTERFACE,
T_TRAIT,
T_ENUM,
];

}//end register()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,5 @@ if (!class_exists('ClassOpeningBraceTooMuchIndentation')) {
{
}
}

enum IncorrectBracePlacement {}
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,7 @@ if (!class_exists('ClassOpeningBraceTooMuchIndentation')) {
{
}
}

enum IncorrectBracePlacement
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function getErrorList($testFile='')
99 => 1,
104 => 1,
110 => 1,
114 => 1,
];

default:
Expand Down
10 changes: 10 additions & 0 deletions src/Standards/PEAR/Tests/Commenting/ClassCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ trait Empty_Trait_Doc
}//end trait


/**
*
*
*/
enum Empty_Enum_Doc
{

}//end enum


/**
* Sample class comment
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function getErrorList()
96 => 5,
106 => 5,
116 => 5,
126 => 5,
];

}//end getErrorList()
Expand Down
8 changes: 8 additions & 0 deletions src/Standards/PEAR/Tests/Commenting/FileCommentUnitTest.3.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

/**
* Some comment
*/
enum SomeEnum
{
}
3 changes: 3 additions & 0 deletions src/Standards/PEAR/Tests/Commenting/FileCommentUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public function getErrorList($testFile='FileCommentUnitTest.inc')
case 'FileCommentUnitTest.2.inc':
return [1 => 1];

case 'FileCommentUnitTest.3.inc':
return [1 => 1];

default:
return [];
}//end switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,25 @@ trait _Invalid_Name {}
trait ___ {}

trait Invalid__Name {}

enum Valid_Name: string {}

enum invalid_Name : String {}

enum invalid_name {}

enum Invalid_name: Int {}

enum VALID_Name {}

enum VALID_NAME {}

enum VALID_Name : int {}

enum ValidName {}

enum _Invalid_Name {}

enum ___ {}

enum Invalid__Name {}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public function getErrorList()
64 => 1,
66 => 2,
68 => 1,
72 => 1,
74 => 2,
76 => 1,
86 => 1,
88 => 2,
90 => 1,
];

}//end getErrorList()
Expand Down
Loading