PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
PHP_CodeSniffer has run correctly under PHP 8.1 since PHP 8 support was added, but it has not supported new 8.1 language features until this release. Version 3.7.0 adds support for the following PHP 8.1 language features:
never
typeNote: 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_ENUM_CASE
token to represent the case statements inside an enumT_TYPE_INTERSECTION
token to represent the ampersand character inside intersection typesFile::getMethodParameters
now supports the new PHP 8.1 readonly token
property_readonly
array index is included in the return value
readonly_token
array index is included in the return value
Generic.PHP.LowerCaseKeyword
PSR2.Classes.PropertyDeclaration
Squiz.Commenting.BlockComment
Squiz.Commenting.DocCommentAlignment
Squiz.Commenting.VariableComment
Squiz.WhiteSpace.ScopeKeywordSpacing
Generic.PHP.UpperCaseConstant
and Generic.PHP.LowerCaseConstant
now ignore type declarations
true
/false
/null
when used as valuesGeneric.PHP.LowerCaseType
now supports the PHP 8.1 never
type
@throw
T_GOTO_LABEL
${
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"