Skip to content

Commit

Permalink
Add a sniffs that ensures we use self when possible und for member va…
Browse files Browse the repository at this point in the history
…r scoping.
  • Loading branch information
realityking committed Jul 6, 2012
1 parent 9befc70 commit 6c381f3
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

defined('_JEXEC') or die;

// Register dependent classes.
JLoader::register('FinderIndexerStemmer', dirname(__FILE__) . '/stemmer.php');
JLoader::register('FinderIndexerToken', dirname(__FILE__) . '/token.php');

Expand Down Expand Up @@ -75,7 +74,7 @@ public static function tokenize($input, $lang, $phrase = false)
$quotes = html_entity_decode('‘’'', ENT_QUOTES, 'UTF-8');

// Get the simple language key.
$lang = FinderIndexerHelper::getPrimaryLanguage($lang);
$lang = self::getPrimaryLanguage($lang);

/*
* Parsing the string input into terms is a multi-step process.
Expand Down Expand Up @@ -312,7 +311,7 @@ public static function isCommon($token, $lang)
// Load the common tokens for the language if necessary.
if (!isset($data[$lang]))
{
$data[$lang] = FinderIndexerHelper::getCommonWords($lang);
$data[$lang] = self::getCommonWords($lang);
}

// Check if the token is in the common array.
Expand Down
31 changes: 15 additions & 16 deletions administrator/components/com_finder/helpers/indexer/indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

defined('_JEXEC') or die;

// Register dependent classes.
JLoader::register('FinderIndexerHelper', dirname(__FILE__) . '/helper.php');
JLoader::register('FinderIndexerParser', dirname(__FILE__) . '/parser.php');
JLoader::register('FinderIndexerStemmer', dirname(__FILE__) . '/stemmer.php');
Expand Down Expand Up @@ -236,7 +235,7 @@ public static function index($item, $format = 'html')
}

// Get the indexer state.
$state = FinderIndexer::getState();
$state = self::getState();

// Get the signatures of the item.
$curSig = self::getSignature($item);
Expand Down Expand Up @@ -438,12 +437,12 @@ public static function index($item, $format = 'html')
}

// Tokenize a string of content and add it to the database.
$count += FinderIndexer::tokenizeToDB($ip, $group, $item->language, $format);
$count += self::tokenizeToDB($ip, $group, $item->language, $format);

// Check if we're approaching the memory limit of the token table.
if ($count > self::$state->options->get('memory_table_limit', 30000))
{
FinderIndexer::toggleTables(false);
self::toggleTables(false);
}
}
}
Expand All @@ -460,12 +459,12 @@ public static function index($item, $format = 'html')
}

// Tokenize a string of content and add it to the database.
$count += FinderIndexer::tokenizeToDB($item->$property, $group, $item->language, $format);
$count += self::tokenizeToDB($item->$property, $group, $item->language, $format);

// Check if we're approaching the memory limit of the token table.
if ($count > self::$state->options->get('memory_table_limit', 30000))
{
FinderIndexer::toggleTables(false);
self::toggleTables(false);
}
}
}
Expand All @@ -487,7 +486,7 @@ public static function index($item, $format = 'html')
FinderIndexerTaxonomy::addMap($linkId, $nodeId);

// Tokenize the node title and add them to the database.
$count += FinderIndexer::tokenizeToDB($node->title, self::META_CONTEXT, $item->language, $format);
$count += self::tokenizeToDB($node->title, self::META_CONTEXT, $item->language, $format);
}
}

Expand Down Expand Up @@ -805,7 +804,7 @@ public static function index($item, $format = 'html')
}

// Toggle the token tables back to memory tables.
FinderIndexer::toggleTables(true);
self::toggleTables(true);

// Mark afterTruncating in the profiler.
self::$profiler ? self::$profiler->mark('afterTruncating') : null;
Expand All @@ -829,7 +828,7 @@ public static function remove($linkId)
$query = $db->getQuery(true);

// Get the indexer state.
$state = FinderIndexer::getState();
$state = self::getState();

// Update the link counts and remove the mapping records.
for ($i = 0; $i <= 15; $i++)
Expand Down Expand Up @@ -916,7 +915,7 @@ public static function remove($linkId)
public static function optimize()
{
// Get the indexer state.
$state = FinderIndexer::getState();
$state = self::getState();

// Get the database object.
$db = JFactory::getDBO();
Expand Down Expand Up @@ -1021,7 +1020,7 @@ public static function optimize()
protected static function getSignature($item)
{
// Get the indexer state.
$state = FinderIndexer::getState();
$state = self::getState();

// Get the relevant configuration variables.
$config = array();
Expand Down Expand Up @@ -1104,12 +1103,12 @@ protected static function tokenizeToDB($input, $context, $lang, $format)
$tokens = FinderIndexerHelper::tokenize($string, $lang);

// Add the tokens to the database.
$count += FinderIndexer::addTokensToDB($tokens, $context);
$count += self::addTokensToDB($tokens, $context);

// Check if we're approaching the memory limit of the token table.
if ($count > self::$state->options->get('memory_table_limit', 30000))
{
FinderIndexer::toggleTables(false);
self::toggleTables(false);
}

unset($string);
Expand Down Expand Up @@ -1157,12 +1156,12 @@ protected static function tokenizeToDB($input, $context, $lang, $format)
$tokens = FinderIndexerHelper::tokenize($string, $lang);

// Add the tokens to the database.
$count += FinderIndexer::addTokensToDB($tokens, $context);
$count += self::addTokensToDB($tokens, $context);

// Check if we're approaching the memory limit of the token table.
if ($count > self::$state->options->get('memory_table_limit', 30000))
{
FinderIndexer::toggleTables(false);
self::toggleTables(false);
}
}
}
Expand All @@ -1181,7 +1180,7 @@ protected static function tokenizeToDB($input, $context, $lang, $format)
$tokens = FinderIndexerHelper::tokenize($input, $lang);

// Add the tokens to the database.
$count = FinderIndexer::addTokensToDB($tokens, $context);
$count = self::addTokensToDB($tokens, $context);
}

return $count;
Expand Down
6 changes: 3 additions & 3 deletions administrator/components/com_login/models/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ protected function populateState()
*/
public static function getLoginModule($name = 'mod_login', $title = null)
{
$result = null;
$modules = LoginModelLogin::_load($name);
$total = count($modules);
$result = null;
$modules = self::_load($name);
$total = count($modules);

for ($i = 0; $i < $total; $i++)
{
Expand Down
2 changes: 1 addition & 1 deletion administrator/includes/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function login($credentials, $options = array())
$lang = preg_replace('/[^A-Z-]/i', '', $lang);
$this->setUserState('application.lang', $lang );

JAdministrator::purgeMessages();
self::purgeMessages();
}

return $result;
Expand Down
93 changes: 93 additions & 0 deletions build/phpcs/Joomla/Sniffs/Classes/MemberVarScopeSniff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/**
* Verifies that class members have scope modifiers.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: MemberVarScopeSniff.php 8 2010-11-06 00:40:23Z elkuku $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/

if(class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false)
{
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found');
}

/**
* Verifies that class members have scope modifiers.
*
* Example:
* class Foo
* {
* <b class="good">private $foo</b>
* <b class="bad">var $foo</b>
* }
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.3.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Joomla_Sniffs_Classes_MemberVarScopeSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff
{
/**
* Processes the function tokens within the class.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
* @param integer $stackPtr The position where the token was found.
*
* @return void
*/
protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

$modifier = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$scopeModifiers, $stackPtr);

if(($modifier === false) || ($tokens[$modifier]['line'] !== $tokens[$stackPtr]['line']))
{
$error = sprintf('Scope modifier not specified for member variable "%s"'
, $tokens[$stackPtr]['content']);

$phpcsFile->addWarning($error, $stackPtr, 'Missing');
}
}//function

/**
* Processes normal variables.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
* @param integer $stackPtr The position where the token was found.
*
* @return void
*/
protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
// We don't care about normal variables.
return;
}//function

/**
* Processes variables in double quoted strings.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
* @param integer $stackPtr The position where the token was found.
*
* @return void
*/
protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
// We don't care about normal variables.
return;
}//function
}//class
4 changes: 4 additions & 0 deletions build/phpcs/Joomla/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<!-- Include some additional sniffs from the Generic standard -->

<rule ref="PEAR.Classes.ClassDeclaration"/>
<rule ref="Squiz.Classes.SelfMemberReference">
<exclude-pattern>/libraries/joomla/*</exclude-pattern>
<exclude-pattern>/libraries/legacy/*</exclude-pattern>
</rule>

<rule ref="Generic.Files.LineEndings"/>
<rule ref="Zend.Files.ClosingTag">
Expand Down
8 changes: 4 additions & 4 deletions components/com_mailto/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function send()

$timeout = $session->get('com_mailto.formtime', 0);
if ($timeout == 0 || time() - $timeout < 20) {
JError::raiseNotice(500, JText:: _ ('COM_MAILTO_EMAIL_NOT_SENT'));
JError::raiseNotice(500, JText::_('COM_MAILTO_EMAIL_NOT_SENT'));
return $this->mailto();
}

Expand All @@ -59,7 +59,7 @@ function send()
// Verify that this is a local link
if (!$link || !JURI::isInternal($link)) {
//Non-local url...
JError::raiseNotice(500, JText:: _ ('COM_MAILTO_EMAIL_NOT_SENT'));
JError::raiseNotice(500, JText::_('COM_MAILTO_EMAIL_NOT_SENT'));
return $this->mailto();
}

Expand Down Expand Up @@ -126,7 +126,7 @@ function send()
}

// Build the message to send
$msg = JText :: _('COM_MAILTO_EMAIL_MSG');
$msg = JText::_('COM_MAILTO_EMAIL_MSG');
$body = sprintf($msg, $SiteName, $sender, $from, $link);

// Clean the email data
Expand All @@ -137,7 +137,7 @@ function send()
// Send the email
if (JFactory::getMailer()->sendMail($from, $sender, $email, $subject, $body) !== true)
{
JError::raiseNotice(500, JText:: _ ('COM_MAILTO_EMAIL_NOT_SENT'));
JError::raiseNotice(500, JText::_('COM_MAILTO_EMAIL_NOT_SENT'));
return $this->mailto();
}

Expand Down

0 comments on commit 6c381f3

Please sign in to comment.