-
-
Notifications
You must be signed in to change notification settings - Fork 88
Description
Bug Description
Label names, i.e. names of namespaces, class/trait/interface/enum name and function names are case-insensitive for the ASCII letters, but case-sensitive for char 0x80 and up.
For the record: variable names in PHP are case-sensitive and so are constant names (unless explicitly declared not to be so via define()).
There are a number of sniffs in PHP_CodeSniffer which compare names, be it comparing a class name with another class name (Generic.Classes.DuplicateClassName), be it comparing a class name with a method name (Generic.NamingConventions.ConstructorName).
I'm fairly sure that, in most cases, these comparisons will use code akin to strtolower($nameA) === strtolower($nameB).
This is incorrect and these comparisons should be fixed to use strcasecmp() instead, as strcasecmp() only compares the ASCII letters case-insensitively (which is exactly what is needed).
Notes about this task:
- Code in sniffs checking the case of keywords using
strtolower()does not need to be changed as PHP does not contain any keywords containing non-ASCII characters. - Code in sniffs checking the case of PHP native label names using
strtolower()does not need to be changed as PHP does not contain any functions/classes etc containing non-ASCII characters. - Any JS/CSS-only sniffs can be ignored for the purposes of this task as they will be removed in PHPCS 4.0 anyway.
- Sniffs from the MySource standards can be ignored for the purposes of this task as they will be removed in PHPCS 4.0 anyway.
Task List
The below is a list of sniffs in which strtolower() was found and which need to be reviewed.
Each of these will need to be reviewed, though I expect that by far not all of them will need changes.
To do
- Generic.Classes.DuplicateClassName
- Generic.Classes.OpeningBraceSameLine
- Generic.CodeAnalysis.EmptyStatement
- Generic.CodeAnalysis.UnusedFunctionParameter
- Generic.Files.LowercasedFilename
- Generic.NamingConventions.AbstractClassNamePrefix
- Generic.NamingConventions.CamelCapsFunctionName
- Generic.NamingConventions.ConstructorName
- Generic.NamingConventions.InterfaceNameSuffix
- Generic.NamingConventions.TraitNameSuffix
- Generic.NamingConventions.UpperCaseConstantName
- Generic.PHP.ForbiddenFunctions
- Generic.PHP.LowerCaseConstant
- Generic.PHP.LowerCaseKeyword
- Generic.PHP.LowerCaseType
- Generic.PHP.RequireStrictTypes
- Generic.PHP.SAPIUsage
- Generic.PHP.UpperCaseConstant
- Generic.WhiteSpace.LanguageConstructSpacing
- Generic.WhiteSpace.ScopeIndent
- PEAR.Classes.ClassDeclaration
- PEAR.Commenting.ClassComment
- PEAR.Commenting.FileComment
- PEAR.Commenting.FunctionComment
- PEAR.Functions.FunctionDeclaration
- PEAR.Functions.ValidDefaultValue
- PEAR.NamingConventions.ValidFunctionName
- PSR1.Classes.ClassDeclaration
- PSR1.Files.SideEffects
- PSR1.Methods.CamelCapsMethodName
- PSR12.Files.DeclareStatement
- PSR12.Files.FileHeader
- PSR12.Files.ImportStatement
- PSR12.Keywords.ShortFormTypeKeywords
- PSR12.Traits.UseDeclaration
- PSR2.Classes.ClassDeclaration
- PSR2.ControlStructures.SwitchDeclaration
- Squiz.Arrays.ArrayDeclaration
- Squiz.Classes.ClassDeclaration
- Squiz.Classes.LowercaseClassKeywords
- Squiz.Commenting.FunctionComment
- Squiz.ControlStructures.ForEachLoopDeclaration
- Squiz.ControlStructures.LowercaseDeclaration
- Squiz.ControlStructures.SwitchDeclaration
- Squiz.Functions.LowercaseFunctionKeywords
- Squiz.Operators.ValidLogicalOperators
- Squiz.PHP.LowercasePHPFunctions
Claimed
Nothing yet
Done
Nothing yet
Want to contribute ?
Leave a comment below to claim one or more files you'll be reviewing.
- If the file does not need changes, report back saying so, so it can be moved to "Done".
- If the file does need changes, please accompany the changes by tests.
The tests should safeguard that names containing only ASCII characters, but in a different case, compare as "equal" and names containing non-ASCII characters in a different case do not compare as "equal".
PRs related to this task should preferably only address one file - or even one instance of the issue in one file - per PR. This will make reviewing the changes more straight forward and will allow for merging PRs promptly.