Skip to content

Commit 128e175

Browse files
frankmayerrdeutz
authored andcommitted
Type safe comparison in libraries/cms - second iteration (#13276)
* ### Summary of Changes Type safe comparison in libraries/cms - second iteration - some bool - some int * Changes according to reviewer's comments + more type safety + some code style
1 parent 751779a commit 128e175

File tree

13 files changed

+32
-32
lines changed

13 files changed

+32
-32
lines changed

libraries/cms/form/rule/password.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function test(SimpleXMLElement $element, $value, $group = null, Registry
9292
// Set a variable to check if any errors are made in password
9393
$validPassword = true;
9494

95-
if (strlen($valueTrim) != $valueLength)
95+
if (strlen($valueTrim) !== $valueLength)
9696
{
9797
JFactory::getApplication()->enqueueMessage(
9898
JText::_('COM_USERS_MSG_SPACES_IN_PASSWORD'),

libraries/cms/html/html.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ protected static function extract($key)
6868
// Check to see whether we need to load a helper file
6969
$parts = explode('.', $key);
7070

71-
$prefix = (count($parts) == 3 ? array_shift($parts) : 'JHtml');
72-
$file = (count($parts) == 2 ? array_shift($parts) : '');
73-
$func = array_shift($parts);
71+
$prefix = count($parts) === 3 ? array_shift($parts) : 'JHtml';
72+
$file = count($parts) === 2 ? array_shift($parts) : '';
73+
$func = array_shift($parts);
7474

7575
return array(strtolower($prefix . '.' . $file . '.' . $func), $prefix, $file, $func);
7676
}
@@ -97,7 +97,7 @@ public static function _($key)
9797
if (array_key_exists($key, static::$registry))
9898
{
9999
$function = static::$registry[$key];
100-
$args = func_get_args();
100+
$args = func_get_args();
101101

102102
// Remove function name from arguments
103103
array_shift($args);

libraries/cms/html/select.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static function genericlist($data, $name, $attribs = null, $optKey = 'val
9595
// Set default options
9696
$options = array_merge(JHtml::$formatOptions, array('format.depth' => 0, 'id' => false));
9797

98-
if (is_array($attribs) && func_num_args() == 3)
98+
if (is_array($attribs) && func_num_args() === 3)
9999
{
100100
// Assume we have an options array
101101
$options = array_merge($options, $attribs);
@@ -354,7 +354,7 @@ public static function integerlist($start, $end, $inc, $name, $attribs = null, $
354354
// Set default options
355355
$options = array_merge(JHtml::$formatOptions, array('format.depth' => 0, 'option.format' => '', 'id' => null));
356356

357-
if (is_array($attribs) && func_num_args() == 5)
357+
if (is_array($attribs) && func_num_args() === 5)
358358
{
359359
// Assume we have an options array
360360
$options = array_merge($options, $attribs);

libraries/cms/html/string.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ abstract class JHtmlString
3636
public static function truncate($text, $length = 0, $noSplit = true, $allowHtml = true)
3737
{
3838
// Assume a lone open tag is invalid HTML.
39-
if ($length == 1 && substr($text, 0, 1) == '<')
39+
if ($length === 1 && substr($text, 0, 1) === '<')
4040
{
4141
return '...';
4242
}
@@ -105,7 +105,7 @@ public static function truncate($text, $length = 0, $noSplit = true, $allowHtml
105105
$numOpened = count($openedTags);
106106

107107
// Not all tags are closed so trim the text and finish.
108-
if (count($closedTags) != $numOpened)
108+
if (count($closedTags) !== $numOpened)
109109
{
110110
// Closing tags need to be in the reverse order of opening tags.
111111
$openedTags = array_reverse($openedTags);
@@ -170,7 +170,7 @@ public static function truncateComplex($html, $maxLength = 0, $noSplit = true)
170170
$baseLength = strlen($html);
171171

172172
// If the original HTML string is shorter than the $maxLength do nothing and return that.
173-
if ($baseLength <= $maxLength || $maxLength == 0)
173+
if ($baseLength <= $maxLength || $maxLength === 0)
174174
{
175175
return $html;
176176
}
@@ -182,7 +182,7 @@ public static function truncateComplex($html, $maxLength = 0, $noSplit = true)
182182
}
183183

184184
// Deal with maximum length of 1 where the string starts with a tag.
185-
if ($maxLength == 1 && substr($html, 0, 1) == '<')
185+
if ($maxLength === 1 && substr($html, 0, 1) === '<')
186186
{
187187
$endTagPos = strlen(strstr($html, '>', true));
188188
$tag = substr($html, 1, $endTagPos);
@@ -204,7 +204,7 @@ public static function truncateComplex($html, $maxLength = 0, $noSplit = true)
204204
$ptString = JHtml::_('string.truncate', $html, $maxLength, $noSplit, $allowHtml = false);
205205

206206
// It's all HTML, just return it.
207-
if (strlen($ptString) == 0)
207+
if (strlen($ptString) === 0)
208208
{
209209
return $html;
210210
}

libraries/cms/installer/helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public static function unpack($p_filename, $alwaysReturnArray = false)
173173
*/
174174
$dirList = array_merge((array) JFolder::files($extractdir, ''), (array) JFolder::folders($extractdir, ''));
175175

176-
if (count($dirList) == 1)
176+
if (count($dirList) === 1)
177177
{
178178
if (JFolder::exists($extractdir . '/' . $dirList[0]))
179179
{

libraries/cms/installer/installer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ public function parseQueries(SimpleXMLElement $element)
892892
// Get the array of query nodes to process
893893
$queries = $element->children();
894894

895-
if (count($queries) == 0)
895+
if (count($queries) === 0)
896896
{
897897
// No queries to process
898898
return 0;
@@ -987,7 +987,7 @@ public function parseSQLFiles($element)
987987
// Create an array of queries from the sql file
988988
$queries = JDatabaseDriver::splitSql($buffer);
989989

990-
if (count($queries) == 0)
990+
if (count($queries) === 0)
991991
{
992992
// No queries to process
993993
return 0;
@@ -1177,7 +1177,7 @@ public function parseSchemaUpdates(SimpleXMLElement $schema, $eid)
11771177
// Create an array of queries from the sql file
11781178
$queries = JDatabaseDriver::splitSql($buffer);
11791179

1180-
if (count($queries) == 0)
1180+
if (count($queries) === 0)
11811181
{
11821182
// No queries to process
11831183
continue;
@@ -1757,7 +1757,7 @@ public function removeFiles($element, $cid = 0)
17571757
// Get the array of file nodes to process
17581758
$files = $element->children();
17591759

1760-
if (count($files) == 0)
1760+
if (count($files) === 0)
17611761
{
17621762
// No files to process
17631763
return true;

libraries/cms/language/associations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static function getAssociations($extension, $tablename, $context, $id, $p
110110
foreach ($items as $tag => $item)
111111
{
112112
// Do not return itself as result
113-
if ((int) $item->{$pk} != $id)
113+
if ((int) $item->{$pk} !== $id)
114114
{
115115
$multilanguageAssociations[$queryKey][$tag] = $item;
116116
}

libraries/cms/module/helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public static function &getModules($position)
9393
}
9494
}
9595

96-
if (count($result) == 0)
96+
if (count($result) === 0)
9797
{
9898
if ($input->getBool('tp') && JComponentHelper::getParams('com_templates')->get('template_positions_display'))
9999
{

libraries/cms/plugin/helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public static function importPlugin($type, $plugin = null, $autocreate = true, J
150150
// Check for the default args, if so we can optimise cheaply
151151
$defaults = false;
152152

153-
if (is_null($plugin) && $autocreate == true && is_null($dispatcher))
153+
if (is_null($plugin) && $autocreate === true && is_null($dispatcher))
154154
{
155155
$defaults = true;
156156
}

libraries/cms/router/site.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ protected function parseRawRoute(&$uri)
227227
$this->setVar('Itemid', $this->app->input->getInt('Itemid', null));
228228

229229
// Only an Itemid OR if filter language plugin set? Get the full information from the itemid
230-
if (count($this->getVars()) == 1 || ($this->app->getLanguageFilter() && count($this->getVars()) == 2))
230+
if (count($this->getVars()) === 1 || ($this->app->getLanguageFilter() && count($this->getVars()) === 2))
231231
{
232232
$item = $this->menu->getItem($this->getVar('Itemid'));
233233

@@ -620,7 +620,7 @@ protected function processBuildRules(&$uri, $stage = self::PROCESS_DURING)
620620
$query = $uri->getQuery(true);
621621
if ($this->_mode != 1
622622
&& isset($query['Itemid'])
623-
&& (count($query) == 2 || (count($query) == 3 && isset($query['lang']))))
623+
&& (count($query) === 2 || (count($query) === 3 && isset($query['lang']))))
624624
{
625625
// Get the active menu item
626626
$itemid = $uri->getVar('Itemid');

0 commit comments

Comments
 (0)