PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
Generic.Files.ExecutableFile
Generic.Files.LowercasedFilename
Generic.Files.LineEndings
Generic.Files.EndFileNewline
Generic.Files.EndFileNoNewline
Generic.PHP.ClosingPHPTag
Generic.PHP.Syntax
Generic.VersionControl.GitMergeConflict
Generic.WhiteSpace.DisallowSpaceIndent
Generic.WhiteSpace.DisallowTabIndent
T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG
and T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG
are unsuedT_BITWISE_AND
for all PHP versionsFile::getMethodParameters()
no longer incorrectly returns argument attributes in the type hint array index
has_attributes
array index is available and set to TRUE
if the argument has attributes definedGeneric.NamingConventions.ConstructorName
no longer throws deprecation notices on PHP 8.1
Squiz.Commenting.BlockComment
now correctly applies rules for block comments after a short echo tag
PEAR.Commenting.FunctionComment
Squiz.Commenting.InlineComment
Squiz.Commenting.BlockComment
Squiz.Commenting.VariableComment
Squiz.WhiteSpace.MemberVarSpacing
PHP_CodeSniffer has run under PHP 8 for some time, but it has not supported all new language features until this release. Version 3.6.0 adds support for all new PHP 8 language features, including:
Note: All standards and sniffs included with PHP_CodeSniffer have been updated to support these language features, but external standards and sniffs may need updating before they are able to detect them correctly.
T_TYPE_UNION
token is available to represent the pipe characterFile::getMethodParameters()
, getMethodProperties()
, and getMemberProperties()
will now return union typesT_PARAM_NAME
token is available to represent the label with the name of the function argument in itT_ATTRIBUTE
token marks the start of an attributeT_ATTRIBUTE_END
token is available to mark the end of an attributeattribute_owner
and attribute_closer
indexes are available in the tokens array for all tokens inside an attributePEAR.Commenting.ClassComment
PEAR.Commenting.FileComment
PSR1.Files.SideEffects
PSR12.Files.FileHeader
Squiz.Commenting.ClassComment
Squiz.Commenting.FileComment
Squiz.WhiteSpace.FunctionSpacing
T_MATCH
token to process match expressionsT_MATCH_ARROW
token is available to represent the arrows in match expressionsT_MATCH_DEFAULT
token is available to represent the default keyword in match expressionsGeneric.CodeAnalysis.AssignmentInCondition
Generic.CodeAnalysis.EmptyPHPStatement
Generic.CodeAnalysis.EmptyStatement
Generic.PHP.LowerCaseKeyword
PEAR.ControlStructures.ControlSignature
PSR12.ControlStructures.BooleanOperatorPlacement
Squiz.Commenting.LongConditionClosingComment
Squiz.Commenting.PostStatementComment
Squiz.ControlStructures.LowercaseDeclaration
Squiz.ControlStructures.ControlSignature
Squiz.Formatting.OperatorBracket
Squiz.PHP.DisallowMultipleAssignments
Squiz.Objects.ObjectInstantiation
Squiz.WhiteSpace.ControlStructureSpacing
T_FN_ARROW
token has changed from "T_FN_ARROW" to "PHPCS_T_FN_ARROW" to avoid package conflicts
T_FN_ARROW
constantFile::findStartOfStatement()
now works correctly when passed the last token in a statementFile::getMethodParameters()
now supports PHP 8.0 constructor property promotion
property_visibility
and visibility_token
index if property promotion is detectedFile::getMethodProperties()
now includes a return_type_end_token
index in the return value
--stdin-path
--stdin-path
to set the file pathGeneric.NamingConventions.AbstractClassNamePrefix
to enforce that class names are prefixed with "Abstract"
Generic.NamingConventions.InterfaceNameSuffix
to enforce that interface names are suffixed with "Interface"
Generic.NamingConventions.TraitNameSuffix
to enforce that trait names are suffixed with "Trait"
Generic.CodeAnalysis.UnusedFunctionParameter
can now be configured to ignore variable usage for specific type hints
ignoreTypeHints
array property to a list of type hints to ignoreGeneric.Formatting.MultipleStatementAlignment
can now align statements at the start of the assignment token
alignAtEnd
sniff property to false
to align the assignment tokenstrue
, so the assigned values are alignedGeneric.PHP.LowerCaseType
now supports checking of typed properties
Generic.PHP.LowerCaseType
now supports checking of union types
PEAR.Commenting.FunctionComment
and Squiz.Commenting.FunctionComment
sniffs can now ignore private and protected methods
minimumVisibility
sniff property to protected
to ignore private methodsminimumVisibility
sniff property to public
to ignore both private and protected methodsprivate
, so all methods are checkedPEAR.Commenting.FunctionComment
and Squiz.Commenting.FunctionComment
sniffs can now ignore return tags in any method
__construct
and __destruct
were ignoredspecialMethods
sniff property__construct
and __destruct
onlyPSR2.ControlStructures.SwitchDeclaration
now supports nested switch statements where every branch terminates
CASE
only contained a SWITCH
and no direct terminating statement, a fall-through error was displayedSWITCH
has a terminating statementPSR2.Methods.FunctionCallSignature.SpaceBeforeCloseBracket
error message is now reported on the closing parenthesis token
Squiz.Commenting.FunctionComment
is now able to ignore function comments that are only inheritdoc statements
skipIfInheritdoc
sniff property to true
to skip checking function comments if the content is only {@inhertidoc}
false
, so these comments will continue to report errorsSquiz.Commenting.FunctionComment
now supports the PHP 8 mixed type
Squiz.PHP.NonExecutableCode
now has improved handling of syntax errors
Squiz.WhiteSpace.ScopeKeywordSpacing
now checks spacing when using PHP 8.0 constructor property promotion
is_readable()
Squiz.PHP.DisallowMultipleAssignments
sniff
T_NULLSAFE_OBJECT_OPERATOR
token has been made available for older versions
T_OBJECT_OPERATOR
have been modified to apply the same rules for the nullsafe object operatorPSR12.ControlStructures.BooleanOperatorPlacement.FoundMixed
error message is now more accurate when using the allowOnly setting
PSR12.Functions.NullableTypeDeclaration
now supports the PHP8 static return type
Squiz.Formatting.OperatorBracket
false positive when exiting with a negative numberSquiz.PHP.DisallowComparisonAssignment
false positive for methods called on an objectFile::getMethodProperties()
now detects the PHP 8.0 static return type
Generic.NamingConventions.CamelCapsFunctionName
no longer reports __serialize
and __unserialize
as invalid names
PEAR.NamingConventions.ValidFunctionName
no longer reports __serialize
and __unserialize
as invalid names
Squiz.Scope.StaticThisUsage
now detects usage of $this
inside closures and arrow functions
T_FN
backfill now works more reliably so T_FN
tokens only ever represent real arrow functions
Generic.CodeAnalysis.EmptyPHPStatement
now detects empty statements at the start of control structuresPEAR.Functions.FunctionCallSignature
now always uses "parenthesis" instead of sometimes using "bracket"
File::getCondition()
now accepts a 3rd argument that allows for the closest matching token to be returned
Generic.PHP.DisallowRequestSuperglobal
to ban the use of the $_REQUEST
superglobal
Generic.ControlStructures.InlineControlStructure
no longer shows errors for while
and for
statements without a body
PSR12.ControlStructures.BooleanOperatorPlacement
can now be configured to enforce a specific operator position
allowOnly
property to first
to enforce all boolean operators to be at the start of a lineallowOnly
property to last
to enforce all boolean operators to be at the end of a linePSR12.Files.ImportStatement
now auto-fixes import statements by removing the leading slash
Squiz.ControlStructures.ForLoopDeclaration
now has a setting to ignore newline characters
FALSE
, so newlines are not allowed within for
definitionsignoreNewlines
setting in a ruleset.xml
file to changeSquiz.PHP.InnerFunctions
now handles multiple nested anon classes correctlyT_FN
token has been made available for older versions
T_FN
represents the fn
string used for arrow functionsT_FN_ARROW
token typefn
will have a T_FN token
for the function name, but have no scope information1_000
would tokenize as T_LNUMBER (1), T_STRING (_000)
T_LNUMBER (1_000)
File::getMethodParameters()
now supports arrow functionsFile::getMethodProperties()
now supports arrow functionsFixer::changeCodeBlockIndent()
to change the indent of a code block while auto-fixing
Generic.Files.ExecutableFile
sniff
Generic.CodeAnalysis.EmptyPhpStatement
now reports unnecessary semicolons after control structure closing braces
Generic.PHP.LowerCaseKeyword
now enforces that the fn
keyword is lowercase
Generic.WhiteSpace.ScopeIndent
now supports static arrow functionsPEAR.Functions.FunctionCallSignature
now adjusts the indent of function argument contents during auto-fixing
PSR2.Methods.FunctionCallSignature
PSR2.ControlStructures.ControlStructureSpacing
now checks whitespace before the closing parenthesis of multi-line control structures
PSR12.Functions.ReturnTypeDeclaration
now checks the return type of arrow functions
PSR12.Traits.UseDeclaration
now ensures all trait import statements are grouped together
Squiz.Functions.LowercaseFunctionKeywords
now enforces that the fn
keyword is lowercase