Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixes #4359 #9

Closed
wants to merge 1 commit into from

3 participants

@wiltave

Fixes #4359 (http://dev.kohanaframework.org/issues/4359#note-4).

Sorry about the lack of unit tests. I didn't figure out how to run the coding standards' unit tests.

Thanks.

@samwilson

The outcome of that bug report was to stick with uppercase logical operators. I think this pull request can be closed?

@Zeelot Zeelot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
79 ...fer/Standards/Kohana/Sniffs/NamingConventions/LowerCaseComparisonLogicalOperatorSniff.php
@@ -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);
+ }
+}
+
+?>
View
13 PHP/CodeSniffer/Standards/Kohana/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php
@@ -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()
Something went wrong with that request. Please try again.