Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #4359 #9

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
/**
* Kohana_Sniffs_NamingConventions_LowerCaseComparisonLogicalOperatorSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Matthew Turland <matt@ishouldbecoding.com>
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id$
* @link http://pear.php.net/package/PHP_CodeSniffer
*/

/**
* Ensures that logical operators names are all lowercase.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Matthew Turland <matt@ishouldbecoding.com>
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: @release_version@
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Kohana_Sniffs_NamingConventions_LowerCaseComparisonLogicalOperatorSniff implements PHP_CodeSniffer_Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_LOGICAL_AND,
T_LOGICAL_OR,
T_LOGICAL_XOR,
);
}

/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the
* document
* @param int $stackPtr Position of the current token in the stack passed
* in $tokens
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$currentToken = $tokens[$stackPtr];
$registeredTokens = $this->register();

if (in_array($currentToken['code'], $registeredTokens)) {
if (! $this->_isLowerCaseTokenContent($currentToken)) {
$error = 'Use lowercase ' . strtolower($currentToken['content']);
$phpcsFile->addError($error, $stackPtr);
}
}
}

/**
* Checks if the current token's content is a lowercase string.
*
* @param array $currentToken
* @return boolean
*/
private function _isLowerCaseTokenContent(array $currentToken)
{
$tokenContent = $currentToken['content'];
$lowerCaseTokenContent = strtolower($tokenContent);

return ($tokenContent === $lowerCaseTokenContent);
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,11 @@ class Kohana_Sniffs_NamingConventions_UpperCaseConstantNameSniff extends Generic
public function register()
{
return array(
T_STRING,
T_TRUE,
T_FALSE,
T_NULL,
T_LOGICAL_AND,
T_LOGICAL_OR,
T_LOGICAL_XOR
);
T_STRING,
T_TRUE,
T_FALSE,
T_NULL,
);

}//end register()

Expand Down