From 033aa88b1bb55ade862fc3162d2f249f854fbe06 Mon Sep 17 00:00:00 2001 From: frank Date: Sun, 25 Sep 2016 18:53:23 +0300 Subject: [PATCH 01/43] Fixed callable call in loop termination condition --- libraries/cms/schema/changeitem/postgresql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/cms/schema/changeitem/postgresql.php b/libraries/cms/schema/changeitem/postgresql.php index a4a8f4d68db85..0ad55207beafc 100644 --- a/libraries/cms/schema/changeitem/postgresql.php +++ b/libraries/cms/schema/changeitem/postgresql.php @@ -86,7 +86,7 @@ protected function buildCheckQuery() { $type = ''; - for ($i = 7; $i < count($wordArray); $i++) + for ($i = 7, $iMax = count($wordArray); $i < $iMax; $i++) { $type .= $wordArray[$i] . ' '; } From a650515773ca792f48bb7629ebd91cc0b159c913 Mon Sep 17 00:00:00 2001 From: frank Date: Sun, 25 Sep 2016 18:54:25 +0300 Subject: [PATCH 02/43] Fixed non-optimal regular expression --- libraries/cms/component/router/legacy.php | 2 +- libraries/cms/router/router.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/cms/component/router/legacy.php b/libraries/cms/component/router/legacy.php index fd8a431d559eb..8c8d674f90054 100644 --- a/libraries/cms/component/router/legacy.php +++ b/libraries/cms/component/router/legacy.php @@ -98,7 +98,7 @@ public function parse(&$segments) for ($i = 0; $i < $total; $i++) { - $segments[$i] = preg_replace('/-/', ':', $segments[$i], 1); + $segments[$i] = str_replace('-', ':', $segments[$i]); } return $function($segments); diff --git a/libraries/cms/router/router.php b/libraries/cms/router/router.php index 640e42a47ed04..a6f760b4cfe72 100644 --- a/libraries/cms/router/router.php +++ b/libraries/cms/router/router.php @@ -774,7 +774,7 @@ protected function decodeSegments($segments) for ($i = 0; $i < $total; $i++) { - $segments[$i] = preg_replace('/-/', ':', $segments[$i], 1); + $segments[$i] = str_replace('-', ':', $segments[$i]); } return $segments; From a33ad89c9534e7ca34c3f9b27cdf4de042054142 Mon Sep 17 00:00:00 2001 From: frank Date: Sun, 25 Sep 2016 18:56:02 +0300 Subject: [PATCH 03/43] Shortened syntax for applied operations --- libraries/cms/form/field/captcha.php | 2 +- libraries/cms/html/number.php | 2 +- libraries/cms/router/site.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/cms/form/field/captcha.php b/libraries/cms/form/field/captcha.php index 67e5e1cb31576..4cd4fe9aed8ea 100644 --- a/libraries/cms/form/field/captcha.php +++ b/libraries/cms/form/field/captcha.php @@ -111,7 +111,7 @@ public function setup(SimpleXMLElement $element, $value, $group = null) if (strpos($this->class, 'required') === false) { - $this->class = $this->class . ' required'; + $this->class .= ' required'; } } diff --git a/libraries/cms/html/number.php b/libraries/cms/html/number.php index cfa1cbe176ce3..24c3b8a3afd72 100644 --- a/libraries/cms/html/number.php +++ b/libraries/cms/html/number.php @@ -58,7 +58,7 @@ public static function bytes($bytes, $unit = 'auto', $precision = 2, $iec = fals { $oBase = $iec && strpos($oUnit, 'i') === false ? 1000 : 1024; $factor = pow($oBase, stripos('BKMGTPEZY', $oUnit[0])); - $oBytes = $oBytes * $factor; + $oBytes *= $factor; } } diff --git a/libraries/cms/router/site.php b/libraries/cms/router/site.php index 151284970a083..5b257dc7f6b01 100644 --- a/libraries/cms/router/site.php +++ b/libraries/cms/router/site.php @@ -231,7 +231,7 @@ protected function parseRawRoute(&$uri) if ($item !== null && is_array($item->query)) { - $vars = $vars + $item->query; + $vars += $item->query; } } From 4173a7ffe1170422efaf61976c001b65d58d12ee Mon Sep 17 00:00:00 2001 From: frank Date: Sun, 25 Sep 2016 19:15:30 +0300 Subject: [PATCH 04/43] Don't use strlen() to check if string is empty. --- libraries/cms/application/cms.php | 2 +- libraries/cms/helper/media.php | 4 ++-- libraries/cms/html/string.php | 2 +- libraries/cms/installer/adapter/library.php | 2 +- libraries/cms/installer/adapter/module.php | 2 +- libraries/cms/installer/adapter/template.php | 2 +- libraries/cms/installer/installer.php | 4 ++-- libraries/cms/installer/manifest.php | 2 +- libraries/cms/toolbar/button/popup.php | 4 ++-- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libraries/cms/application/cms.php b/libraries/cms/application/cms.php index 4574077ff0c68..35e9c4a3b94c4 100644 --- a/libraries/cms/application/cms.php +++ b/libraries/cms/application/cms.php @@ -231,7 +231,7 @@ public function checkSession() public function enqueueMessage($msg, $type = 'message') { // Don't add empty messages. - if (!strlen(trim($msg))) + if (trim($msg) === '') { return; } diff --git a/libraries/cms/helper/media.php b/libraries/cms/helper/media.php index ff48d93771d79..b56c16d031b3e 100644 --- a/libraries/cms/helper/media.php +++ b/libraries/cms/helper/media.php @@ -160,7 +160,7 @@ public function canUpload($file, $component = 'com_media') $finfo = finfo_open(FILEINFO_MIME); $type = finfo_file($finfo, $file['tmp_name']); - if (strlen($type) && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) + if ($type !== '' && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) { $app->enqueueMessage(JText::_('JLIB_MEDIA_ERROR_WARNINVALID_MIME'), 'notice'); @@ -174,7 +174,7 @@ public function canUpload($file, $component = 'com_media') // We have mime magic. $type = mime_content_type($file['tmp_name']); - if (strlen($type) && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) + if ($type !== '' && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) { $app->enqueueMessage(JText::_('JLIB_MEDIA_ERROR_WARNINVALID_MIME'), 'notice'); diff --git a/libraries/cms/html/string.php b/libraries/cms/html/string.php index 8b60a81d54040..cfb536152fe5e 100644 --- a/libraries/cms/html/string.php +++ b/libraries/cms/html/string.php @@ -197,7 +197,7 @@ public static function truncateComplex($html, $maxLength = 0, $noSplit = true) $ptString = JHtml::_('string.truncate', $html, $maxLength, $noSplit, $allowHtml = false); // It's all HTML, just return it. - if (strlen($ptString) == 0) + if ($ptString === '') { return $html; } diff --git a/libraries/cms/installer/adapter/library.php b/libraries/cms/installer/adapter/library.php index a124903438c03..098879f05cd4d 100644 --- a/libraries/cms/installer/adapter/library.php +++ b/libraries/cms/installer/adapter/library.php @@ -362,7 +362,7 @@ public function uninstall($id) // This should give us the necessary information to proceed. $row = JTable::getInstance('extension'); - if (!$row->load((int) $id) || !strlen($row->element)) + if (!$row->load((int) $id) || $row->element === '') { JLog::add(JText::_('ERRORUNKOWNEXTENSION'), JLog::WARNING, 'jerror'); diff --git a/libraries/cms/installer/adapter/module.php b/libraries/cms/installer/adapter/module.php index ecf8a08f9b9bb..acbb0679ce763 100644 --- a/libraries/cms/installer/adapter/module.php +++ b/libraries/cms/installer/adapter/module.php @@ -517,7 +517,7 @@ public function uninstall($id) // First order of business will be to load the module object table from the database. // This should give us the necessary information to proceed. - if (!$this->extension->load((int) $id) || !strlen($this->extension->element)) + if (!$this->extension->load((int) $id) || $this->extension->element === '') { JLog::add(JText::_('JLIB_INSTALLER_ERROR_MOD_UNINSTALL_ERRORUNKOWNEXTENSION'), JLog::WARNING, 'jerror'); diff --git a/libraries/cms/installer/adapter/template.php b/libraries/cms/installer/adapter/template.php index b24ae7431e092..de65c247f56e6 100644 --- a/libraries/cms/installer/adapter/template.php +++ b/libraries/cms/installer/adapter/template.php @@ -409,7 +409,7 @@ public function uninstall($id) // This should give us the necessary information to proceed. $row = JTable::getInstance('extension'); - if (!$row->load((int) $id) || !strlen($row->element)) + if (!$row->load((int) $id) || $row->element === '') { JLog::add(JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_ERRORUNKOWNEXTENSION'), JLog::WARNING, 'jerror'); diff --git a/libraries/cms/installer/installer.php b/libraries/cms/installer/installer.php index 30f53423dc723..d27f771f7d416 100644 --- a/libraries/cms/installer/installer.php +++ b/libraries/cms/installer/installer.php @@ -1027,7 +1027,7 @@ public function setSchemaVersion(SimpleXMLElement $schema, $eid) } } - if (strlen($schemapath)) + if ($schemapath !== '') { $files = str_replace('.sql', '', JFolder::files($this->getPath('extension_root') . '/' . $schemapath, '\.sql$')); usort($files, 'version_compare'); @@ -1102,7 +1102,7 @@ public function parseSchemaUpdates(SimpleXMLElement $schema, $eid) } } - if (strlen($schemapath)) + if ($schemapath !== '') { $files = str_replace('.sql', '', JFolder::files($this->getPath('extension_root') . '/' . $schemapath, '\.sql$')); usort($files, 'version_compare'); diff --git a/libraries/cms/installer/manifest.php b/libraries/cms/installer/manifest.php index 548d55d21f9d6..2f52a83dc2202 100644 --- a/libraries/cms/installer/manifest.php +++ b/libraries/cms/installer/manifest.php @@ -91,7 +91,7 @@ abstract class JInstallerManifest */ public function __construct($xmlpath = '') { - if (strlen($xmlpath)) + if ($xmlpath !== '') { $this->loadManifestFromXml($xmlpath); } diff --git a/libraries/cms/toolbar/button/popup.php b/libraries/cms/toolbar/button/popup.php index 4a16183dada94..4c8327153be7a 100644 --- a/libraries/cms/toolbar/button/popup.php +++ b/libraries/cms/toolbar/button/popup.php @@ -46,7 +46,7 @@ public function fetchButton($type = 'Modal', $name = '', $text = '', $url = '', $onClose = '', $title = '', $footer = null) { // If no $title is set, use the $text element - if (strlen($title) == 0) + if ($title === '') { $title = $text; } @@ -83,7 +83,7 @@ public function fetchButton($type = 'Modal', $name = '', $text = '', $url = '', $html[] = JHtml::_('bootstrap.renderModal', 'modal-' . $name, $params); // If an $onClose event is passed, add it to the modal JS object - if (strlen($onClose) >= 1) + if ($onClose !== '') { $html[] = '