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

Type safe comparison in plugins - second iteration #13272

Merged
merged 9 commits into from
May 31, 2017
4 changes: 2 additions & 2 deletions plugins/authentication/cookie/cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function onUserAuthenticate($credentials, $options, &$response)
$cookieArray = explode('.', $cookieValue);

// Check for valid cookie value
if (count($cookieArray) != 2)
if (count($cookieArray) !== 2)
{
// Destroy the cookie in the browser.
$this->app->input->cookie->set($cookieName, '', 1, $this->app->get('cookie_path', '/'), $this->app->get('cookie_domain', ''));
Expand Down Expand Up @@ -279,7 +279,7 @@ public function onUserAfterLogin($options)
$errorCount++;

// We'll let this query fail up to 5 times before giving up, there's probably a bigger issue at this point
if ($errorCount == 5)
if ($errorCount === 5)
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/authentication/gmail/gmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function onUserAuthenticate($credentials, $options, &$response)
foreach ($localUsers as $localUser)
{
// Local user exists with same username but different email address
if ($email != $localUser->email)
if ($email !== $localUser->email)
{
$response->status = JAuthentication::STATUS_FAILURE;
$response->error_message = JText::sprintf('JGLOBAL_AUTH_FAILED', JText::_('PLG_GMAIL_ERROR_LOCAL_USERNAME_CONFLICT'));
Expand Down
2 changes: 1 addition & 1 deletion plugins/captcha/recaptcha/recaptchalib.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class JReCaptcha
*/
public function __construct($secret)
{
if ($secret == null || $secret == '')
if ($secret == null || $secret === '')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frankmayer Should this be === null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think It could, and I also think I have done this in another PR.

{
die("To use reCAPTCHA you must get an API key from <a href='"
. self::$_signupUrl . "'>" . self::$_signupUrl . "</a>");
Expand Down
2 changes: 1 addition & 1 deletion plugins/content/contact/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected function getContactId($created_by)
$query->where('contact.published = 1');
$query->where('contact.user_id = ' . (int) $created_by);

if (JLanguageMultilang::isEnabled() == 1)
if (JLanguageMultilang::isEnabled() === true)
{
$query->where('(contact.language in '
. '(' . $this->db->quote(JFactory::getLanguage()->getTag()) . ',' . $this->db->quote('*') . ') '
Expand Down
10 changes: 5 additions & 5 deletions plugins/content/pagebreak/pagebreak.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,17 +316,17 @@ protected function _createToc(&$row, &$matches, &$page)
$title = JText::sprintf('PLG_CONTENT_PAGEBREAK_PAGE_NUM', $i);
}

$liClass = ($limitstart == $i - 1) ? ' class="active"' : '';
$class = ($limitstart == $i - 1) ? 'toclink active' : 'toclink';
$liClass = ($limitstart === $i - 1) ? ' class="active"' : '';
$class = ($limitstart === $i - 1) ? 'toclink active' : 'toclink';
$row->toc .= '<li' . $liClass . '><a href="' . $link . '" class="' . $class . '">' . $title . '</a></li>';
$i++;
}

if ($this->params->get('showall'))
{
$link = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catid, $row->language) . '&showall=1&limitstart=');
$liClass = ($limitstart == $i - 1) ? ' class="active"' : '';
$class = ($limitstart == $i - 1) ? 'toclink active' : 'toclink';
$liClass = ($limitstart === $i - 1) ? ' class="active"' : '';
$class = ($limitstart === $i - 1) ? 'toclink active' : 'toclink';
$row->toc .= '<li' . $liClass . '><a href="' . $link . '" class="' . $class . '">'
. JText::_('PLG_CONTENT_PAGEBREAK_ALL_PAGES') . '</a></li>';
}
Expand Down Expand Up @@ -370,7 +370,7 @@ protected function _createNavigation(&$row, $page, $n)

if ($page > 0)
{
$page_prev = $page - 1 == 0 ? '' : $page - 1;
$page_prev = $page - 1 === 0 ? '' : $page - 1;

$link_prev = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catid, $row->language) . '&showall=&limitstart=' . $page_prev);

Expand Down
4 changes: 2 additions & 2 deletions plugins/editors-xtd/image/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public function onDisplay($name, $asset, $author)
if ($user->authorise('core.edit', $asset)
|| $user->authorise('core.create', $asset)
|| (count($user->getAuthorisedCategories($asset, 'core.create')) > 0)
|| ($user->authorise('core.edit.own', $asset) && $author == $user->id)
|| ($user->authorise('core.edit.own', $asset) && $author === $user->id)
|| (count($user->getAuthorisedCategories($extension, 'core.edit')) > 0)
|| (count($user->getAuthorisedCategories($extension, 'core.edit.own')) > 0 && $author == $user->id))
|| (count($user->getAuthorisedCategories($extension, 'core.edit.own')) > 0 && $author === $user->id))
{
$link = 'index.php?option=com_media&amp;view=images&amp;tmpl=component&amp;e_name=' . $name . '&amp;asset=' . $asset . '&amp;author=' . $author;

Expand Down
4 changes: 2 additions & 2 deletions plugins/finder/categories/categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,13 @@ public function onFinderChangeState($context, $pks, $value)
protected function index(FinderIndexerResult $item, $format = 'html')
{
// Check if the extension is enabled.
if (JComponentHelper::isEnabled($this->extension) == false)
if (JComponentHelper::isEnabled($this->extension) === false)
{
return;
}

// Check if the extension that owns the category is also enabled.
if (JComponentHelper::isEnabled($item->extension) == false)
if (JComponentHelper::isEnabled($item->extension) === false)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/finder/contacts/contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function onFinderChangeState($context, $pks, $value)
protected function index(FinderIndexerResult $item, $format = 'html')
{
// Check if the extension is enabled
if (JComponentHelper::isEnabled($this->extension) == false)
if (JComponentHelper::isEnabled($this->extension) === false)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/finder/newsfeeds/newsfeeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function onFinderChangeState($context, $pks, $value)
protected function index(FinderIndexerResult $item, $format = 'html')
{
// Check if the extension is enabled.
if (JComponentHelper::isEnabled($this->extension) == false)
if (JComponentHelper::isEnabled($this->extension) === false)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/finder/tags/tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function onFinderChangeState($context, $pks, $value)
protected function index(FinderIndexerResult $item, $format = 'html')
{
// Check if the extension is enabled
if (JComponentHelper::isEnabled($this->extension) == false)
if (JComponentHelper::isEnabled($this->extension) === false)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/quickicon/extensionupdate/extensionupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PlgQuickiconExtensionupdate extends JPlugin
*/
public function onGetIcons($context)
{
if ($context != $this->params->get('context', 'mod_quickicon') || !JFactory::getUser()->authorise('core.manage', 'com_installer'))
if ($context !== $this->params->get('context', 'mod_quickicon') || !JFactory::getUser()->authorise('core.manage', 'com_installer'))
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/quickicon/joomlaupdate/joomlaupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PlgQuickiconJoomlaupdate extends JPlugin
*/
public function onGetIcons($context)
{
if ($context != $this->params->get('context', 'mod_quickicon') || !JFactory::getUser()->authorise('core.manage', 'com_installer'))
if ($context !== $this->params->get('context', 'mod_quickicon') || !JFactory::getUser()->authorise('core.manage', 'com_installer'))
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/search/categories/categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = nu

$text = trim($text);

if ($text == '')
if ($text === '')
{
return array();
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/search/contacts/contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = nu

$text = trim($text);

if ($text == '')
if ($text === '')
{
return array();
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/search/content/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = nu

$text = trim($text);

if ($text == '')
if ($text === '')
{
return array();
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/search/newsfeeds/newsfeeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = nu

$text = trim($text);

if ($text == '')
if ($text === '')
{
return array();
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/search/tags/tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = nu

$text = trim($text);

if ($text == '')
if ($text === '')
{
return array();
}
Expand Down Expand Up @@ -156,7 +156,7 @@ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = nu
foreach ($rows as $key => $row)
{
$rows[$key]->href = TagsHelperRoute::getTagRoute($row->id);
$rows[$key]->text = ($row->description != '' ? $row->description : $row->title);
$rows[$key]->text = ($row->description !== '' ? $row->description : $row->title);
$rows[$key]->text .= $row->note;
$rows[$key]->section = $section;
$rows[$key]->created = $row->created;
Expand Down
2 changes: 1 addition & 1 deletion plugins/system/debug/debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ protected function displayQueries()
$labelClass = 'label-warning';
}

if ($this->totalQueries == 0)
if ($this->totalQueries === 0)
{
$this->totalQueries = $db->getCount();
}
Expand Down
18 changes: 9 additions & 9 deletions plugins/system/languagefilter/languagefilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ public function buildRule(&$router, &$uri)

if ($this->mode_sef
&& (!$this->params->get('remove_default_prefix', 0)
|| $lang != $this->default_lang
|| $lang != $this->current_lang))
|| $lang !== $this->default_lang
|| $lang !== $this->current_lang))
{
$uri->setPath($uri->getPath() . '/' . $sef . '/');
}
Expand Down Expand Up @@ -338,7 +338,7 @@ public function parseRule(&$router, &$uri)
array_shift($parts);

// Empty parts array when "index.php" is the only part left.
if (count($parts) == 1 && $parts[0] === 'index.php')
if (count($parts) === 1 && $parts[0] === 'index.php')
{
$parts = array();
}
Expand Down Expand Up @@ -548,7 +548,7 @@ public function onUserAfterSave($user, $isnew, $success, $msg)
$lang_code = $this->current_lang;
}

if ($lang_code == $this->user_lang_code || !isset($this->lang_codes[$lang_code]))
if ($lang_code === $this->user_lang_code || !isset($this->lang_codes[$lang_code]))
{
if ($this->app->isClient('site'))
{
Expand Down Expand Up @@ -662,15 +662,15 @@ public function onUserLogin($user, $options = array())
// We are on a Home page, we redirect to the user preferred site language Home page.
$item = $menu->getDefault($lang_code);

if ($item && $item->language != $active->language && $item->language !== '*')
if ($item && $item->language !== $active->language && $item->language !== '*')
{
$this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $item->id);
$foundAssociation = true;
}
}
}

if ($foundAssociation && $lang_code != $this->current_lang)
if ($foundAssociation && $lang_code !== $this->current_lang)
{
// Change language.
$this->current_lang = $lang_code;
Expand Down Expand Up @@ -721,14 +721,14 @@ public function onAfterDispatch()
$current_link = JRoute::_($currentInternalUrl);

// Load menu associations
if ($active_link == $current_link)
if ($active_link === $current_link)
{
$associations = MenusHelper::getAssociations($active->id);
}

// Check if we are on the home page
$is_home = ($active->home
&& ($active_link == $current_link || $active_link == $current_link . 'index.php' || $active_link . '/' == $current_link));
&& ($active_link === $current_link || $active_link === $current_link . 'index.php' || $active_link . '/' === $current_link));
}

// Load component associations.
Expand Down Expand Up @@ -759,7 +759,7 @@ public function onAfterDispatch()
break;

// Current language link
case ($i == $this->current_lang):
case ($i === $this->current_lang):
$language->link = JRoute::_($currentInternalUrl);
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function updatecachetime_postinstall_condition()
$cacheTimeout = (int) JComponentHelper::getComponent('com_installer')->params->get('cachetimeout', 6);

// Check if cachetimeout is eq zero
if ($cacheTimeout == 0 && JPluginHelper::isEnabled('system', 'updatenotification'))
if ($cacheTimeout === 0 && JPluginHelper::isEnabled('system', 'updatenotification'))
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/twofactorauth/totp/postinstall/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function twofactorauth_postinstall_condition()
$db->setQuery($query);
$enabled_plugins = $db->loadObjectList();

return count($enabled_plugins) == 0;
return count($enabled_plugins) === 0;
}

/**
Expand Down
18 changes: 9 additions & 9 deletions plugins/twofactorauth/totp/totp.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function onUserTwofactorShowConfiguration($otpConfig, $user_id = null)
// Create a new TOTP class with Google Authenticator compatible settings
$totp = new FOFEncryptTotp(30, 6, 10);

if ($otpConfig->method == $this->methodName)
if ($otpConfig->method === $this->methodName)
{
// This method is already activated. Reuse the same secret key.
$secret = $otpConfig->config['code'];
Expand Down Expand Up @@ -152,7 +152,7 @@ public function onUserTwofactorShowConfiguration($otpConfig, $user_id = null)
*/
public function onUserTwofactorApplyConfiguration($method)
{
if ($method != $this->methodName)
if ($method !== $this->methodName)
{
return false;
}
Expand Down Expand Up @@ -192,7 +192,7 @@ public function onUserTwofactorApplyConfiguration($method)

// Check the security code entered by the user (exact time slot match)
$code = $totp->getCode($data['key']);
$check = $code == $data['securitycode'];
$check = $code === $data['securitycode'];

/*
* If the check fails, test the previous 30 second slot. This allow the
Expand All @@ -203,7 +203,7 @@ public function onUserTwofactorApplyConfiguration($method)
{
$time = time() - 30;
$code = $totp->getCode($data['key'], $time);
$check = $code == $data['securitycode'];
$check = $code === $data['securitycode'];
}

/*
Expand All @@ -214,7 +214,7 @@ public function onUserTwofactorApplyConfiguration($method)
{
$time = time() + 30;
$code = $totp->getCode($data['key'], $time);
$check = $code == $data['securitycode'];
$check = $code === $data['securitycode'];
}

if (!$check)
Expand Down Expand Up @@ -258,7 +258,7 @@ public function onUserTwofactorAuthenticate($credentials, $options)
}

// Check if we have the correct method
if ($otpConfig->method != $this->methodName)
if ($otpConfig->method !== $this->methodName)
{
return false;
}
Expand All @@ -274,7 +274,7 @@ public function onUserTwofactorAuthenticate($credentials, $options)

// Check the code
$code = $totp->getCode($otpConfig->config['code']);
$check = $code == $credentials['secretkey'];
$check = $code === $credentials['secretkey'];

/*
* If the check fails, test the previous 30 second slot. This allow the
Expand All @@ -285,7 +285,7 @@ public function onUserTwofactorAuthenticate($credentials, $options)
{
$time = time() - 30;
$code = $totp->getCode($otpConfig->config['code'], $time);
$check = $code == $credentials['secretkey'];
$check = $code === $credentials['secretkey'];
}

/*
Expand All @@ -296,7 +296,7 @@ public function onUserTwofactorAuthenticate($credentials, $options)
{
$time = time() + 30;
$code = $totp->getCode($otpConfig->config['code'], $time);
$check = $code == $credentials['secretkey'];
$check = $code === $credentials['secretkey'];
}

return $check;
Expand Down
Loading