function Common::isCamelCaps
Returns true if the specified string is in the camel caps format.
Parameters
string $string The string the verify.:
boolean $classFormat If true, check to see if the string is in the: class format. Class format strings must start with a capital letter and contain no underscores.
boolean $public If true, the first character in the string: must be an a-z character. If false, the character must be an underscore. This argument is only applicable if $classFormat is false.
boolean $strict If true, the string must not have two capital: letters next to each other. If false, a relaxed camel caps policy is used to allow for acronyms.
Return value
boolean
14 calls to Common::isCamelCaps()
- CamelCapsFunctionNameSniff::processTokenOutsideScope in vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Generic/ Sniffs/ NamingConventions/ CamelCapsFunctionNameSniff.php - Processes the tokens outside the scope.
- CamelCapsFunctionNameSniff::processTokenWithinScope in vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Generic/ Sniffs/ NamingConventions/ CamelCapsFunctionNameSniff.php - Processes the tokens within the scope.
- CamelCapsMethodNameSniff::processTokenWithinScope in vendor/
squizlabs/ php_codesniffer/ src/ Standards/ PSR1/ Sniffs/ Methods/ CamelCapsMethodNameSniff.php - Processes the tokens within the scope.
- ValidClassNameSniff::process in vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Squiz/ Sniffs/ Classes/ ValidClassNameSniff.php - Processes this test, when one of its tokens is encountered.
- ValidFunctionNameSniff::processTokenOutsideScope in vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Squiz/ Sniffs/ NamingConventions/ ValidFunctionNameSniff.php - Processes the tokens outside the scope.
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Util/ Common.php, line 350
Class
Namespace
PHP_CodeSniffer\UtilCode
public static function isCamelCaps($string, $classFormat = false, $public = true, $strict = true) {
// Check the first character first.
if ($classFormat === false) {
$legalFirstChar = '';
if ($public === false) {
$legalFirstChar = '[_]';
}
if ($strict === false) {
// Can either start with a lowercase letter, or multiple uppercase
// in a row, representing an acronym.
$legalFirstChar .= '([A-Z]{2,}|[a-z])';
}
else {
$legalFirstChar .= '[a-z]';
}
}
else {
$legalFirstChar = '[A-Z]';
}
if (preg_match("/^{$legalFirstChar}/", $string) === 0) {
return false;
}
// Check that the name only contains legal characters.
$legalChars = 'a-zA-Z0-9';
if (preg_match("|[^{$legalChars}]|", substr($string, 1)) > 0) {
return false;
}
if ($strict === true) {
// Check that there are not two capital letters next to each other.
$length = strlen($string);
$lastCharWasCaps = $classFormat;
for ($i = 1; $i < $length; $i++) {
$ascii = ord($string[$i]);
if ($ascii >= 48 && $ascii <= 57) {
// The character is a number, so it can't be a capital.
$isCaps = false;
}
else {
if (strtoupper($string[$i]) === $string[$i]) {
$isCaps = true;
}
else {
$isCaps = false;
}
}
if ($isCaps === true && $lastCharWasCaps === true) {
return false;
}
$lastCharWasCaps = $isCaps;
}
}
//end if
return true;
}